示例#1
0
 /**
  * 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);
         }
     }
 }
示例#2
0
 /**
  * Check cart integrity
  *
  * @param CartPreLoadEvent $event Event
  */
 public function checkCartIntegrity(CartPreLoadEvent $event)
 {
     /**
      * @var CartInterface $cart
      */
     $cart = $event->getCart();
     /**
      * Check every CartLine
      *
      * @var CartLineInterface $cartLine
      */
     foreach ($cart->getCartLines() as $cartLine) {
         $this->checkCartLine($cartLine);
     }
 }