Jun 2 2011

Configurable product options in Category list page in magento

Often we may need to show product’s option in category list page, for example a product may contain a option ‘size’ where the values are small, medium and large and price may different for different options. We can display these options in category list page like product view page. This can be done as below:

[php]
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product):
$product = Mage::getModel(‘catalog/product’)->setStoreId(Mage::app()->getStore()->getId());
$xml = "";
$hasAtts = 0;
$pass = 0;
$productType = $product->getTypeId();
if($productType == "configurable")
{
$attValConfig = $product->getTypeInstance(true)->setStoreFilter(Mage::app()->getStore(), $product)->getConfigurableAttributesAsArray($product);
if(sizeof($attValConfig)) {
$hasAtts++;
foreach($attValConfig as $attValConfigSingle)
{
echo "<select class=’cust_select’ name=’super_attribute[".$attValConfigSingle['attribute_id']."]’>";
foreach($attValConfigSingle['values'] as $attValConfigSingleVal) {
echo "<option value=’".$attValConfigSingleVal['value_index']."’>".$attValConfigSingleVal['label'].’ +’.Mage::helper(‘core’)->currency($attValConfigSingleVal['pricing_value'])."</option>";
}
echo "</select>";
}
}
}
endforeach;
[/php]

These code snippet shows the product’s options with prices.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>