How to get salable qty in magento 2.3.3?
-
06-04-2021 - |
Frage
How to get salable qty of each Product and display in Product view page.
Can someone help me?
Thanks in advance.
Lösung
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku');
$qty = $StockState->execute($_product->getSku());
echo ($qty[0]['qty']);
?>
You can get only the saleable quantity by the following above code.
Andere Tipps
Try the below code to get salable QTY.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\InventorySalesApi\Api\GetProductSalableQtyInterface');
$qty = $StockState->execute($_product->getSku(), 2);
?>
Hope this will help you.
Use the following code :-
namespace Vendor\Module\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 = "testsku"; //pass your product sku
$salable = $this->getSalableQuantityDataBySku->execute($sku);
echo json_encode($salable);
}
}
Output :-
[{"stock_name":"Default Stock","qty":4,"manage_stock":true}]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange