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_returns_regular_price_of_discount_order_item(OrderItemInterface $orderItem) { $orderItem->getQuantity()->willReturn(2); $orderItem->getUnitPrice()->willReturn(1000); $orderItem->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->willReturn(1000); $this->getRegularPrice($orderItem)->shouldReturn(3000); }
function it_executes_request(InvoiceNumberGeneratorInterface $invoiceNumberGenerator, CurrencyConverterInterface $currencyConverter, Convert $request, PaymentInterface $payment, OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant, ProductInterface $product) { $request->getTo()->willReturn('array'); $payment->getId()->willReturn(19); $order->getId()->willReturn(92); $order->getId()->willReturn(92); $order->getCurrencyCode()->willReturn('PLN'); $order->getTotal()->willReturn(22000); $order->getItems()->willReturn([$orderItem]); $order->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->willReturn(0); $order->getOrderPromotionTotal()->willReturn(0); $order->getShippingTotal()->willReturn(2000); $orderItem->getVariant()->willReturn($productVariant); $orderItem->getDiscountedUnitPrice()->willReturn(20000); $orderItem->getQuantity()->willReturn(1); $productVariant->getProduct()->willReturn($product); $product->getName()->willReturn('Lamborghini Aventador Model'); $request->getSource()->willReturn($payment); $payment->getOrder()->willReturn($order); $invoiceNumberGenerator->generate($order, $payment)->willReturn('19-92'); $currencyConverter->convertFromBase(22000, 'PLN')->willReturn(88000); $currencyConverter->convertFromBase(20000, 'PLN')->willReturn(80000); $currencyConverter->convertFromBase(2000, 'PLN')->willReturn(8000); $details = ['PAYMENTREQUEST_0_INVNUM' => '19-92', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'PLN', 'PAYMENTREQUEST_0_AMT' => 880.0, 'PAYMENTREQUEST_0_ITEMAMT' => 880.0, 'L_PAYMENTREQUEST_0_NAME0' => 'Lamborghini Aventador Model', 'L_PAYMENTREQUEST_0_AMT0' => 800.0, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'L_PAYMENTREQUEST_0_NAME1' => 'Shipping Total', 'L_PAYMENTREQUEST_0_AMT1' => 80.0, 'L_PAYMENTREQUEST_0_QTY1' => 1]; $request->setResult($details)->shouldBeCalled(); $this->execute($request); }
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_nothing_if_target_quantity_is_below_0($orderItemUnitFactory, OrderItemInterface $orderItem) { $orderItem->getQuantity()->willReturn(3); $orderItemUnitFactory->createForItem(Argument::any())->shouldNotBeCalled(); $orderItem->addUnit(Argument::any())->shouldNotBeCalled(); $orderItem->removeUnit(Argument::any())->shouldNotBeCalled(); $this->modify($orderItem, -10); }
/** * @param OrderItemInterface $item * @param array $configuration * * @return bool */ private function isItemEligible(OrderItemInterface $item, array $configuration) { if (!$configuration['exclude']) { if (isset($configuration['count'])) { return $this->isItemQuantityEligible($item->getQuantity(), $configuration); } return true; } return false; }
function it_throws_exception_when_recalculated_on_hand_quantity_is_lower_than_zero(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant) { $order->getItems()->willReturn([$orderItem]); $orderItem->getQuantity()->willReturn(5); $orderItem->getVariant()->willReturn($productVariant); $productVariant->isTracked()->willReturn(true); $productVariant->getOnHand()->willReturn(4); $productVariant->getName()->willReturn('Variant'); $this->shouldThrow(\InvalidArgumentException::class)->during('decrease', [$order]); }
function it_recalculates_prices_without_adding_anything_to_the_context_if_its_not_needed(DelegatingCalculatorInterface $priceCalculator, OrderInterface $order, OrderItemInterface $item, PriceableInterface $variant) { $order->getCustomer()->willReturn(null); $order->getChannel()->willReturn(null); $order->getItems()->willReturn([$item]); $item->isImmutable()->willReturn(false); $item->getQuantity()->willReturn(5); $item->getVariant()->willReturn($variant); $priceCalculator->calculate($variant, ['quantity' => 5])->willReturn(10); $item->setUnitPrice(10)->shouldBeCalled(); $this->process($order); }
/** * @param OrderItemInterface $item * @param PromotionInterface $promotion * @param int $itemPromotionAmount */ private function applyAdjustmentsOnItemUnits(OrderItemInterface $item, PromotionInterface $promotion, $itemPromotionAmount) { $splitPromotionAmount = $this->distributor->distribute($itemPromotionAmount, $item->getQuantity()); $i = 0; foreach ($item->getUnits() as $unit) { $promotionAmount = $splitPromotionAmount[$i++]; if (0 === $promotionAmount) { continue; } $this->addAdjustment($promotion, $unit, $promotionAmount); } }
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_recalculates_prices_adding_customer_to_the_context(ChannelInterface $channel, CustomerGroupInterface $group, CustomerInterface $customer, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator) { $order->getCustomer()->willReturn($customer); $order->getChannel()->willReturn(null); $order->getItems()->willReturn([$item]); $order->getCurrencyCode()->willReturn(null); $customer->getGroup()->willReturn($group); $item->isImmutable()->willReturn(false); $item->getQuantity()->willReturn(5); $item->getVariant()->willReturn($variant); $order->getChannel()->willReturn($channel); $productVariantPriceCalculator->calculate($variant, ['channel' => $channel])->willReturn(10); $item->setUnitPrice(10)->shouldBeCalled(); $this->process($order); }
function it_holds_the_variant_stock_via_inventory_operator($inventoryOperator, $stateMachineFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2) { $order->getItems()->willReturn([$item]); $item->getVariant()->willReturn($variant); $item->getQuantity()->willReturn(2); $item->getUnits()->willReturn(new ArrayCollection([$unit1, $unit2])); $stateMachineFactory->get($unit1, InventoryUnitTransitions::GRAPH)->willReturn($sm1); $sm1->can(InventoryUnitTransitions::SYLIUS_HOLD)->willReturn(false); $sm1->apply(InventoryUnitTransitions::SYLIUS_HOLD)->shouldNotBeCalled(); $stateMachineFactory->get($unit2, InventoryUnitTransitions::GRAPH)->willReturn($sm2); $sm1->can(InventoryUnitTransitions::SYLIUS_HOLD)->willReturn(true); $sm1->apply(InventoryUnitTransitions::SYLIUS_HOLD)->shouldBeCalled(); $inventoryOperator->hold($variant, 1)->shouldBeCalled(); $this->holdInventory($order); }
/** * {@inheritdoc} */ public function processInventoryUnits(OrderItemInterface $item) { $nbUnits = $item->getInventoryUnits()->count(); if ($item->getQuantity() > $nbUnits) { $this->createInventoryUnits($item, $item->getQuantity() - $nbUnits); } elseif ($item->getQuantity() < $nbUnits) { foreach ($item->getInventoryUnits()->slice(0, $nbUnits - $item->getQuantity()) as $unit) { $item->removeInventoryUnit($unit); } } foreach ($item->getInventoryUnits() as $unit) { if ($unit->getStockable() !== $item->getVariant()) { $unit->setStockable($item->getVariant()); } } }
function it_recalculates_prices_adding_all_context(GenericEvent $event, OrderInterface $order, OrderItemInterface $item, DelegatingCalculatorInterface $priceCalculator, GroupableInterface $customer, ArrayCollection $groups, ChannelInterface $channel, PriceableInterface $variant) { $event->getSubject()->shouldBeCalled()->willReturn($order); $order->getCustomer()->shouldBeCalled()->willReturn($customer); $order->getChannel()->shouldBeCalled()->willReturn($channel); $order->getItems()->shouldBeCalled()->willReturn(array($item)); $order->calculateTotal()->shouldBeCalled(); $customer->getGroups()->shouldBeCalled()->willReturn($groups); $groups->toArray()->shouldBeCalled()->willReturn(array('group1', 'group2')); $item->isImmutable()->shouldBeCalled()->willReturn(false); $item->getQuantity()->shouldBeCalled()->willReturn(5); $item->setUnitPrice(10)->shouldBeCalled(); $item->getVariant()->shouldBeCalled()->willReturn($variant); $priceCalculator->calculate($variant, array('customer' => $customer, 'groups' => array('group1', 'group2'), 'channel' => array($channel), 'quantity' => 5))->shouldBeCalled()->willReturn(10); $this->recalculatePrices($event); }
function it_decreases_the_variant_stock_via_inventory_operator($inventoryOperator, $stateMachineFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2) { $order->getItems()->willReturn([$item]); $item->getVariant()->willReturn($variant); $item->getQuantity()->willReturn(2); $item->getUnits()->shouldBeCalled()->willReturn([$unit1, $unit2]); $stateMachineFactory->get($unit1, InventoryUnitTransitions::GRAPH)->willReturn($sm1); $sm1->can(InventoryUnitTransitions::SYLIUS_SELL)->willReturn(true); $sm1->can(InventoryUnitTransitions::SYLIUS_RELEASE)->willReturn(true); $sm1->apply(InventoryUnitTransitions::SYLIUS_SELL)->shouldBeCalled(); $stateMachineFactory->get($unit2, InventoryUnitTransitions::GRAPH)->willReturn($sm2); $sm2->can(InventoryUnitTransitions::SYLIUS_SELL)->willReturn(true); $sm2->can(InventoryUnitTransitions::SYLIUS_RELEASE)->willReturn(false); $sm2->apply(InventoryUnitTransitions::SYLIUS_SELL)->shouldBeCalled(); $inventoryOperator->decrease([$unit1, $unit2])->shouldBeCalled(); $inventoryOperator->release($variant, 1)->shouldBeCalled(); $this->updateInventory($order); }
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_throws_invalid_argument_exception_if_difference_between_on_hand_and_item_quantity_is_smaller_than_zero_during_selling(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $variant) { $order->getItems()->willReturn([$orderItem]); $orderItem->getVariant()->willReturn($variant); $variant->isTracked()->willReturn(true); $orderItem->getQuantity()->willReturn(10); $variant->getOnHold()->willReturn(10); $variant->getOnHand()->willReturn(5); $variant->getName()->willReturn('Red Skirt'); $this->shouldThrow(\InvalidArgumentException::class)->during('sell', [$order]); }
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); }
function it_does_not_add_violation_if_total_quantity_of_cart_items_do_not_exceed_available_quantity(ExecutionContextInterface $executionContext, AvailabilityCheckerInterface $availabilityChecker, AddToCartCommandInterface $addCartItemCommand, OrderInterface $order, OrderItemInterface $orderItem, OrderItemInterface $existingOrderItem, ProductVariantInterface $productVariant) { $addCartItemCommand->getCart()->willReturn($order); $addCartItemCommand->getCartItem()->willReturn($orderItem); $orderItem->getVariant()->willReturn($productVariant); $orderItem->getQuantity()->willReturn(10); $existingOrderItem->equals($orderItem)->willReturn(true); $order->getItems()->willReturn([$existingOrderItem]); $existingOrderItem->getQuantity()->willReturn(10); $availabilityChecker->isStockSufficient($productVariant, 20)->willReturn(true); $executionContext->addViolation(Argument::any(), Argument::any())->shouldNotBeCalled(); $cartItemAvailabilityConstraint = new CartItemAvailability(); $cartItemAvailabilityConstraint->message = 'Insufficient stock'; $this->validate($addCartItemCommand, $cartItemAvailabilityConstraint); }
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]); }
function it_does_not_apply_taxes_with_amount_0($adjustmentsFactory, $calculator, $distributor, $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); }
function it_throws_invalid_argument_exception_if_on_hold_quantity_to_decrease_will_be_below_zero(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant) { $productVariant->getOnHold()->willReturn(5); $productVariant->isTracked()->willReturn(true); $productVariant->getName()->willReturn('t-shirt'); $orderItem->getVariant()->willReturn($productVariant); $orderItem->getQuantity()->willReturn(10); $order->getItems()->willReturn([$orderItem]); $productVariant->setOnHold(-5)->shouldNotBeCalled(); $this->shouldThrow(\InvalidArgumentException::class)->during('decrease', [$order]); }
/** * @param OrderItemInterface $orderItem * * @return int */ public function getRegularPrice(OrderItemInterface $orderItem) { return $orderItem->getUnitPrice() * $orderItem->getQuantity() + $orderItem->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT); }
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); }