function it_decrements_a_usage_of_promotions_applied_on_order(OrderInterface $order, PromotionInterface $firstPromotion, PromotionInterface $secondPromotion)
 {
     $order->getPromotions()->willReturn([$firstPromotion, $secondPromotion]);
     $firstPromotion->decrementUsed()->shouldBeCalled();
     $secondPromotion->decrementUsed()->shouldBeCalled();
     $this->decrement($order);
 }
 function it_does_not_apply_bigger_promotions_than_unit_total($adjustmentFactory, $originator, $priceRangeFilter, $taxonFilter, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemInterface $orderItem2, OrderItemInterface $orderItem3, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($originalItems);
     $originalItems->toArray()->willReturn([$orderItem1, $orderItem2, $orderItem3]);
     $priceRangeFilter->filter([$orderItem1, $orderItem2, $orderItem3], ['amount' => 1000, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1, $orderItem3]);
     $taxonFilter->filter([$orderItem1, $orderItem3], ['amount' => 1000, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1]);
     $orderItem1->getQuantity()->willReturn(2);
     $orderItem1->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $promotion->getName()->willReturn('Test promotion');
     $adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2);
     $unit1->getTotal()->willReturn(300);
     $promotionAdjustment1->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled();
     $promotionAdjustment1->setAmount(-300)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
     $unit2->getTotal()->willReturn(200);
     $promotionAdjustment2->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
     $promotionAdjustment2->setAmount(-200)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment2, $promotion)->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment($promotionAdjustment2)->shouldBeCalled();
     $this->execute($order, ['amount' => 1000, 'filters' => ['taxons' => ['testTaxon']]], $promotion);
 }
 /**
  * @When /^I try to delete ("[^"]+" coupon) related to (this promotion)$/
  */
 public function iTryToDeleteCoupon(PromotionCouponInterface $coupon, PromotionInterface $promotion)
 {
     try {
         $promotion->removeCoupon($coupon);
         $this->couponRepository->remove($coupon);
     } catch (ForeignKeyConstraintViolationException $exception) {
         $this->sharedStorage->set('last_exception', $exception);
     }
 }
 function it_returns_false_if_subject_coupon_is_eligible_to_promotion_and_number_of_usages_is_bigger_than_coupon_usage_limit(OrderRepositoryInterface $orderRepository, OrderInterface $subject, PromotionInterface $promotion, CouponInterface $coupon, CustomerInterface $customer)
 {
     $subject->getPromotionCoupon()->willReturn($coupon);
     $promotion->isCouponBased()->willReturn(true);
     $subject->getCustomer()->willReturn($customer);
     $coupon->getPromotion()->willReturn($promotion);
     $coupon->getPerCustomerUsageLimit()->willReturn(5);
     $orderRepository->countByCustomerAndCoupon($customer, $coupon)->willReturn(6);
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
 function it_reverts_a_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $items, Collection $units, Collection $adjustments, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($items);
     $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
     $orderItem->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit->getWrappedObject()]));
     $unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn($adjustments);
     $adjustments->getIterator()->willReturn(new \ArrayIterator([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()]));
     $promotion->getCode()->willReturn('PROMOTION');
     $promotionAdjustment1->getOriginCode()->willReturn('PROMOTION');
     $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled();
     $promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION');
     $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled();
     $this->revert($order, ['percentage' => 0.2], $promotion);
 }
 function it_creates_percentage_shipping_discount_action_for_promotion($actionFactory, $objectManager, ActionInterface $action, PromotionInterface $promotion)
 {
     $actionFactory->createPercentageShippingDiscount(0.1)->willReturn($action);
     $promotion->addAction($action)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->itGivesPercentageDiscountOnShippingToEveryOrder($promotion, 0.1);
 }
 function it_does_not_apply_promotions_with_amount_0($adjustmentFactory, $distributor, $originator, $priceRangeFilter, $taxonFilter, AdjustmentInterface $promotionAdjustment1, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemInterface $orderItem2, OrderItemInterface $orderItem3, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($originalItems);
     $originalItems->toArray()->willReturn([$orderItem1, $orderItem2, $orderItem3]);
     $priceRangeFilter->filter([$orderItem1, $orderItem2, $orderItem3], ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1, $orderItem2]);
     $taxonFilter->filter([$orderItem1, $orderItem2], ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1]);
     $orderItem1->getQuantity()->willReturn(2);
     $orderItem1->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $orderItem1->getTotal()->willReturn(5);
     $distributor->distribute(1, 2)->willReturn([1, 0]);
     $promotion->getDescription()->willReturn('Test description');
     $adjustmentFactory->createNew()->willReturn($promotionAdjustment1);
     $promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
     $promotionAdjustment1->setAmount(-1)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->execute($order, ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]], $promotion);
 }
 function it_applies_percentage_discount_on_every_unit_in_order($adjustmentFactory, $originator, $priceRangeFilter, $taxonFilter, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemInterface $orderItem2, OrderItemInterface $orderItem3, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($originalItems);
     $originalItems->toArray()->willReturn([$orderItem1, $orderItem2, $orderItem3]);
     $priceRangeFilter->filter([$orderItem1, $orderItem2, $orderItem3], ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1, $orderItem2]);
     $taxonFilter->filter([$orderItem1, $orderItem2], ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1]);
     $orderItem1->getQuantity()->willReturn(2);
     $orderItem1->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $orderItem1->getUnitPrice()->willReturn(500);
     $promotion->getName()->willReturn('Test promotion');
     $adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2);
     $promotionAdjustment1->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled();
     $promotionAdjustment1->setAmount(-100)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
     $promotionAdjustment2->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
     $promotionAdjustment2->setAmount(-100)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment2, $promotion)->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment($promotionAdjustment2)->shouldBeCalled();
     $this->execute($order, ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]], $promotion);
 }
 /**
  * @Then /^(this promotion) should no longer exist in the promotion registry$/
  */
 public function promotionShouldNotExistInTheRegistry(PromotionInterface $promotion)
 {
     $this->indexPage->open();
     Assert::false($this->indexPage->isSingleResourceOnPage(['code' => $promotion->getCode()]), sprintf('Promotion with code %s exists but should not.', $promotion->getCode()));
 }
 /**
  * @param PromotionInterface $promotion
  * @param ActionInterface $action
  * @param array $configuration
  * @param RuleInterface|null $rule
  */
 private function persistPromotion(PromotionInterface $promotion, ActionInterface $action, array $configuration, RuleInterface $rule = null)
 {
     $configuration = array_merge($configuration, $action->getConfiguration());
     $action->setConfiguration($configuration);
     $promotion->addAction($action);
     if (null !== $rule) {
         $promotion->addRule($rule);
     }
     $this->objectManager->flush();
 }
 /**
  * @When /^I delete ("[^"]+" coupon) related to (this promotion)$/
  */
 public function iDeleteCouponRelatedTo(CouponInterface $coupon, PromotionInterface $promotion)
 {
     $this->sharedStorage->set('coupon', $coupon);
     $this->couponRepository->remove($coupon);
     $promotion->removeCoupon($coupon);
 }
 function it_reverts_a_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, ChannelInterface $channel, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
     $orderItem->getUnits()->willReturn(new ArrayCollection([$unit->getWrappedObject()]));
     $unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn(new ArrayCollection([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()]));
     $promotion->getCode()->willReturn('PROMOTION');
     $promotionAdjustment1->getOriginCode()->willReturn('PROMOTION');
     $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled();
     $promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION');
     $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled();
     $this->revert($order, ['WEB_US' => ['amount' => 1000]], $promotion);
 }
