Magento, Magento 2

How to Get Salable Quantity in Magento 2.3.x

How to Get Salable Quantity in Magento 2.3.x

In this tutorial, Today I will explain to how to get salable quantity in Magento 2.3.x version. After Magento 2.3.x version, you might notice that Magento display 2 different qty. one is quantity and second is salable quantity.

The Quantity of product will not decrease when you just place order. It will decrease salable quantity when you place order. Quantity value will be decrease after shipped order.

So, Let’s check the below way

You may also like this :

First of all, Let’s assume that you have created simple module. Now you can add this below code in your block file or any other file :

<?php
/**
 * Created By : Rohan Hapani
 */
namespace RH\Helloworld\Block;

use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;

class Helloworld extends \Magento\Framework\View\Element\Template
{
    protected $salableQty;
    
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        GetSalableQuantityDataBySku $salableQty,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }
    public function getSalableQty($productSku)
    {
        return $this->salableQty->execute($sku);
    }
}

Now, you can get value by call getSalabelQty() function in your module file. You need to pass parameter of product sku in the function. You can call function by this below line.

$block->getSalabelQty(’24-MB01′);

Here, 24-MB01 is product sku. You will get array of salable qty details.

Products-Inventory-Catalog-Magento-Admin

That’s it !!!

I hope this blog is easy to understand how to get salable quantity in Magento 2.3.x version. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with a proper solution.

Stay Safe and Stay Connected !!

Tagged , ,