magento 2.3 get salable quantity

Salable quantity magento 2.3

Rate this article

Share this article

Read Magento 2 search settings for more information.

In the latest Magento version 2.3, you might have noticed an additional quantity parameter ‘Salable Quantity‘. Take a look at how to get a product’s salable quantity Magento 2.3

Unlike in previous versions of Magento, the quantity of a product does not decrease when an order is placed. Instead, the quantity remains the same but the salable quantity gets reduced. The quantity of the product decrease only after shipping is completed.

magento 2.3 get salable quantity

Add a search bar to Magento

To get salable quantity use the following code –

namespace Webkul\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 = "testsimpleproduct1";
        $salable = $this->getSalableQuantityDataBySku->execute($sku);
        echo json_encode($salable);
    }
}

This will give output as –

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

Here qty is the salable quantity and not the actual quantity of the product. We can get the actual quantity of the product by $product->getQty()

Add a Search Bar to Magento

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
You may also like