Categories
CMS Magento Mastering Development

Get quantity of simple products in configurable products on list.phtml

I’m trying to get the qty of simple products in configurable products in the list page and it works with this code inside the product collection foreach: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get(‘\Magento\CatalogInventory\Api\StockStateInterface’); foreach ($_productCollection as $_product): $configProduct = $objectManager->create(‘Magento\Catalog\Model\Product’)->load($_product->getId()); $_childrens = $configProduct->getTypeInstance()->getUsedProducts($configProduct); foreach ($_childrens as $child) { if ($StockState->getStockQty($child->getId(), $child->getStore()->getWebsiteId()) == 0) { echo […]