/** * {@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)); }
/** * {@inheritdoc} */ public function fillBackorders(StockableInterface $stockable) { $onHand = $stockable->getOnHand(); if ($onHand <= 0) { return; } $units = $this->repository->findBy(['stockable' => $stockable, 'inventoryState' => InventoryUnitInterface::STATE_BACKORDERED], ['createdAt' => 'ASC']); foreach ($units as $unit) { $unit->setInventoryState(InventoryUnitInterface::STATE_SOLD); if (--$onHand === 0) { break; } } $stockable->setOnHand($onHand); }