Latest news

How To Get Child Product From Configurable Product in Magento?

No comments

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 guy 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?

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
Loading...

April LeeHow To Get Child Product From Configurable Product in Magento?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *