diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php
index b8e2a7553..da8862d54 100644
--- a/core/lib/Thelia/Action/Coupon.php
+++ b/core/lib/Thelia/Action/Coupon.php
@@ -109,6 +109,14 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$this->createOrUpdateCondition($modelCoupon, $event);
}
+ /**
+ * Clear all coupons in session.
+ */
+ public function clearAllCoupons() {
+
+ $this->request->getSession()->setConsumedCoupons(array());
+ }
+
/**
* Occurring when a Coupon condition is about to be consumed
*
@@ -139,21 +147,22 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$consumedCoupons[$event->getCode()] = $event->getCode();
$this->request->getSession()->setConsumedCoupons($consumedCoupons);
-
- $totalDiscount = $this->couponManager->getDiscount();
-
- $this->request
- ->getSession()
- ->getCart()
- ->setDiscount($totalDiscount)
- ->save();
- $this->request
- ->getSession()
- ->getOrder()
- ->setDiscount($totalDiscount)
- ;
}
- }
+
+ $totalDiscount = $this->couponManager->getDiscount();
+
+ $this->request
+ ->getSession()
+ ->getCart()
+ ->setDiscount($totalDiscount)
+ ->save();
+
+ $this->request
+ ->getSession()
+ ->getOrder()
+ ->setDiscount($totalDiscount)
+ ;
+ }
}
$event->setIsValid($isValid);
@@ -339,7 +348,8 @@ class Coupon extends BaseAction implements EventSubscriberInterface
}
}
- $this->request->getSession()->setConsumedCoupons(array());
+ // Clear all coupouns.
+ $event->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
}
/**
@@ -368,6 +378,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
TheliaEvents::COUPON_CREATE => array("create", 128),
TheliaEvents::COUPON_UPDATE => array("update", 128),
TheliaEvents::COUPON_CONSUME => array("consume", 128),
+ TheliaEvents::COUPON_CLEAR_ALL => array("clearAllCoupons", 128),
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128),
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 132),
TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128),
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index 69c12fb73..9d67366cc 100644
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -464,6 +464,12 @@ final class TheliaEvents
*/
const COUPON_CONSUME = "action.consume_coupon";
+ /**
+ * Sent when all coupons in the current session should be cleared
+ */
+ const COUPON_CLEAR_ALL = "action.clear_all_coupon";
+
+
/**
* Sent just before an attempt to use a Coupon
*/
diff --git a/local/modules/Front/Config/front.xml b/local/modules/Front/Config/front.xml
index 0a987eaa2..c37b119ad 100644
--- a/local/modules/Front/Config/front.xml
+++ b/local/modules/Front/Config/front.xml
@@ -160,6 +160,11 @@
order-invoice
+
+ Front\Controller\CouponController::clearAllCouponsAction
+ order-invoice
+
+
Front\Controller\OrderController::pay
diff --git a/local/modules/Front/Controller/CouponController.php b/local/modules/Front/Controller/CouponController.php
index 98333dd0a..8bce7b206 100644
--- a/local/modules/Front/Controller/CouponController.php
+++ b/local/modules/Front/Controller/CouponController.php
@@ -40,9 +40,16 @@ use Thelia\Module\Exception\DeliveryException;
*/
class CouponController extends BaseFrontController
{
+ /**
+ * Clear all coupons.
+ */
+ public function clearAllCouponsAction() {
+ // Dispatch Event to the Action
+ $this->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
+ }
/**
- * Test Coupon consuming
+ * Coupon consuming
*/
public function consumeAction()
{