/**
  * {@inheritdoc}
  */
 public function isStockSufficient(StockableInterface $stockable, $quantity)
 {
     if ($stockable instanceof SoftDeletableInterface && $stockable->isDeleted()) {
         return false;
     }
     if ($this->backorders || $stockable->isAvailableOnDemand()) {
         return true;
     }
     return $quantity <= $stockable->getOnHand() - $stockable->getOnHold();
 }
 /**
  * {@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);
 }
 /**
  * {@inheritdoc}
  */
 public function release(StockableInterface $stockable, $quantity)
 {
     if ($quantity < 0) {
         throw new \InvalidArgumentException('Quantity of units must be greater than 0.');
     }
     $this->eventDispatcher->dispatch(SyliusStockableEvents::PRE_RELEASE, new GenericEvent($stockable));
     $stockable->setOnHold($stockable->getOnHold() - $quantity);
     $this->eventDispatcher->dispatch(SyliusStockableEvents::POST_RELEASE, new GenericEvent($stockable));
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function getInventoryName()
 {
     return $this->stockable->getInventoryName();
 }
 /**
  * @param StockableInterface $stockable
  * @param int            $quantity
  */
 public function __construct(StockableInterface $stockable, $quantity)
 {
     $this->stockable = $stockable;
     parent::__construct(sprintf('Only %d %s(s) on hand, %d requested.', $stockable->getOnHand(), $stockable->getInventoryName(), $quantity));
 }