/** * Checks if all Coupons applied to current cart are still valid. * If are not, they will be deleted from the Cart and new Event typeof * CartCouponOnRejected will be dispatched * * @param CartInterface $cart Cart */ public function validateCartCoupons(CartInterface $cart) { $cartCoupons = $this->cartCouponManager->getCartCoupons($cart); foreach ($cartCoupons as $cartCoupon) { $coupon = $cartCoupon->getCoupon(); try { $this->cartCouponEventDispatcher->dispatchCartCouponOnCheckEvent($cart, $coupon); } catch (AbstractCouponException $exception) { $this->cartCouponManager->removeCoupon($cart, $coupon); $this->cartCouponEventDispatcher->dispatchCartCouponOnRejectedEvent($cart, $coupon); } } }
/** * Method subscribed to CartLoad event * * Checks if all Coupons applied to current cart are still valid. * If are not, they will be deleted from the Cart and new Event typeof * CartCouponOnRejected will be dispatched * * @param CartOnLoadEvent $event Event */ public function refreshCartCoupons(CartOnLoadEvent $event) { $cart = $event->getCart(); $cartCoupons = $this->cartCouponManager->getCartCoupons($cart); foreach ($cartCoupons as $cartCoupon) { $coupon = $cartCoupon->getCoupon(); try { $this->cartCouponEventDispatcher->dispatchCartCouponOnCheckEvent($cart, $coupon); } catch (AbstractCouponException $exception) { $this->cartCouponManager->removeCoupon($cart, $coupon); $this->cartCouponEventDispatcher->dispatchCartCouponOnRejectedEvent($cart, $coupon); } } }
/** * Method subscribed to PreCartLoad event * * Checks if all Coupons applied to current cart are still valid. * If are not, they will be deleted from the Cart and new Event typeof * CartCouponOnRejected will be dispatched * * @param CartPreLoadEvent $cartPreLoadEvent Event */ public function onCartPreLoadCoupons(CartPreLoadEvent $cartPreLoadEvent) { $cart = $cartPreLoadEvent->getCart(); $cartCoupons = $this->cartCouponManager->getCartCoupons($cart); /** * @var CartCouponInterface $cartCoupon */ foreach ($cartCoupons as $cartCoupon) { $coupon = $cartCoupon->getCoupon(); if (!$this->cartCouponRuleManager->checkCouponValidity($cart, $coupon)) { $this->cartCouponManager->removeCoupon($cart, $coupon); $this->cartCouponEventDispatcher->dispatchCartCouponOnRejectedEvent($cart, $coupon); } } }