From e02d9c161155cc0cdbd4ca7cef82e590bfbb34af Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 18 Apr 2014 00:09:26 +0200 Subject: [PATCH] Fix for #308 --- .../Front/Controller/CouponController.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/local/modules/Front/Controller/CouponController.php b/local/modules/Front/Controller/CouponController.php index ba7433612..3c3c025ab 100644 --- a/local/modules/Front/Controller/CouponController.php +++ b/local/modules/Front/Controller/CouponController.php @@ -26,11 +26,12 @@ use Propel\Runtime\Exception\PropelException; use Thelia\Controller\Front\BaseFrontController; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Form\CouponCode; use Thelia\Form\Exception\FormValidationException; -use Thelia\Core\Event\TheliaEvents; use Thelia\Log\Tlog; use Thelia\Model\AddressQuery; +use Thelia\Module\Exception\DeliveryException; /** * Class CouponController @@ -74,12 +75,23 @@ class CouponController extends BaseFrontController if (null !== $deliveryModule && null !== $deliveryAddress) { $moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode())); - $postage = $moduleInstance->getPostage($deliveryAddress->getCountry()); $orderEvent = new OrderEvent($order); - $orderEvent->setPostage($postage); - $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent); + try { + $postage = $moduleInstance->getPostage($deliveryAddress->getCountry()); + + $orderEvent->setPostage($postage); + + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent); + } + catch (DeliveryException $ex) { + // The postage has been chosen, but changes dues to coupon causes an exception. + // Reset the postage data in the order + $orderEvent->setDeliveryModule(0); + + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); + } } }