The Salable Quantity first appears in Magento 2.3 release together with the Multi-Source Inventory system. It allows you to manage all your warehouses in one place and avoid dead stocks and out-of-stock situations.
You can see the additional column at the product grid – salable quantity.
The product grid salable quantity.
Salable Quantity is the sum of available resources, grouped in stocks.
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.
Get Product Salable Quantity Programmatically through two methods.
Method 1: Using getSalableQuantityDataBySku method.
Method 2: Using The Object Manager
<?php use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku; private $getSalableQuantityDataBySku; public function __construct(GetSalableQuantityDataBySku $getSalableQuantityDataBySku) { $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku; } public function getProductSalableQty($sku) { $salable = $this->getSalableQuantityDataBySku->execute($sku); echo json_encode($salable); }
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-MB04′);
Here, 24-MB04 is product sku. You will get array of salable qty details.
This will give output:-
[dt_code][{"stock_name":"Default Stock","qty":100,"manage_stock":true}][/dt_code]
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku'); $qty = $StockState->execute($_product->getSku()); echo($qty[0]['qty']); ?>
If you have any queries regarding this post, use the comment section below!
Happy Coding!
Thank you for reading.
Click one of our contacts below to chat on WhatsApp