skip to Main Content

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?

2

Answers


  1. Please use this code in phtml file to get salable qty

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $StockState = $objectManager->get('MagentoInventorySalesAdminUiModelGetSalableQuantityDataBySku');
    $qty = $StockState->execute($_product->getSku());
    echo($qty[0]['qty']);
    
    Login or Signup to reply.
  2. Try the below code to get salable QTY.

    <?php 
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $StockState = $objectManager->get('MagentoInventorySalesApiApiGetProductSalableQtyInterface');
        $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 CloudwaysModuleModelName;
    use MagentoInventorySalesAdminUiModelGetSalableQuantityDataBySku;
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search