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);
|
$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
|
* Occurring when a Coupon condition is about to be consumed
|
||||||
*
|
*
|
||||||
@@ -139,6 +147,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
$consumedCoupons[$event->getCode()] = $event->getCode();
|
$consumedCoupons[$event->getCode()] = $event->getCode();
|
||||||
|
|
||||||
$this->request->getSession()->setConsumedCoupons($consumedCoupons);
|
$this->request->getSession()->setConsumedCoupons($consumedCoupons);
|
||||||
|
}
|
||||||
|
|
||||||
$totalDiscount = $this->couponManager->getDiscount();
|
$totalDiscount = $this->couponManager->getDiscount();
|
||||||
|
|
||||||
@@ -147,6 +156,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
->getCart()
|
->getCart()
|
||||||
->setDiscount($totalDiscount)
|
->setDiscount($totalDiscount)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$this->request
|
$this->request
|
||||||
->getSession()
|
->getSession()
|
||||||
->getOrder()
|
->getOrder()
|
||||||
@@ -154,7 +164,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$event->setIsValid($isValid);
|
$event->setIsValid($isValid);
|
||||||
$event->setDiscount($totalDiscount);
|
$event->setDiscount($totalDiscount);
|
||||||
@@ -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_CREATE => array("create", 128),
|
||||||
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
||||||
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
||||||
|
TheliaEvents::COUPON_CLEAR_ALL => array("clearAllCoupons", 128),
|
||||||
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128),
|
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128),
|
||||||
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 132),
|
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 132),
|
||||||
TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128),
|
TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128),
|
||||||
|
|||||||
@@ -464,6 +464,12 @@ final class TheliaEvents
|
|||||||
*/
|
*/
|
||||||
const COUPON_CONSUME = "action.consume_coupon";
|
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
|
* Sent just before an attempt to use a Coupon
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -160,6 +160,11 @@
|
|||||||
<default key="_view">order-invoice</default>
|
<default key="_view">order-invoice</default>
|
||||||
</route>
|
</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">
|
<route id="order.payment.process" path="/order/pay">
|
||||||
<default key="_controller">Front\Controller\OrderController::pay</default>
|
<default key="_controller">Front\Controller\OrderController::pay</default>
|
||||||
</route>
|
</route>
|
||||||
|
|||||||
@@ -40,9 +40,16 @@ use Thelia\Module\Exception\DeliveryException;
|
|||||||
*/
|
*/
|
||||||
class CouponController extends BaseFrontController
|
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()
|
public function consumeAction()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user