How to Get Grouped Product by Associated Product

grouped-productsproduct

I need to detect if product is associated product of grouped product and if it is get this grouped product. Can anyone help me with it?

Best Answer

Let's say you have the product in question $product.
Try this:

$groupedParentsIds = Mage::getResourceSingleton('catalog/product_link')
                   ->getParentIdsByChild($product->getId(), Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED);

Now that you have the parent ids you can easily get the product instances using

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

or

$parents = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('entity_id', array('in'=>$groupedParentsIds))
Related Topic