How to check that Displaying configurable product options in category list page?
6 Answers
In order just to display all sale able options
in the category go to .../app/design/frontend/[package]/[theme]/template/catalog/product/list.phtml
and place within foreach ($_productCollection as $_product)
something like this:
<?php if($_product->isConfigurable()): ?>
//get attributes
<?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
<?php if(count($attributes)): ?>
<ul>
<?php foreach($attributes as $att): ?>
<?php $pAtt=$att->getProductAttribute();
//get the child products
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
$frontValues =array() ?>
<li><?php echo $pAtt->getFrontendLabel() ?>
<ul>
<?php foreach($allProducts as $p): ?>
//check stock, status, ...
//do not show unsaleable options
<?php if(!$p->isSaleable()) continue; ?>
<?php $out=$p->getAttributeText($pAtt->getName()); ?>
<?php $frontValues[$out]=$out; ?>
<?php endforeach ?>
<li><?php echo implode('</li><li>', $frontValues) ?></li>
</ul>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?php endif ?>
Perhaps you like to add some css classes to the <ul>
and <li>
tags.
This won't increase the performance of your shop!
inspired by this Post
http://www.magentocommerce.com/boards/viewthread/73926/#t437146
You can use something like if ($_product->getTypeId() == 'configurable')
inside of your products loop.
This can take up considerable server resources as there can be many options for each product. Best way is to use ajax to only load ALL the options when asked for. I found this extension that will load colors first, then when you mouse over it will give you all the product options.
http://www.consofas.com/plugins/options-quickview-for-configurable-products-in-magento/
Try This once
<?php $ptype = $_product->getTypeId();?>
<?php
if($ptype=='configurable'): ?>
<!--get attributes-->
<?php
$attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
<?php
if(count($attributes)): ?>
<?php
foreach($attributes as $att): ?>
<?php
$pAtt=$att->getProductAttribute();
//get the child products
$allProducts = $_product->getTypeInstance(true)->getUsedProducts($_product,null);
$frontValues =array();
foreach($allProducts as $p):
if($p->isSaleable()):
$attributeExist =$_product->getResource()->getAttribute($pAtt->getName());
?>
<input type="hidden" name="super_attribute[<?php echo $pAtt->getAttributeId() ?>]" value="<?php echo $attributeExist->getSource()->getOptionId($p->getAttributeText($pAtt->getName()));?>">
<?php
break;
endif;
endforeach;
endforeach;
endif;
?>
<?php
endif;
?>
Following link might help you.
http://hkpatel201.blogspot.in/2012/09/get-product-custom-option-in-list-page.html
Go through the code
Thanks
-
i am looking for something like
if($_product->isConfigurable) { //Do This }
Commented Apr 1, 2013 at 16:55 -
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Commented May 30, 2013 at 20:28