Tag Archives: php

Getting Configurable Product from Simple Product ID in Magento 1.5+

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.

Adding new attribute to Customer Account in Magento

I recently discovered that this is a right pig to get going. There’s plenty of “solutions” on the interwebs. Many seemingly either don’t work, don’t work as expected, or are complete hacks which makes your extension not modular (i.e; by executing the “addAttribute” function within a template, then removing it once it’s done).

Here’s how I did it. Continue reading “Adding new attribute to Customer Account in Magento” »