1

I want to get Configurable child simple products from order items.How can I get child simple Product from the configurable product?
I want to fetch only simple product object which associated with configurable product in order items

Here is my code.I can not fetch together configurable product Id and its associated child simple product object.

echo "<pre>";
$items = $order->getAllItems();
foreach($items as $item){
print_r($item->getProduct());
}

1 Answer 1

5

Use $order->getAllVisibleItems() instead of $order->getAllItems()

Updated Answer

$order->getAllVisibleItems() will return only configurable product. Then you can get the child items of configurable products using $item->getChildrenItems(). This method (getChildrenItems()) is defined in Mage_Sales_Model_Order_Item. So, the code will be

foreach($order->getAllVisibleItems() as $item) {
$childItems = $item->getChildrenItems();
echo "<pre>";
   foreach($item->getChildrenItems() as $item){
     echo $item->getProduct()->getId(); // child product Id
     print_r($item->getProduct()); // child product Object
   }
 }
4
  • I want to get configurable item id and its associated simple product obj at same time Commented Feb 26, 2018 at 14:41
  • getAllVisibleItems() not return simple product which has a parent item Commented Feb 26, 2018 at 14:43
  • I want to get associated child product with configurable product and $order->getAllVisibleItems() not return which has a parent item. Commented Feb 26, 2018 at 14:45
  • @NirajPatel Answer updated Commented Feb 26, 2018 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.