Get Salable Quantity in Magento 2.3
In the latest Magento version 2.3, you might have noticed an additional quantity parameter ‘Salable Quantity’. Today we will see how to get a product’s salable quantity in 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.
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()
{
$sku = "testsimpleproduct1";
$salable = $this->getSalableQuantityDataBySku->execute($sku);
echo json_encode($salable);
}
}
This will give the output as –
[{“stock_name”:”Default Stock”,”qty”:4,”manage_stock”:true}]
Hope this helps. Please visit our Magento 2 affiliate Extension.
Happy coding 🙂
Categories:
Magento2
View Comments (10)
Comment or Ask a Question
Quick Links