예제 #1
0
 function it_filters_passed_order_items_with_given_configuration(OrderItemInterface $item1, OrderItemInterface $item2, ProductInterface $product1, ProductInterface $product2)
 {
     $item1->getProduct()->willReturn($product1);
     $product1->getCode()->willReturn('product1');
     $item2->getProduct()->willReturn($product2);
     $product2->getCode()->willReturn('product2');
     $this->filter([$item1, $item2], ['filters' => ['products_filter' => ['products' => ['product1']]]])->shouldReturn([$item1]);
 }
예제 #2
0
 function it_recognizes_a_subject_as_not_eligible_if_a_product_taxon_is_not_matched(OrderInterface $subject, OrderItemInterface $item, ProductInterface $reflexBow, TaxonInterface $bows)
 {
     $configuration = ['taxons' => ['swords', 'axes']];
     $bows->getCode()->willReturn('bows');
     $reflexBow->getTaxons()->willReturn([$bows]);
     $item->getProduct()->willReturn($reflexBow);
     $subject->getItems()->willReturn([$item]);
     $this->isEligible($subject, $configuration)->shouldReturn(false);
 }
 function it_returns_false_if_product_is_wrong(OrderInterface $subject, OrderItemInterface $firstOrderItem, OrderItemInterface $secondOrderItem, ProductInterface $shaft, ProductInterface $head)
 {
     $subject->getItems()->willReturn([$firstOrderItem, $secondOrderItem]);
     $firstOrderItem->getProduct()->willReturn($head);
     $secondOrderItem->getProduct()->willReturn($shaft);
     $head->getCode()->willReturn('LACROSSE_HEAD');
     $shaft->getCode()->willReturn('LACROSSE_SHAFT');
     $this->isEligible($subject, ['product_code' => 'LACROSSE_STRING'])->shouldReturn(false);
 }
예제 #4
0
 function it_should_recognize_subject_as_not_eligible_if_product_taxonomy_is_matched_and_exclude_is_set(OrderInterface $subject, OrderItemInterface $item, Taxon $taxon, Product $product, ArrayCollection $collection)
 {
     $configuration = ['taxons' => $collection, 'exclude' => true];
     $collection->contains(2)->willReturn(true);
     $taxon->getId()->willReturn(2);
     $product->getTaxons()->willReturn([$taxon]);
     $item->getProduct()->willReturn($product);
     $subject->getItems()->willReturn([$item]);
     $this->isEligible($subject, $configuration)->shouldReturn(false);
 }
 function it_does_not_check_an_item_if_its_product_has_no_required_taxon(OrderInterface $order, OrderItemInterface $compositeBowItem, OrderItemInterface $longswordItem, ProductInterface $compositeBow, ProductInterface $longsword, TaxonInterface $bows, TaxonRepositoryInterface $taxonRepository)
 {
     $order->getItems()->willReturn(new \ArrayIterator([$compositeBowItem->getWrappedObject(), $longswordItem->getWrappedObject()]));
     $taxonRepository->findOneBy(['code' => 'bows'])->willReturn($bows);
     $compositeBowItem->getProduct()->willReturn($compositeBow);
     $compositeBow->hasTaxon($bows)->willReturn(true);
     $compositeBowItem->getQuantity()->willReturn(4);
     $longswordItem->getProduct()->willReturn($longsword);
     $longsword->hasTaxon($bows)->willReturn(false);
     $longswordItem->getQuantity()->shouldNotBeCalled();
     $this->isEligible($order, ['taxon' => 'bows', 'count' => 5])->shouldReturn(false);
 }
 function it_does_not_recognize_a_subject_as_eligible_if_items_from_required_taxon_has_too_low_total(TaxonRepositoryInterface $taxonRepository, OrderInterface $order, OrderItemInterface $compositeBowItem, OrderItemInterface $longswordItem, ProductInterface $compositeBow, ProductInterface $longsword, TaxonInterface $bows)
 {
     $order->getItems()->willReturn([$compositeBowItem, $longswordItem]);
     $taxonRepository->findOneBy(['code' => 'bows'])->willReturn($bows);
     $compositeBowItem->getProduct()->willReturn($compositeBow);
     $compositeBow->hasTaxon($bows)->willReturn(true);
     $compositeBowItem->getTotal()->willReturn(5000);
     $longswordItem->getProduct()->willReturn($longsword);
     $longsword->hasTaxon($bows)->willReturn(false);
     $longswordItem->getTotal()->willReturn(4000);
     $this->isEligible($order, ['taxon' => 'bows', 'amount' => 10000])->shouldReturn(false);
 }
 function it_removes_invalid_cart_items($cartProvider, $restrictedZoneChecker, $session, $translator, $cartManager, OrderItemInterface $item, GenericEvent $event, OrderInterface $cart, ProductInterface $product, AddressInterface $address, FlashBag $flashBag)
 {
     $event->getSubject()->willReturn($cart);
     $cartProvider->getCart()->shouldNotBeCalled();
     $item->getProduct()->willReturn($product);
     $product->getName()->willReturn('invalid');
     $cart->getItems()->willReturn([$item]);
     $cart->getShippingAddress()->willReturn($address);
     $cart->removeItem($item)->shouldBeCalled();
     $restrictedZoneChecker->isRestricted($product, $address)->willReturn(true);
     $session->getBag('flashes')->willReturn($flashBag);
     $flashBag->add('error', Argument::any())->shouldBeCalled();
     $translator->trans('sylius.cart.restricted_zone_removal', ['%product%' => 'invalid'], 'flashes')->shouldBeCalled();
     $cartManager->persist($cart)->shouldBeCalled();
     $cartManager->flush()->shouldBeCalled();
     $this->handleRestrictedZone($event);
 }
 function it_does_not_recognize_a_subject_as_eligible_if_items_from_required_taxon_has_too_low_total(ChannelInterface $channel, OrderInterface $order, OrderItemInterface $compositeBowItem, OrderItemInterface $longswordItem, ProductInterface $compositeBow, ProductInterface $longsword, ProductTaxonInterface $bowsProductTaxon, TaxonInterface $bows, TaxonRepositoryInterface $taxonRepository)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $order->getItems()->willReturn([$compositeBowItem, $longswordItem]);
     $taxonRepository->findOneBy(['code' => 'bows'])->willReturn($bows);
     $compositeBowItem->getProduct()->willReturn($compositeBow);
     $compositeBow->filterProductTaxonsByTaxon($bows)->willReturn(new ArrayCollection([$bowsProductTaxon]));
     $compositeBowItem->getTotal()->willReturn(5000);
     $longswordItem->getProduct()->willReturn($longsword);
     $longsword->filterProductTaxonsByTaxon($bows)->willReturn(new ArrayCollection([]));
     $longswordItem->getTotal()->willReturn(4000);
     $this->isEligible($order, ['WEB_US' => ['taxon' => 'bows', 'amount' => 10000]])->shouldReturn(false);
 }