How to get all associated products to a configurable product in Magento

Saturday, August 18, 2012
Configurable product is the product which is created by some Associated product, If you have an configurable product and you want to get list of all associated product and it's attribute then, follow the below code:You must have your configurable product Id, My configurable product Id is 10
 
$proId=10; //Use your Configurable product Id
$_product = new Mage_Catalog_Model_Product();
$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($proId);
foreach($childIds[0] as $key=>$val)
{
   $associatedProduct = Mage::getModel('catalog/product') ->load($val);
   echo $associatedProduct ->getName();
//You can fetch all attribute in each associated product, for ex: size
   $sizeids[] = $associatedProduct ->getSize();
   $sizename[] = $associatedProduct ->getAttributeText('size');
} 

2 comments:

Post a Comment