I need to retrieve product quantity, I found that, the interfaces we used before to get product quantity are deprecated, these are:

\Magento\CatalogInventory\Api\StockStateInterface $stockItem


\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry

Below link says StockStateInterface is replaced with Multi Source Inventory but I cannot see a function returning product quantity in it.


Is there some other way to get product quantity? I don't want to use deprecated code.


Here is the sample code:


namespace SR\MagentoCommunity\Model;

use Magento\InventoryCatalog\Model\GetStockIdForCurrentWebsite;
use Magento\InventorySales\Model\GetProductSalableQty;
use Magento\InventorySalesApi\Model\GetStockItemDataInterface;

class Stock
     * @var GetProductSalableQty
    private $getProductSalableQty;

     * @var GetStockIdForCurrentWebsite
    private $getStockIdForCurrentWebsite;

     * @var GetStockItemDataInterface
    private $getStockItemData;

     * Stock constructor.
     * @param GetProductSalableQty $getProductSalableQty
     * @param GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite
     * @param GetStockItemDataInterface $getStockItemData
    public function __construct(
        GetProductSalableQty $getProductSalableQty,
        GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite,
        GetStockItemDataInterface $getStockItemData
    ) {
        $this->getProductSalableQty = $getProductSalableQty;
        $this->getStockIdForCurrentWebsite = $getStockIdForCurrentWebsite;
        $this->getStockItemData = $getStockItemData;

    public function getStock($sku)
        $stockId = $this->getStockIdForCurrentWebsite->execute();

        // Actual qty - Reserve Qty - OOS Threshold
        $productQtyInStock = $this->getProductSalableQty->execute($sku, $stockId);
        echo $productQtyInStock . PHP_EOL;

        // Return only qty
        $stockItemData = $this->getStockItemData->execute($sku, $stockId);
        $qty = $stockItemData[GetStockItemDataInterface::QUANTITY];
        echo $qty . PHP_EOL;

You can get salable qty or total Qty using the above code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.