/** * @param Product $product * @param int $quantity * @throws InventoryException * @throws InsufficientInventoryException * @throws EntityValidatorException */ public function reserveProduct(Product $product, $quantity) { if (!$product->isInventoryRequired()) { // TODO: Investigate throwing exception in this case return; } try { $inventoryHoldLocation = $this->inventoryLocationRepository->findOneById($this->inventoryHoldLocationId); } catch (EntityNotFoundException $e) { throw InventoryException::missingInventoryHoldLocation(); } try { $inventoryLocationId = $this->inventoryTransactionRepository->findInventoryIdForProductAndQuantity($product, $quantity); $inventoryLocation = $this->inventoryLocationRepository->findOneById($inventoryLocationId); } catch (EntityNotFoundException $e) { throw new InsufficientInventoryException(); } $this->transferProduct($product, $quantity, 'Hold ' . ngettext('item', 'items', $quantity) . ' for order', $inventoryLocation, $inventoryHoldLocation, InventoryTransactionType::hold()); }
public function testFindInventoryIdForProductAndQuantityThrowsException() { $this->setExpectedException(EntityNotFoundException::class, 'InventoryTransaction not found'); $product = $this->dummyData->getProduct(); $this->inventoryTransactionRepository->findInventoryIdForProductAndQuantity($product, 2); }