Beispiel #13
0
 /**
  * @param PromotionInterface $promotion
  * @param ActionInterface $action
  * @param array $configuration
  */
 private function persistPromotionWithAction(PromotionInterface $promotion, ActionInterface $action, array $configuration)
 {
     $configuration = array_merge($configuration, $action->getConfiguration());
     $action->setConfiguration($configuration);
     $promotion->addAction($action);
     $this->objectManager->flush();
 }
 function it_creates_a_fixed_discount_promotion_which_contains_a_taxon_rule(ActionFactoryInterface $actionFactory, ActionInterface $action, ObjectManager $objectManager, PromotionInterface $promotion, RuleFactoryInterface $ruleFactory, RuleInterface $rule, TaxonInterface $tanks)
 {
     $tanks->getCode()->willReturn('tanks');
     $ruleFactory->createContainsTaxon('tanks', 10)->willReturn($rule);
     $actionFactory->createFixedDiscount(500)->willReturn($action);
     $action->getConfiguration()->willReturn([]);
     $action->setConfiguration([])->shouldBeCalled();
     $promotion->addAction($action)->shouldBeCalled();
     $promotion->addRule($rule)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->thePromotionGivesOffIfOrderContainsNumberOfProductsClassifiedAs($promotion, 500, 10, $tanks);
 }
Beispiel #15
0
 function it_creates_item_percentage_discount_action_for_promotion_products_priced_between(ActionFactoryInterface $actionFactory, ActionInterface $action, ObjectManager $objectManager, PromotionInterface $promotion)
 {
     $actionFactory->createItemPercentageDiscount(0.1)->willReturn($action);
     $action->getConfiguration()->willReturn([]);
     $action->setConfiguration(['filters' => ['price_range' => ['min' => 5000, 'max' => 10000]]])->shouldBeCalled();
     $promotion->addAction($action)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->thisPromotionPercentageGivesOffOnEveryProductPricedBetween($promotion, 0.1, 5000, 10000);
 }
Beispiel #16
0
 /**
  * @Given /^([^"]+) gives ("[^"]+") percentage discount on shipping to every order$/
  */
 public function itGivesPercentageDiscountOnShippingToEveryOrder(PromotionInterface $promotion, $discount)
 {
     $action = $this->actionFactory->createPercentageShippingDiscount($discount);
     $promotion->addAction($action);
     $this->objectManager->flush();
 }