How To Get Salable Quantity in Magento 2.3

March 4, 2020 0 Comments

get salable quantity use the following code :

namespace Yuvraj\Raulji\ModelName;
use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;
class ClassName
{
    private $getSalableQuantityDataBySku;
    public function __construct(
        GetSalableQuantityDataBySku $getSalableQuantityDataBySku
    ) {
        $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
    }
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $sku = "YUVI123";
        $salable = $this->getSalableQuantityDataBySku->execute($sku);
        echo json_encode($salable);
    }
}

output as

[{"stock_name":"Default Stock","qty":4,"manage_stock":true}]

We can get the actual quantity of the product by $product->getQty();

Leave A Comment

To Top