Blog Placholder Image Magento 2 Get Child Products of Configurable Product

Magento 2 Get Child Products of Configurable Product

Today we are going to talk about how to get a child product of a configurable product programmatically in Magento 2. This programming tutorial explains in detail, how to get child product id from configurable product. By following this example you can get the child product’s other data like name. So let’s start with our example.

namespace QaisarSatti\Module\Block;

class Product extends \Magento\Framework\View\Element\Template
{

  protected $_product;  


  public function __construct(
     
        \Magento\Catalog\Model\ProductFactory $_productloader

    ) {


        $this->_productloader = $_productloader;
     
    }
    public function getLoadProduct()
    {
        $product_id=7;
       $configProduct=$this->_productloader->create()->load($product_id);
       $_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
foreach ($_children as $child){
    echo "Child Product Ids ".$child->getID()".<br />;
}
    }

}

Search

Recent Blogs

Categories

Archives

Archives

Tags