4

How to check that Displaying configurable product options in category list page?

| improve this question | | | | |
6

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

| improve this answer | | | | |
  • May I Get Same Code For Magento 2 ? – SURENDER SINGH Mar 30 '18 at 22:19
3

You can use something like if ($_product->getTypeId() == 'configurable') inside of your products loop.

| improve this answer | | | | |
0

try this one. Display Available Configurable Product Options on Product Listing page in Magento

| improve this answer | | | | |
0

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/

| improve this answer | | | | |
0

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;
                                                ?>
| improve this answer | | | | |
-4

Following link might help you.

http://hkpatel201.blogspot.in/2012/09/get-product-custom-option-in-list-page.html

Go through the code

Thanks

| improve this answer | | | | |
  • i am looking for something like if($_product->isConfigurable) { //Do This } – Alizain Prasla Apr 1 '13 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. – Fabian Blechschmidt May 30 '13 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.