/** * 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); } } }
/** * Checks if a Coupon is applicable to a Cart * * @param CartCouponOnApplyEvent $event Event */ public function validateCoupon(CartCouponOnApplyEvent $event) { $this->cartCouponDispatcher->dispatchCartCouponOnCheckEvent($event->getCart(), $event->getCoupon()); }