November 21, 2014

Get a Configurable Products Associated or Related Simple Product

Output the configurable related products.

/* Get all products */

$collection  = Mage::getModel ('catalog/product')
                 ->getCollection(); 

foreach($collection as $product) {
   
   /* If product is not configurable move to next item in loop */

   if($product->getTypeId() != "configurable"):
 continue;
   endif;

   /* Assign configurable related products in collection  */

   $conf = Mage::getModel('catalog/product_type_configurable')
        ->setProduct($product);


   $simpleCollection = $conf->getUsedProductCollection()
    ->addAttributeToSelect('*')    
    ->addFilterByRequiredOptions();

   /* Get all configurable related product ids */

   $simpleIds = $simpleCollection->getAllIds();

   /* Loop all related products and output the product name */

   foreach($simpleCollection as $simpleProduct){
      echo $simpleProduct->getName(). "<br/>";
   }
}

No comments:

Post a Comment