function it_applies_percentage_discount_on_every_unit_in_order(FactoryInterface $adjustmentFactory, FilterInterface $priceRangeFilter, FilterInterface $taxonFilter, FilterInterface $productFilter, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($originalItems);
     $originalItems->toArray()->willReturn([$orderItem1]);
     $priceRangeFilter->filter([$orderItem1], ['percentage' => 0.2])->willReturn([$orderItem1]);
     $taxonFilter->filter([$orderItem1], ['percentage' => 0.2])->willReturn([$orderItem1]);
     $productFilter->filter([$orderItem1], ['percentage' => 0.2])->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');
     $promotion->getCode()->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();
     $promotionAdjustment1->setOriginCode('TEST_PROMOTION')->shouldBeCalled();
     $promotionAdjustment2->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
     $promotionAdjustment2->setAmount(-100)->shouldBeCalled();
     $promotionAdjustment2->setOriginCode('TEST_PROMOTION')->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment($promotionAdjustment2)->shouldBeCalled();
     $this->execute($order, ['percentage' => 0.2], $promotion);
 }
 function it_applies_taxes_on_units_based_on_item_total_and_rate($adjustmentsFactory, $calculator, $distributor, $taxRateResolver, AdjustmentInterface $taxAdjustment1, AdjustmentInterface $taxAdjustment2, Collection $items, Collection $units, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, ProductVariantInterface $productVariant, TaxRateInterface $taxRate, ZoneInterface $zone)
 {
     $order->getItems()->willReturn($items);
     $items->count()->willReturn(1);
     $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
     $orderItem->getQuantity()->willReturn(2);
     $orderItem->getVariant()->willReturn($productVariant);
     $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate);
     $orderItem->getTotal()->willReturn(1000);
     $calculator->calculate(1000, $taxRate)->willReturn(100);
     $taxRate->getLabel()->willReturn('Simple tax (10%)');
     $taxRate->isIncludedInPrice()->willReturn(false);
     $orderItem->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $distributor->distribute(100, 2)->willReturn([50, 50]);
     $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, 'Simple tax (10%)', 50, false)->willReturn($taxAdjustment1, $taxAdjustment2);
     $unit1->addAdjustment($taxAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment($taxAdjustment2)->shouldBeCalled();
     $this->apply($order, $zone);
 }
 /**
  * @param OrderItemUnitInterface $unit
  * @param int $taxAmount
  * @param string $label
  * @param bool $included
  */
 private function addAdjustment(OrderItemUnitInterface $unit, $taxAmount, $label, $included)
 {
     $unitTaxAdjustment = $this->adjustmentFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, $label, $taxAmount, $included);
     $unit->addAdjustment($unitTaxAdjustment);
 }
 function it_does_not_apply_taxes_with_amount_0(CalculatorInterface $calculator, AdjustmentFactoryInterface $adjustmentsFactory, TaxRateResolverInterface $taxRateResolver, Collection $items, Collection $units, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, ProductVariantInterface $productVariant, TaxRateInterface $taxRate, ZoneInterface $zone)
 {
     $order->getItems()->willReturn($items);
     $items->count()->willReturn(2);
     $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
     $orderItem->getQuantity()->willReturn(2);
     $orderItem->getVariant()->willReturn($productVariant);
     $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate);
     $orderItem->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $unit1->getTotal()->willReturn(1000);
     $calculator->calculate(1000, $taxRate)->willReturn(0);
     $unit2->getTotal()->willReturn(900);
     $calculator->calculate(900, $taxRate)->willReturn(0);
     $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, Argument::cetera())->shouldNotBeCalled();
     $unit1->addAdjustment(Argument::any())->shouldNotBeCalled();
     $unit2->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->apply($order, $zone);
 }
Ejemplo n.º 5
0
 /**
  * @param OrderItemUnitInterface $unit
  * @param int $amount
  * @param PromotionInterface $promotion
  */
 protected function addAdjustmentToUnit(OrderItemUnitInterface $unit, $amount, PromotionInterface $promotion)
 {
     $adjustment = $this->createAdjustment($promotion, AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT);
     $adjustment->setAmount(-$amount);
     $unit->addAdjustment($adjustment);
 }
 function it_does_not_distribute_0_amount_to_unit_even_if_its_middle_element(AdjustmentFactoryInterface $adjustmentFactory, AdjustmentInterface $adjustment, IntegerDistributorInterface $distributor, OrderInterface $order, OrderItemInterface $coltItem, OrderItemUnitInterface $firstColtUnit, OrderItemUnitInterface $secondColtUnit, PromotionInterface $promotion)
 {
     $order->countItems()->willReturn(1);
     $order->getItems()->willReturn(new ArrayCollection([$coltItem->getWrappedObject()]));
     $coltItem->getQuantity()->willReturn(2);
     $distributor->distribute(1, 2)->willReturn([1, 0]);
     $coltItem->getUnits()->willReturn(new ArrayCollection([$firstColtUnit->getWrappedObject(), $secondColtUnit->getWrappedObject()]));
     $promotion->getName()->willReturn('Winter guns promotion!');
     $promotion->getCode()->willReturn('WINTER_GUNS_PROMOTION');
     $adjustmentFactory->createWithData(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT, 'Winter guns promotion!', 1)->willReturn($adjustment);
     $adjustment->setOriginCode('WINTER_GUNS_PROMOTION')->shouldBeCalled();
     $firstColtUnit->addAdjustment($adjustment)->shouldBeCalled();
     $secondColtUnit->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->apply($order, $promotion, [1]);
 }
Ejemplo n.º 7
0
 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);
 }
 function it_does_not_apply_bigger_discount_than_unit_total(ChannelInterface $channel, FactoryInterface $adjustmentFactory, FilterInterface $priceRangeFilter, FilterInterface $taxonFilter, FilterInterface $productFilter, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $order->getItems()->willReturn(new ArrayCollection([$orderItem]));
     $order->getChannel()->willReturn($channel);
     $priceRangeFilter->filter([$orderItem], ['amount' => 1000, 'channel' => $channel])->willReturn([$orderItem]);
     $taxonFilter->filter([$orderItem], ['amount' => 1000])->willReturn([$orderItem]);
     $productFilter->filter([$orderItem], ['amount' => 1000])->willReturn([$orderItem]);
     $orderItem->getQuantity()->willReturn(2);
     $orderItem->getUnits()->willReturn(new ArrayCollection([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $promotion->getName()->willReturn('Test promotion');
     $promotion->getCode()->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();
     $promotionAdjustment1->setOriginCode('TEST_PROMOTION')->shouldBeCalled();
     $unit2->getTotal()->willReturn(200);
     $promotionAdjustment2->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled();
     $promotionAdjustment2->setAmount(-200)->shouldBeCalled();
     $promotionAdjustment2->setOriginCode('TEST_PROMOTION')->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment($promotionAdjustment2)->shouldBeCalled();
     $this->execute($order, ['WEB_US' => ['amount' => 1000]], $promotion)->shouldReturn(true);
 }
 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);
 }