/** * {@inheritdoc} */ public function increase(StockableInterface $stockable, $quantity) { if ($quantity < 0) { throw new \InvalidArgumentException('Quantity of units must be greater than 0.'); } $this->eventDispatcher->dispatch(SyliusStockableEvents::PRE_INCREASE, new GenericEvent($stockable)); $stockable->setOnHand($stockable->getOnHand() + $quantity); $this->eventDispatcher->dispatch(SyliusStockableEvents::POST_INCREASE, new GenericEvent($stockable)); }
function it_partially_fills_backordered_units_and_updates_stock_accordingly(StockableInterface $stockable, InventoryUnitInterface $inventoryUnit1, InventoryUnitInterface $inventoryUnit2, ObjectRepository $repository) { $stockable->getOnHand()->shouldBeCalled()->willReturn(5); $stockable->setOnHand(3)->shouldBeCalled(); $inventoryUnit1->setInventoryState(InventoryUnitInterface::STATE_SOLD)->shouldBeCalled(); $inventoryUnit2->setInventoryState(InventoryUnitInterface::STATE_SOLD)->shouldBeCalled(); $repository->findBy(['stockable' => $stockable, 'inventoryState' => InventoryUnitInterface::STATE_BACKORDERED], ['createdAt' => 'ASC'])->willReturn([$inventoryUnit1, $inventoryUnit2]); $this->fillBackorders($stockable); }
/** * {@inheritdoc} */ public function fillBackorders(StockableInterface $stockable) { $onHand = $stockable->getOnHand(); if ($onHand <= 0) { return; } $units = $this->repository->findBy(array('stockable' => $stockable, 'inventoryState' => InventoryUnitInterface::STATE_BACKORDERED), array('createdAt' => 'ASC')); foreach ($units as $unit) { $unit->setInventoryState(InventoryUnitInterface::STATE_SOLD); if (--$onHand === 0) { break; } } $stockable->setOnHand($onHand); }
function it_increases_stockable_on_hand(StockableInterface $stockable) { $stockable->getOnHand()->shouldBeCalled()->willReturn(2); $stockable->setOnHand(7)->shouldBeCalled(); $this->increase($stockable, 5); }