How to Get Product Salable Quantity in Magento 2?

| |
2 mins read
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.

User Image
Author By

Vishal Lakhani

Vishal Lakhani, Founder and CTO of Rock Technolabs, brings over a decade of expertise in eCommerce development and Magento solutions. As a Magento Certified Developer, Vishal combines his technical know-how with a commitment to innovation, delivering high-quality results. Beyond his technical competency, Vishal is a passionate blogger who prioritizes quality content over quantity. Apart from blogging and playing with Magento, he enjoys reading, traveling, and learning something new every day.

Let's Discuss

Leave a Reply

Your email address will not be published. Required fields are marked *