Tag: products

Getting Configurable Product from Simple Product ID in Magento 1.5+

by Dan on Sep.19, 2011, under Magento, PHP

I recently stumbled across a hurdle which stopped some of my code from working. It was code that gets the configurable product associated with a given simple product. Many solutions out there call a “loadParentProductIds()” function within the Mage_Catalog_Model_Product class. However, as of Magento, they deprecated this method, simply by setting the data element (and returning) an empty array. So any calls to this function would return/yield no parents. Hm, how to get the parent product now?

Finally, I managed to find a workable solution. Check this out;

$simpleProductId = 465;
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
$product = Mage::getModel('catalog/product')->load($parentIds[0]);
echo $product->getId(); // ID = 462 (aka, Parent of 465)

There you have it. Short and sweet.

6 Comments :, , more...


A few highly recommended websites...