/**
  * {@inheritdoc}
  */
 public function isEligible(PromotionSubjectInterface $subject, PromotionInterface $promotion)
 {
     if (!$this->datesEligibilityChecker->isEligible($promotion)) {
         return false;
     }
     if (!$this->usageLimitEligibilityChecker->isEligible($promotion)) {
         return false;
     }
     $eligible = $this->rulesEligibilityChecker->isEligible($subject, $promotion);
     if (!$eligible) {
         return false;
     }
     if (!$promotion->isCouponBased()) {
         return $eligible;
     }
     return $this->couponsEligibilityChecker->isEligible($subject, $promotion);
 }
 function it_returns_true_if_promotion_is_coupon_based_and_eligible_to_rules_and_eligible_to_coupons(PromotionEligibilityCheckerInterface $datesEligibilityChecker, PromotionEligibilityCheckerInterface $usageLimitEligibilityChecker, PromotionSubjectEligibilityCheckerInterface $couponsEligibilityChecker, PromotionSubjectEligibilityCheckerInterface $rulesEligibilityChecker, PromotionInterface $promotion, PromotionSubjectInterface $subject)
 {
     $datesEligibilityChecker->isEligible($promotion)->willReturn(true);
     $usageLimitEligibilityChecker->isEligible($promotion)->willReturn(true);
     $rulesEligibilityChecker->isEligible($subject, $promotion)->willReturn(true);
     $promotion->isCouponBased()->willReturn(true);
     $couponsEligibilityChecker->isEligible($subject, $promotion)->willReturn(true);
     $this->isEligible($subject, $promotion)->shouldReturn(true);
 }
Esempio n. 3
0
 /**
  * @param PromotionSubjectInterface $subject
  *
  * @return mixed
  */
 public function process(PromotionSubjectInterface $subject)
 {
     foreach ($subject->getPromotions() as $promotion) {
         $this->applicator->revert($subject, $promotion);
     }
     $eligiblePromotions = [];
     foreach ($this->preQualifiedPromotionsProvider->getPromotions($subject) as $promotion) {
         if (!$this->checker->isEligible($subject, $promotion)) {
             continue;
         }
         if ($promotion->isExclusive()) {
             return $this->applicator->apply($subject, $promotion);
         }
         $eligiblePromotions[] = $promotion;
     }
     foreach ($eligiblePromotions as $promotion) {
         $this->applicator->apply($subject, $promotion);
     }
 }