How To Get Child Product From Configurable Product In Magento?

how to get child product in configurable product magento

To get the child product from the configurable product in Magento, we can follow this instruction:

In the order, if using this method:

$items = $order->getAllVisibleItems();

foreach ($items as $item) {

   $item->getProduct()->getData();

}

You just can get the parent product.

However, if you want to get the child products or options from the Configurable product, you must use the code below to add this code to anywhere that you want.

public function getItems($order)

{

  if ($order) {

    $items = $order->getAllVisibleItems();

    foreach ($items as $item) {

      if($item->getProduct()->getTypeId() == 'configurable'){

       $childProduct = $this->getChildProduct($item);

       $childProductId = $childProduct->getData();
      }
    }
  }
}

 

public function getChildProduct($orderItem)

{

  $productId = $orderItem->getProductId();

  $product = Mage::getModel('catalog/product')->load($productId);

  $optionData = unserialize($orderItem->getData('product_options'));

  $childProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($optionData['info_buyRequest']['super_attribute'], $product);

  return $childProduct;

}

We have shown you how to get the simple product from the Configurable products in Magento. Hope you guys find this concise tutorial useful.

See More: 

How To Import/Export CMS Pages & Static Blocks In Magento 1

5 Common Magento 2 Issues That Can Ruin Your Store

Top 5 Must-have Magento 2 Extensions in 2017

How Much Does It Cost To Build A Magento Website?

[ratings]

Leave a Reply

Your email address will not be published.