How to Get Product Salable Quantity in Magento 2

The release of Magento 2.3.3 introduced the concept of salable quantity.

If you have downloaded the Magento 2.3.3 version, you might have seen the salable quantity and quantity in the product grid.

Salable Quantity is the sum of available resources, grouped in stocks. Salable quantity gets changed when the order is placed or the physical quantity in the warehouse changes.

Now, the merchants can link multiple inventory sources to one or multiple websites and manage their inventory in more than one location to accurately reflect their physical inventories without any 3rd party extensions!

While working on inventory management, a need may arrive to apply validation or conditions based on salable quantity.

For instance, the admin may want to hide the SKU and stock status if the salable quantity is zero and if it is greater than zero, show the SKU and stock status in Magento 2 store.

In the above scenario, we have to pass the condition on a salable quantity. To do so, we need to get product salable quantity in Magento 2.

The product grid displays the salable quantity in Magento 2 store:

How to get Salable Quantity

Use the below method and get the salable quantity programmatically in Magento 2.

Method to Get Product Salable Quantity in Magento 2

use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku; 
private $getSalableQuantityDataBySku;

public function __construct(GetSalableQuantityDataBySku $getSalableQuantityDataBySku) 
{
    $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
}

public function getProductSalableQty()
{
    $sku = "simple_blue";
    $salable = $this->getSalableQuantityDataBySku->execute($sku);
    echo json_encode($salable);
}

Get salable quantity using ObjectManager

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

That’s all!

Feel free to share the solution with Magento Community via social media.

Thank You.

Sanjay Jethva

Article by

Sanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for...