/** * {@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_decreases_the_variant_stock_via_inventory_operator($inventoryOperator, $factory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, InventoryUnitInterface $unit1, InventoryUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2) { $order->getItems()->willReturn(array($item)); $item->getVariant()->willReturn($variant); $item->getQuantity()->willReturn(2); $item->getInventoryUnits()->shouldBeCalled()->willReturn(array($unit1, $unit2)); $factory->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(); $factory->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(array($unit1, $unit2))->shouldBeCalled(); $inventoryOperator->release($variant, 1)->shouldBeCalled(); $this->updateInventory($order); }
function it_not_a_backorder_if_contains_no_backordered_units(InventoryUnitInterface $unit1, InventoryUnitInterface $unit2, OrderItemInterface $item) { $unit1->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD); $unit2->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD); $item->getInventoryUnits()->willReturn(array($unit1, $unit2)); $item->setOrder($this)->shouldBeCalled(); $this->addItem($item); $this->shouldNotBeBackorder(); }