/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionCouponInterface $promotionCoupon) { if (!$promotionSubject instanceof OrderInterface) { return true; } if (!$promotionCoupon instanceof CorePromotionCouponInterface) { return true; } $perCustomerUsageLimit = $promotionCoupon->getPerCustomerUsageLimit(); if ($perCustomerUsageLimit === null) { return true; } $customer = $promotionSubject->getCustomer(); if ($customer === null) { return true; } $placedOrdersNumber = $this->orderRepository->countByCustomerAndCoupon($customer, $promotionCoupon); return $placedOrdersNumber < $perCustomerUsageLimit; }
function it_returns_false_if_usage_limit_has_been_reached(PromotionSubjectInterface $promotionSubject, PromotionCouponInterface $promotionCoupon) { $promotionCoupon->getUsageLimit()->willReturn(42); $promotionCoupon->getUsed()->willReturn(42); $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false); }
function it_returns_false_if_promotion_coupon_has_already_expired(PromotionSubjectInterface $promotionSubject, PromotionCouponInterface $promotionCoupon) { $promotionCoupon->getExpiresAt()->willReturn(new \DateTime('yesterday')); $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false); }
/** * @Then /^([^"]+) should still exist in the registry$/ */ public function couponShouldStillExistInTheRegistry(PromotionCouponInterface $coupon) { Assert::notNull($this->couponRepository->find($coupon->getId()), sprintf('The coupon with id %s should exist', $coupon->getId())); }
/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionCouponInterface $promotionCoupon) { $usageLimit = $promotionCoupon->getUsageLimit(); return $usageLimit === null || $promotionCoupon->getUsed() < $usageLimit; }
/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionCouponInterface $promotionCoupon) { $endsAt = $promotionCoupon->getExpiresAt(); return $endsAt === null || new \DateTime() < $endsAt; }
/** * {@inheritdoc} */ public function removeCoupon(PromotionCouponInterface $coupon) { $coupon->setPromotion(null); $this->coupons->removeElement($coupon); }