/** * {@inheritdoc} */ protected function areCouponsEligibleForPromotion(PromotionSubjectInterface $subject, PromotionInterface $promotion) { if (!$subject instanceof CustomerAwareInterface) { return false; } $eligible = false; // Check to see if there is a per customer usage limit on coupon if ($subject instanceof PromotionCouponAwareSubjectInterface) { $coupon = $subject->getPromotionCoupon(); if (null !== $coupon && $promotion === $coupon->getPromotion()) { $eligible = $this->isCouponEligibleToLimit($coupon, $promotion, $subject->getCustomer()); } } elseif ($subject instanceof PromotionCouponsAwareSubjectInterface) { foreach ($subject->getPromotionCoupons() as $coupon) { if ($promotion === $coupon->getPromotion()) { $eligible = $this->isCouponEligibleToLimit($coupon, $promotion, $subject->getCustomer()); break; } } } else { return false; } if ($eligible) { $this->dispatcher->dispatch(SyliusPromotionEvents::COUPON_ELIGIBLE, new GenericEvent($promotion)); } return $eligible; }
/** * Checks are subject's coupons eligible to promotion. * * @param PromotionSubjectInterface $subject * @param PromotionInterface $promotion * * @return bool */ protected function areCouponsEligibleForPromotion(PromotionSubjectInterface $subject, PromotionInterface $promotion) { $eligible = false; if ($subject instanceof PromotionCouponAwareSubjectInterface) { $coupon = $subject->getPromotionCoupon(); if (null !== $coupon && $promotion === $coupon->getPromotion()) { $eligible = true; } } elseif ($subject instanceof PromotionCouponsAwareSubjectInterface) { foreach ($subject->getPromotionCoupons() as $coupon) { if ($promotion === $coupon->getPromotion()) { $eligible = true; break; } } } else { return false; } if ($eligible) { $this->dispatcher->dispatch(SyliusPromotionEvents::COUPON_ELIGIBLE, new GenericEvent($promotion)); } return $eligible; }