6 declare(strict_types=1);
14 use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterfaceFactory;
15 use Magento\InventorySalesApi\Api\Data\ProductSalabilityErrorInterfaceFactory;
27 private $getStockItemData;
32 private $getReservationsQuantity;
37 private $getStockItemConfiguration;
42 private $productSalabilityErrorFactory;
47 private $productSalableResultFactory;
60 ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory,
61 ProductSalableResultInterfaceFactory $productSalableResultFactory
63 $this->getStockItemData = $getStockItemData;
64 $this->getReservationsQuantity = $getReservationsQuantity;
65 $this->getStockItemConfiguration = $getStockItemConfiguration;
66 $this->productSalabilityErrorFactory = $productSalabilityErrorFactory;
67 $this->productSalableResultFactory = $productSalableResultFactory;
76 $stockItemData = $this->getStockItemData->execute($sku, $stockId);
77 if (
null === $stockItemData) {
79 $this->productSalabilityErrorFactory->create([
80 'code' =>
'is_salable_with_reservations-no_data',
81 'message' =>
__(
'The requested sku is not assigned to given stock')
84 return $this->productSalableResultFactory->create([
'errors' =>
$errors]);
88 $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
91 $this->getReservationsQuantity->execute($sku, $stockId);
92 $qtyLeftInStock = $qtyWithReservation - $stockItemConfiguration->getMinQty() - $requestedQty;
96 $this->productSalabilityErrorFactory->create([
97 'code' =>
'is_salable_with_reservations-not_enough_qty',
98 'message' =>
__(
'The requested qty is not available')
101 return $this->productSalableResultFactory->create([
'errors' =>
$errors]);
103 return $this->productSalableResultFactory->create([
'errors' => []]);
__construct(GetStockItemDataInterface $getStockItemData, GetReservationsQuantityInterface $getReservationsQuantity, GetStockItemConfigurationInterface $getStockItemConfiguration, ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory, ProductSalableResultInterfaceFactory $productSalableResultFactory)
execute(string $sku, int $stockId, float $requestedQty)