I want to display Product Salable Quantity, on Category view page.

On \app\design\frontend\Smartwave\porto\Magento_Catalog\templates\product\list.phtml

added the follow code:

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

form this post And it is works fine, but not for all categories pages. If in category view there are "Configurable Products" i get this error:

1 exception(s):
Exception #0 (Exception): Notice: Undefined offset: 0 in /var/www/vhosts/glowfashion.gr/httpdocs/app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/list.phtml on line 239

line 239: echo ($qty[0]['qty']);

i want to display the lower quantity of "Configurable Sub Products". Any idea?

1 Answer 1


You can not directly get configurable product's salable Quantity.

What you can do is either you can fetch any first simple product or you can sumup all the salable qty of the simple products associated with the configurable product.

Here is the sample code for the configurable product :

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
$total_stock = 0;
if($_product->getTypeID() == 'configurable'){
    $productTypeInstance = $_product->getTypeInstance();
    $usedProducts = $productTypeInstance->getUsedProducts($_product);
    foreach ($usedProducts as $simple) {
        $total_stock += $StockState->getStockQty($simple->getId(), $simple->getStore()->getWebsiteId());
echo $total_stock;
  • Thnx it is works! But i want to display and Salable Quantity for products which is NON Configurable Products. So i added an else{ $StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku'); $qty = $StockState->execute($_product->getSku()); echo ($qty[0]['qty']); } Commented May 21 at 9:59
  • Congratulations! Happy to hear it worked. :) Commented May 21 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.