function it_returns_false_if_variant_is_not_included_and_exclude_is_not_set(OrderInterface $subject, OrderItem $orderItem, ProductVariant $variant) { $subject->getItems()->willReturn([$orderItem]); $orderItem->getVariant()->willReturn($variant); $variant->getId()->willReturn(2); $this->isEligible($subject, ['variant' => 1, 'exclude' => false])->shouldReturn(false); }
/** * {@inheritdoc} */ public function holdInventory(OrderInterface $order) { foreach ($order->getItems() as $item) { $quantity = $this->applyTransition($item->getUnits(), InventoryUnitTransitions::SYLIUS_HOLD); $this->inventoryOperator->hold($item->getVariant(), $quantity); } }
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); }
/** * @param OrderInterface $order */ public function decreaseSoldVariants(OrderInterface $order) { /** @var $item OrderItemInterface */ foreach ($order->getItems() as $item) { $variant = $item->getVariant(); $variant->setSold($variant->getSold() - $item->getQuantity()); } }
function it_returns_false_if_variant_is_included_and_count_is_set_bigger_amount_than_quantity(OrderInterface $subject, OrderItem $orderItem, ProductVariant $variant) { $subject->getItems()->willReturn([$orderItem]); $orderItem->getVariant()->willReturn($variant); $variant->getId()->willReturn(1); $orderItem->getPromotionSubjectCount()->willReturn(1); $this->isEligible($subject, ['variant' => 1, 'exclude' => false, 'count' => 2])->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); }
function it_doesnt_apply_any_taxes_if_zone_is_missing(OrderInterface $order, Collection $collection, $taxationSettings) { $collection->isEmpty()->willReturn(false); $order->getItems()->willReturn($collection); $order->removeTaxAdjustments()->shouldBeCalled(); $order->getShippingAddress()->willReturn(null); $taxationSettings->has('default_tax_zone')->willReturn(false); $order->addAdjustment(Argument::any())->shouldNotBeCalled(); $this->applyTaxes($order); }
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_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); }
/** * {@inheritdoc} */ public function decrease(OrderInterface $order) { /** @var OrderItemInterface $orderItem */ foreach ($order->getItems() as $orderItem) { $variant = $orderItem->getVariant(); if ($variant->isTracked()) { Assert::greaterThanEq($variant->getOnHold() - $orderItem->getQuantity(), 0, sprintf('Not enough units to decrease the inventory of a variant "%s".', $variant->getName())); $variant->setOnHold($variant->getOnHold() - $orderItem->getQuantity()); } } }
/** * @param OrderInterface $order */ private function giveBack(OrderInterface $order) { /** @var OrderItemInterface $orderItem */ foreach ($order->getItems() as $orderItem) { $variant = $orderItem->getVariant(); if (!$variant->isTracked()) { continue; } $variant->setOnHand($variant->getOnHand() + $orderItem->getQuantity()); } }
/** * {@inheritdoc} */ public function apply(OrderInterface $order, PromotionInterface $promotion, array $adjustmentsAmounts) { Assert::eq($order->countItems(), count($adjustmentsAmounts)); $i = 0; foreach ($order->getItems() as $item) { $adjustmentAmount = $adjustmentsAmounts[$i++]; if (0 === $adjustmentAmount) { continue; } $this->applyAdjustmentsOnItemUnits($item, $promotion, $adjustmentAmount); } }
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_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_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); }
function it_does_not_process_taxes_if_there_is_no_tax_zone(ZoneProviderInterface $defaultTaxZoneProvider, ZoneMatcherInterface $zoneMatcher, PrioritizedServiceRegistryInterface $strategyRegistry, OrderInterface $order, OrderItemInterface $orderItem, AddressInterface $address) { $order->getItems()->willReturn([$orderItem]); $order->isEmpty()->willReturn(false); $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); $order->getShippingAddress()->willReturn($address); $zoneMatcher->match($address)->willReturn(null); $defaultTaxZoneProvider->getZone($order)->willReturn(null); $strategyRegistry->all()->shouldNotBeCalled(); $this->process($order); }
function it_reverts_product($orderItemQuantityModifier, $variantRepository, FactoryInterface $itemFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, PromotionInterface $promotion) { $variantRepository->find(500)->willReturn($variant); $itemFactory->createNew()->willReturn($item); $item->setUnitPrice(2)->willReturn($item); $item->setVariant($variant)->willReturn($item); $orderItemQuantityModifier->modify($item, 3)->shouldBeCalled(); $item->equals($item)->willReturn(true); $item->setImmutable(true)->shouldBeCalled(); $order->getItems()->willReturn([$item]); $order->removeItem($item)->shouldBeCalled(); $this->revert($order, ['variant' => 500, 'quantity' => 3, 'price' => 2], $promotion); }
function it_reverts_product(RepositoryInterface $variantRepository, RepositoryInterface $itemRepository, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, PromotionInterface $promotion) { $configuration = array('variant' => 500, 'quantity' => 3, 'price' => 2); $variantRepository->find($configuration['variant'])->willReturn($variant); $itemRepository->createNew()->willReturn($item); $item->setUnitPrice($configuration['price'])->shouldBeCalled()->willReturn($item); $item->setVariant($variant)->shouldBeCalled()->willReturn($item); $item->setQuantity($configuration['quantity'])->shouldBeCalled()->willReturn($item); $item->equals($item)->willReturn(true); $order->getItems()->willReturn(array($item)); $order->removeItem($item)->shouldBeCalled(); $this->revert($order, $configuration, $promotion); }
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); }
function it_reverts_proper_promotion_adjustment_from_all_units($originator, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $items, Collection $units, Collection $adjustments, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion, PromotionInterface $someOtherPromotion) { $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()])); $originator->getOrigin($promotionAdjustment1)->willReturn($promotion); $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled(); $originator->getOrigin($promotionAdjustment2)->willReturn($someOtherPromotion); $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled(); $this->revert($order, ['percentage' => 0.2], $promotion); }
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 apply(OrderInterface $order, ZoneInterface $zone) { foreach ($order->getItems() as $item) { $taxRate = $this->taxRateResolver->resolve($item->getVariant(), ['zone' => $zone]); if (null === $taxRate) { continue; } foreach ($item->getUnits() as $unit) { $taxAmount = $this->calculator->calculate($unit->getTotal(), $taxRate); if (0 === $taxAmount) { continue; } $this->addTaxAdjustment($unit, $taxAmount, $taxRate->getLabel(), $taxRate->isIncludedInPrice()); } } }
function it_does_not_apply_taxes_if_there_is_no_tax_zone($defaultTaxZoneProvider, $zoneMatcher, $orderItemsTaxesApplicator, AddressInterface $address, \Iterator $iterator, Collection $items, OrderInterface $order, OrderItemInterface $orderItem) { $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); $order->getItems()->willReturn($items); $order->isEmpty()->willReturn(false); $items->count()->willReturn(1); $items->getIterator()->willReturn($iterator); $iterator->rewind()->shouldBeCalled(); $iterator->valid()->willReturn(true, false)->shouldBeCalled(); $iterator->current()->willReturn($orderItem); $iterator->next()->shouldBeCalled(); $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); $order->getShippingAddress()->willReturn($address); $zoneMatcher->match($address)->willReturn(null); $defaultTaxZoneProvider->getZone()->willReturn(null); $orderItemsTaxesApplicator->apply(Argument::any())->shouldNotBeCalled(); $this->apply($order); }
/** * {@inheritdoc} */ public function recalculate(OrderInterface $order) { $context = []; if (null !== ($customer = $order->getCustomer())) { $context['customer'] = $customer; $context['groups'] = $customer->getGroups()->toArray(); } if (null !== $order->getChannel()) { $context['channel'] = [$order->getChannel()]; } foreach ($order->getItems() as $item) { if ($item->isImmutable()) { continue; } $context['quantity'] = $item->getQuantity(); $item->setUnitPrice($this->priceCalculator->calculate($item->getVariant(), $context)); } }
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); }
/** * {@inheritdoc} */ public function updateInventory(OrderInterface $order) { foreach ($order->getItems() as $item) { $units = $item->getUnits(); $quantity = 0; foreach ($units as $unit) { $stateMachine = $this->stateMachineFactory->get($unit, InventoryUnitTransitions::GRAPH); if ($stateMachine->can(InventoryUnitTransitions::SYLIUS_SELL)) { if ($stateMachine->can(InventoryUnitTransitions::SYLIUS_RELEASE)) { ++$quantity; } $stateMachine->apply(InventoryUnitTransitions::SYLIUS_SELL); } } $this->inventoryOperator->release($item->getVariant(), $quantity); $this->inventoryOperator->decrease($units); } }
/** * {@inheritdoc} */ public function apply(OrderInterface $order, ZoneInterface $zone) { foreach ($order->getItems() as $item) { $quantity = $item->getQuantity(); if (0 === $quantity) { continue; } $taxRate = $this->taxRateResolver->resolve($item->getProduct(), array('zone' => $zone)); if (null === $taxRate) { continue; } $totalTaxAmount = $this->calculator->calculate($item->getTotal(), $taxRate); $splitTaxes = $this->distributor->distribute($totalTaxAmount, $quantity); $units = $item->getUnits(); foreach ($splitTaxes as $key => $tax) { if (0 === $tax) { continue; } $this->addAdjustment($units->get($key), $tax, $taxRate->getLabel(), $taxRate->isIncludedInPrice()); } } }
/** * {@inheritdoc} */ public function apply(OrderInterface $order, ZoneInterface $zone) { foreach ($order->getItems() as $item) { $quantity = $item->getQuantity(); if (0 === $quantity) { throw new \InvalidArgumentException('Cannot apply tax to order item with 0 quantity.'); } $taxRate = $this->taxRateResolver->resolve($item->getVariant(), ['zone' => $zone]); if (null === $taxRate) { continue; } $totalTaxAmount = $this->calculator->calculate($item->getTotal(), $taxRate); $splitTaxes = $this->distributor->distribute($totalTaxAmount, $quantity); $i = 0; foreach ($item->getUnits() as $unit) { if (0 === $splitTaxes[$i]) { continue; } $this->addAdjustment($unit, $splitTaxes[$i], $taxRate->getLabel(), $taxRate->isIncludedInPrice()); $i++; } } }
function it_does_nothing_if_variant_is_not_tracked_during_selling(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $variant) { $order->getItems()->willReturn([$orderItem]); $orderItem->getVariant()->willReturn($variant); $variant->isTracked()->willReturn(false); $variant->setOnHold(Argument::any())->shouldNotBeCalled(); $variant->setOnHand(Argument::any())->shouldNotBeCalled(); $this->sell($order); }