/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionInterface $promotion) { if (!$promotion->isCouponBased()) { throw new UnsupportedPromotionException('Only coupon based promotions can be evaluated by this checker.'); } if (!$promotionSubject instanceof CouponAwarePromotionSubjectInterface) { return false; } if (null === $promotionSubject->getPromotionCoupon()) { return false; } return $promotion === $promotionSubject->getPromotionCoupon()->getPromotion(); }
/** * {@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; }
/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionInterface $promotion) { if (!$promotion->isCouponBased()) { throw new UnsupportedPromotionException('Only coupon based promotions can be evaluated by this checker.'); } if (!$promotionSubject instanceof OrderInterface) { return false; } $coupon = $promotionSubject->getPromotionCoupon(); if (!$coupon instanceof CouponInterface) { return false; } if ($promotion !== $coupon->getPromotion()) { return false; } $couponUsageLimit = $coupon->getPerCustomerUsageLimit(); if (0 === $couponUsageLimit) { return true; } $customer = $promotionSubject->getCustomer(); if (null === $customer) { return false; } $placedOrdersNumber = $this->orderRepository->countByCustomerAndCoupon($customer, $coupon); // <= because we need to include the cart orders as well return $placedOrdersNumber <= $couponUsageLimit; }
/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $subject, PromotionInterface $promotion) { if (!$subject instanceof PromotionCouponAwareSubjectInterface || null === $subject->getPromotionCoupon()) { return false; } if (!$this->isCouponEligible($promotion, $subject)) { $this->eventDispatcher->dispatch(SyliusPromotionEvents::COUPON_NOT_ELIGIBLE, new GenericEvent($promotion)); return false; } $this->eventDispatcher->dispatch(SyliusPromotionEvents::COUPON_ELIGIBLE, new GenericEvent($promotion)); return true; }
/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionInterface $promotion) { if (!$promotion->isCouponBased()) { return true; } if (!$promotionSubject instanceof PromotionCouponAwarePromotionSubjectInterface) { return false; } $promotionCoupon = $promotionSubject->getPromotionCoupon(); if (null === $promotionCoupon) { return false; } if ($promotion !== $promotionCoupon->getPromotion()) { return false; } return $this->promotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon); }
/** * 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; }