How to Get Product Salable Quantity in Magento 2?
Salable quantity in Magento changes when the item is shipped to the customers and the quantity of the product changes. When customers place an order, salable quantity reduces. In this blog, we will discuss how to get product salable quantity in Magento 2.
To get product salable quantity in Magento 2 programmatically, you can use the below methods.
Method to Get Product Salable Quantity in Magento 2 Programmatically
<?php namespace Mageants\Blog\Controller\Index; use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku; class Index extends \Magento\Framework\App\Action\Action { private $getSalableQuantityDataBySku; public function __construct( GetSalableQuantityDataBySku $getSalableQuantityDataBySku, \Magento\Framework\App\Action\Context $context ) { $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku; return parent::__construct($context); } public function execute() { $sku = “24-MB05”; $salable = $this->getSalableQuantityDataBySku->execute($sku); echo json_encode($salable); } } |
We need to use getSalableQuantityDataBySku method to get Product Salable Quantity in Magento 2.
In above example, we get the salable quantity value of product which have “24-MB05” Sku, So we get following output:
[{“stock_name”:”Default Stock”,”qty”:100,”manage_stock”:true}] |
Conclusion:
We hope above blog helps you to clearly understand How to Get Product Salable Quantity in Magento 2. In case of any kind of problem with the above code implementation, you can contact us or let us know in comment section.