Advertisements
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 1.4.2.0, 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')
->getParentIdsByChild($simpleProductId);
$product = Mage::getModel('catalog/product')->load($parentIds[0]);
echo $product->getId(); // ID = 462 (aka, Parent of 465)
There you have it. Short and sweet.
Thanks a lot your code helped me 🙂
What is the file you changed? I’m trying to get this to work again after upgrading.
This isn’t a change to Magento’s core. It’s a solution for when you’re writing your own custom modules. It would go in place of wherever you called the previous Mage_Catalog_Model_Product::loadParentProductIds() method, to use this code instead to get the parent product ID of a simple product that you currently have loaded.
thanx a lot dear….i tried another but that was not worked for me….this one works for me….
Hello
Where do i put that code ?
Tomas,
Wherever you need to. This is just an instructional post, for anyone writing their own extensions and need to find out/retrieve the parent configurable product model given a simple product model/id.