aivus/orocommerce-collect-on-delivery
Installation:
composer require aivus/orocommerce-collect-on-delivery
Ensure OroCommerce is already installed and configured in your project.
Enable Bundle:
Add to config/bundles.php:
Aivus\OroCommerceCollectOnDeliveryBundle\AivusOroCommerceCollectOnDeliveryBundle::class => ['all' => true],
Database Migration: Run:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case:
Payment Method Integration:
oro_integration.payment_method.update).use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Oro\Bundle\PaymentBundle\Event\PaymentMethodUpdateEvent;
class CodValidationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'oro_integration.payment_method.update' => 'onPaymentMethodUpdate',
];
}
public function onPaymentMethodUpdate(PaymentMethodUpdateEvent $event)
{
$method = $event->getMethod();
if ($method->getCode() === 'cod' && $method->isActive()) {
$event->setActive($this->isCodEligible($event->getOrder()));
}
}
private function isCodEligible(Order $order): bool
{
// Custom logic (e.g., min order amount, specific regions)
return $order->getTotal() >= 50;
}
}
Order Processing:
oro_order.payment event to handle COD-specific logic (e.g., marking orders as "pending" until delivery confirmation).use Oro\Bundle\OrderBundle\Entity\Order;
use Oro\Bundle\OrderBundle\Event\OrderPaymentEvent;
$event->getOrder()->setPaymentStatus('pending_cod');
Frontend Integration:
oro_order_checkout_payment.html.twig).{% extends 'OroOrderBundle:OrderCheckout:payment.html.twig' %}
{% block cod_option %}
{% if isCODEligible(order) %}
<div class="cod-option">
<input type="radio" name="payment_method" value="cod" id="cod">
<label for="cod">{{ 'oro.order.payment_method.cod'|trans }}</label>
</div>
{% endif %}
{% endblock %}
Delivery Confirmation:
config/routes.yaml):
aivus_cod_confirmation:
path: /api/cod/confirm/{orderId}
controller: Aivus\OroCommerceCollectOnDeliveryBundle\Controller\CodConfirmationController::confirm
methods: [POST]
Database Conflicts:
cod_payment_method table. Ensure no naming collisions with existing tables.Resources/config/doctrine if needed.Payment Status Mismatch:
getPaymentStatus() method in your Order entity or use a custom query builder to filter COD orders:
$queryBuilder->andWhere('o.paymentStatus != :codStatus')
->setParameter('codStatus', 'pending_cod');
Frontend Visibility:
php bin/console assets:install
yarn encore dev
Archived Package Risks:
src/DependencyInjection/AivusOroCommerceCollectOnDeliveryExtension.php for configuration options.EventListener/CodListener.php for core logic.Enable Debugging:
Add to config/packages/dev/oro_integration.yaml:
oro_integration:
debug: true
Log COD Events: Use Monolog to track COD-related events:
$this->logger->info('COD Payment Initiated', ['order_id' => $order->getId()]);
Override Bundle Classes:
If the bundle’s logic is insufficient, extend its services via config/services.yaml:
Aivus\OroCommerceCollectOnDeliveryBundle\Service\CodService:
class: App\Service\CustomCodService
arguments:
- '@=service("aivus.oro_commerce_collect_on_delivery.cod_service").originalService'
Custom Validation Rules:
Extend the CodValidator service to add business logic (e.g., blacklisted products):
class CustomCodValidator extends CodValidator
{
public function isValid(Order $order): bool
{
if (!$this->isMinAmountMet($order)) {
return false;
}
return !$this->hasBlacklistedProduct($order);
}
private function hasBlacklistedProduct(Order $order): bool
{
// Custom logic
}
}
Delivery Confirmation Workflow: Create a custom command to bulk-process COD confirmations:
php bin/console aivus:cod:confirm --order-id=123
Multi-Currency Support:
Ensure COD is disabled for non-supported currencies by overriding the getSupportedCurrencies() method in the payment method entity.
How can I help you explore Laravel packages today?