1

Let me start with some context. I'm operating in Magento Enterprise Edition 1.8.0.0 and I am relatively new to Magento Development.

I have seen questions similar to this on Stack Overflow, forums, and blogs, but the answer tends to be something like the one I came up with myself:

$parentIds = (Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($_item->getProductId());
$parentId = $parentIds[0];

It's true that this will retrieve a Parent ID, but it will not always retrieve the right one. The "right" Parent ID, in my case, is the one belonging to the Grouped Product from which a Simple Product was placed in the cart and eventually ordered.

The file I'm trying to get this logic into is:

my_template_path/email/order/items/order/default.phtml

The end goal is to retrieve the thumbnail image of the right Grouped Product in an Order Confirmation Transactional Email. Any ideas?

Rune
  • 133
  • 7

1 Answers1

1

The information about the parent product is stored in the property 'product_options' of the order item object. You can retrieve the right parent id for every order element by executing this code:

foreach ($order->getAllItems() as $item) {
    $options = $item->getProductOptions();
    $parentId = $options['super_product_config']['product_id'];

}
Oleg Ishenko
  • 2,243
  • 1
  • 15
  • 16
  • Sorry it took me so long to accept your answer; I didn't get to test it until another project rolled around that could use it. It works perfectly. In any situation where `$item` (or in some templates `$_item`) is an object of class `Mage_Sales_Model_Order_Item` this **will** work. – Rune Apr 02 '13 at 21:46