Tutorialsplane

Magento 2 Get simple Products From Configurable Product


Magento 2 Get simple Products From Configurable ProductIt is little bit different to get the simple products from configurable in Magento 2.x. You can get the child products of parrent configurable products using object manager or factory method in Magento 2. Here in this article we are going to explain how you can get simple products of any configurable ie. child products of configurable product.


Magento 2 Get simple Products From Configurable Product | Get Child Products | Collection | Query Example

You can get the child products of any configurable products simply as below-

Magento 2 Get simple Products From Configurable Product | Example:

$productId = 199; 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);

 
$configMgr = $objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable'); 
$childProducts = $configMgr->getUsedProducts($_product,null);   
                    
foreach($childProducts as $childProduct) {
    echo "Product ID: ".$childProduct->getId();
    echo "<br/>Product Name: ".$childProduct->getName();
     echo "<br/>Product Price: ".$childProduct->getPrice();
}

The above example will give you all the child products of configurable products.