How to get salable qty of each Product and display in Product view page.

Can someone help me?

Thanks in advance.

4 Answers 4

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku');
$qty = $StockState->execute($_product->getSku());
echo ($qty[0]['qty']);

You can get only the saleable quantity by the following above code.

  • How can I check saleable qty of product in current quote?
    – huykon225
    Commented Aug 3, 2021 at 2:56

Try the below code to get salable QTY.

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $StockState = $objectManager->get('\Magento\InventorySalesApi\Api\GetProductSalableQtyInterface');
    $qty = $StockState->execute($_product->getSku(), 2);

Hope this will help you.

  • 2
    I tried this one and got answer. Here you mentioned 2 manually.It is stock_id. How to get stock_id dynamically and update salable qty? Commented Jan 23, 2020 at 7:14

Use the following code :-

namespace Vendor\Module\ModelName;
use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;
class ClassName
    private $getSalableQuantityDataBySku;
    public function __construct(
        GetSalableQuantityDataBySku $getSalableQuantityDataBySku
    ) {
        $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
    public function execute(\Magento\Framework\Event\Observer $observer)
        $sku = "testsku"; //pass your product sku
        $salable = $this->getSalableQuantityDataBySku->execute($sku);
        echo json_encode($salable);

Output :-

[{"stock_name":"Default Stock","qty":4,"manage_stock":true}]

Reference Link

  • It's showing array of stock information.I need to show only salable qty. How to get only salable qty, not stock name,manage stock? @Rk Rathod Commented Jan 23, 2020 at 7:54
  • as per example salable qty is 4 Commented Jan 23, 2020 at 7:55

Loop stock qty or sum the stock you need

  • output the array value in second position
    – Fabio
    Commented Aug 9, 2022 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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