diff --git a/vendor/magento/module-inventory-sales-admin-ui/Model/ResourceModel/GetStockItemData.php b/vendor/magento/module-inventory-sales-admin-ui/Model/ResourceModel/GetStockItemData.php new file mode 100644 index 00000000000..2b3c7011db6 --- /dev/null +++ b/vendor/magento/module-inventory-sales-admin-ui/Model/ResourceModel/GetStockItemData.php @@ -0,0 +1,88 @@ +resource = $resource; + $this->defaultStockProvider = $defaultStockProvider; + $this->getProductIdsBySkus = $getProductIdsBySkus; + $this->getCustomStockItemData = $getCustomStockItemData; + } + + /** + * @inheritdoc + */ + public function execute(string $sku, int $stockId): ?array + { + if ($this->defaultStockProvider->getId() !== $stockId) { + return $this->getCustomStockItemData->execute($sku, $stockId); + } + + $productId = current($this->getProductIdsBySkus->execute([$sku])); + $connection = $this->resource->getConnection(); + $select = $connection->select() + ->from( + $this->resource->getTableName('cataloginventory_stock_item'), + [ + GetStockItemDataInterface::QUANTITY => 'qty', + GetStockItemDataInterface::IS_SALABLE => 'is_in_stock', + ] + )->where( + 'product_id = ?', + $productId + ); + + try { + return $connection->fetchRow($select) ?: null; + } catch (\Exception $e) { + throw new LocalizedException(__('Could not receive Stock Item data'), $e); + } + } +} diff --git a/vendor/magento/module-inventory-sales-admin-ui/etc/adminhtml/di.xml b/vendor/magento/module-inventory-sales-admin-ui/etc/adminhtml/di.xml index 37c3b4688e7..9fce5d23d70 100644 --- a/vendor/magento/module-inventory-sales-admin-ui/etc/adminhtml/di.xml +++ b/vendor/magento/module-inventory-sales-admin-ui/etc/adminhtml/di.xml @@ -29,4 +29,14 @@ + + + Magento\InventorySalesAdminUi\Model\ResourceModel\GetStockItemData + + + + + GetProductSalableQtyAdminUi + +