top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to get simple products of a configurable product?

+3 votes
411 views
How to get simple products of a configurable product?
posted Aug 3, 2015 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

We recently helped a client with their Magento website. They were wanting to show a grid while on a configurable products page of all the associated simple products. This is an easy way to quickly show the customer what products are available along with their price.

The first step is to determine if the product is a configurable type, otherwise we don’t want to show the grid. We’ll assume you’re using the default template/catalog/product/view.phtml file and that you’ve already got your product object ($_product). Below is the code to check if the current product is configurable.

if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
        echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
endif;
answer Sep 8, 2015 by Rahul Singh
...