Added the COUPON_CLEAR_ALL event, and a route to trigger it.

This commit is contained in:
Franck Allimant
2014-06-12 16:39:27 +02:00
parent 95841809c4
commit 96ebcf1880
4 changed files with 45 additions and 16 deletions

View File

@@ -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,6 +147,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$consumedCoupons[$event->getCode()] = $event->getCode();
$this->request->getSession()->setConsumedCoupons($consumedCoupons);
}
$totalDiscount = $this->couponManager->getDiscount();
@@ -147,6 +156,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
->getCart()
->setDiscount($totalDiscount)
->save();
$this->request
->getSession()
->getOrder()
@@ -154,7 +164,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
;
}
}
}
$event->setIsValid($isValid);
$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_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),

View File

@@ -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
*/

View File

@@ -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>

View File

@@ -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()
{