Added the COUPON_CLEAR_ALL event, and a route to trigger it.
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -160,6 +160,11 @@
|
||||
<default key="_view">order-invoice</default>
|
||||
</route>
|
||||
|
||||
<route id="order.coupon.clear" path="/order/clear-coupons">
|
||||
<default key="_controller">Front\Controller\CouponController::clearAllCouponsAction</default>
|
||||
<default key="_view">order-invoice</default>
|
||||
</route>
|
||||
|
||||
<route id="order.payment.process" path="/order/pay">
|
||||
<default key="_controller">Front\Controller\OrderController::pay</default>
|
||||
</route>
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user