Home > other >  Magento2.4: How to get Salable quantity in list.phtml file?
Magento2.4: How to get Salable quantity in list.phtml file?

Time:05-18

How can I get salable quantity on list.phtml or category page file, I want to show labels on products with 0 salable quantity. Are there any other approaches without using object manager?

CodePudding user response:

Please use this code in phtml file to get salable qty

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku');
$qty = $StockState->execute($_product->getSku());
echo($qty[0]['qty']);

CodePudding user response:

Try the below code to get salable QTY.

get('\Magento\InventorySalesApi\Api\GetProductSalableQtyInterface'); $qty = $StockState->execute($_product->getSku(), 2); ?>

Either Object Manager is not a good approach, but you need to inject in your custom module such as:

namespace Cloudways\Module\ModelName; use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;

Refer Link: https://magento.stackexchange.com/questions/301956/how-to-get-salable-qty-in-magento-2-3-3/302187#302187

  • Related