1

I was trying to show configurable color swatches on category listing page but unable to get it, I used below code but it just shows the name of color but I want to show swatches same as on product detail page,

Below code shows only color name which I have tried,

<?php if($_product->isConfigurable()): ?>
      <?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() ?>
           <ul>
           <?php foreach($allProducts as $p): ?>
             <?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>
        <?php endforeach ?>
        </ul>
      <?php endif ?>
    <?php endif ?>    
0

Change

<?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>

to

<?php $attributes = $product->getTypeInstance()->getUsedProductAttributes($_product); ?>
| improve this answer | |
  • Already used it in next loop but not working – Avinash Borse Aug 29 '18 at 10:04

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.