Example #1
0
 /**
  * {@inheritdoc}
  */
 public function isEligible(PromotionSubjectInterface $subject, array $configuration)
 {
     if (!$subject instanceof OrderInterface) {
         throw new UnsupportedTypeException($subject, 'Sylius\\Component\\Core\\Model\\OrderInterface');
     }
     if (null === ($customer = $subject->getCustomer())) {
         return false;
     }
     return $this->orderRepository->countByCustomerAndPaymentState($customer, PaymentInterface::STATE_COMPLETED) === $configuration['nth'] - 1;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function isEligible(PromotionSubjectInterface $subject, array $configuration)
 {
     if (!$subject instanceof OrderInterface) {
         throw new UnsupportedTypeException($subject, OrderInterface::class);
     }
     if (!isset($configuration['nth']) || !is_int($configuration['nth'])) {
         return false;
     }
     $customer = $subject->getCustomer();
     if (null === $customer) {
         return false;
     }
     return $this->orderRepository->countByCustomerAndPaymentState($customer, PaymentInterface::STATE_COMPLETED) === $configuration['nth'] - 1;
 }
 function it_recognizes_subject_as_eligible_if_nth_order_is_equal_with_configured(CustomerInterface $customer, OrderInterface $subject, OrderRepositoryInterface $ordersRepository)
 {
     $subject->getCustomer()->willReturn($customer);
     $ordersRepository->countByCustomerAndPaymentState($customer, PaymentInterface::STATE_COMPLETED)->willReturn(9);
     $this->isEligible($subject, ['nth' => 10])->shouldReturn(true);
 }