function it_does_nothing_if_order_item_has_no_units(CalculatorInterface $calculator, AdjustmentFactoryInterface $adjustmentsFactory, TaxRateResolverInterface $taxRateResolver, OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant, TaxRateInterface $taxRate, ZoneInterface $zone) { $orderItems = new ArrayCollection([$orderItem->getWrappedObject()]); $order->getItems()->willReturn($orderItems); $orderItem->getVariant()->willReturn($productVariant); $orderItem->getUnits()->willReturn(new ArrayCollection()); $taxRateResolver->resolve(Argument::cetera())->willReturn($taxRate); $calculator->calculate(Argument::cetera())->shouldNotBeCalled(); $adjustmentsFactory->createWithData(Argument::cetera())->shouldNotBeCalled(); $this->apply($order, $zone); }
function it_does_nothing_if_the_tax_amount_is_0(CalculatorInterface $calculator, AdjustmentFactoryInterface $adjustmentsFactory, TaxRateResolverInterface $taxRateResolver, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod, TaxRateInterface $taxRate, ZoneInterface $zone) { $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); $shipment->getMethod()->willReturn($shippingMethod); $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn($taxRate); $order->getShippingTotal()->willReturn(1000); $calculator->calculate(1000, $taxRate)->willReturn(0); $adjustmentsFactory->createWithData(Argument::cetera())->shouldNotBeCalled(); $order->addAdjustment(Argument::any())->shouldNotBeCalled(); $this->apply($order, $zone); }
function it_does_nothing_if_there_are_no_shipment_taxes_on_order(CalculatorInterface $calculator, AdjustmentFactoryInterface $adjustmentsFactory, TaxRateResolverInterface $taxRateResolver, Collection $shippingAdjustments, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod, TaxRateInterface $taxRate, ZoneInterface $zone) { $order->getLastShipment()->willReturn($shipment); $shipment->getMethod()->willReturn($shippingMethod); $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn($taxRate); $order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn($shippingAdjustments); $shippingAdjustments->isEmpty()->willReturn(false); $order->getShippingTotal()->willReturn(1000); $calculator->calculate(1000, $taxRate)->willReturn(0); $adjustmentsFactory->createWithData(Argument::cetera())->shouldNotBeCalled(); $order->addAdjustment(Argument::any())->shouldNotBeCalled(); $this->apply($order, $zone); }
/** * @param OrderItemInterface $orderItem * @param int $increaseBy */ private function increaseUnitsNumber(OrderItemInterface $orderItem, $increaseBy) { for ($i = 0; $i < $increaseBy; ++$i) { $unit = $this->orderItemUnitFactory->createForItem($orderItem); if ($orderItem instanceof OrderItem) { /** @var AdjustmentInterface $adjustment */ $adjustment = $this->adjustmentFactory->createNew(); $adjustment->setType('tax'); $adjustment->setAmount($orderItem->getProduct()->getTax()); $unit->addAdjustment($adjustment); } } }
/** * @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); }
/** * @param PromotionInterface $promotion * @param OrderItemUnitInterface $unit * @param int $amount */ private function addAdjustment(PromotionInterface $promotion, OrderItemUnitInterface $unit, $amount) { $adjustment = $this->adjustmentFactory->createWithData(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT, $promotion->getName(), $amount); $adjustment->setOriginCode($promotion->getCode()); $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]); }
/** * @param OrderInterface $order * @param int $taxAmount * @param string $label * @param bool $included */ private function addAdjustment($order, $taxAmount, $label, $included) { /** @var AdjustmentInterface $shippingTaxAdjustment */ $shippingTaxAdjustment = $this->adjustmentFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, $label, $taxAmount, $included); $order->addAdjustment($shippingTaxAdjustment); }
function it_does_not_apply_taxes_with_amount_0(CalculatorInterface $calculator, AdjustmentFactoryInterface $adjustmentsFactory, IntegerDistributorInterface $distributor, 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(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(0); $taxRate->getLabel()->willReturn('Simple tax (0%)'); $taxRate->isIncludedInPrice()->willReturn(false); $orderItem->getUnits()->willReturn($units); $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()])); $distributor->distribute(0, 2)->willReturn([0, 0]); $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, 'Simple tax (0%)', 0, false)->shouldNotBeCalled(); $this->apply($order, $zone); }