Пример #1
0
 /**
  * Occurring when a Coupon condition is about to be consumed
  *
  * @param CouponConsumeEvent $event Event consuming Coupon
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function consume(CouponConsumeEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $totalDiscount = 0;
     $isValid = false;
     /** @var CouponInterface $coupon */
     $coupon = $this->couponFactory->buildCouponFromCode($event->getCode());
     if ($coupon) {
         $isValid = $coupon->isMatching();
         if ($isValid) {
             $this->couponManager->pushCouponInSession($event->getCode());
             $totalDiscount = $this->couponManager->getDiscount();
             $this->getSession()->getSessionCart($dispatcher)->setDiscount($totalDiscount)->save();
             $this->getSession()->getOrder()->setDiscount($totalDiscount);
         }
     }
     $event->setIsValid($isValid);
     $event->setDiscount($totalDiscount);
 }