How do I retrieve the ID of a Grouped Product from which a Simple Product was ordered in Magento?

StackOverflow https://stackoverflow.com/questions/14757977

Domanda

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?

È stato utile?

Soluzione

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'];

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top