Hi i am trying to show the color on product listing page which is configure in the color attribute as visual swatch.

Please find the screenshot below.

enter image description here

  • Does other option are display or not ? May 2, 2017 at 5:01

1 Answer 1

<?php/***********Display Color Attribute************/?>
$om = \Magento\Framework\App\ObjectManager::getInstance();
$attribute = $om->get(\Magento\Catalog\Api\ProductAttributeRepositoryInterface::class)->get('color');
foreach ($attribute->getOptions() as $option) {
    $name = $option->getLabel();
    $optId = $option->getValue();
    $curnt_cat_url = $category->getUrl();
    $colorId = '?color='.$optId;

    $swatchCollection = $om->create('Magento\Swatches\Model\ResourceModel\Swatch\Collection');
    $ThumbImage =  $swatchHelper->getSwatchAttributeImage('swatch_thumb', $item->getValue());
    //$SwatchImage = $swatchHelper->getSwatchAttributeImage('swatch_image', $item->getValue());
    <?php if ($ThumbImage) { ?>
        <div class="color_bg">
            <li class="color_img_bg"> 
                <a href="<?php echo $curnt_cat_url.$colorId ?>"><img src="<?php echo $ThumbImage; ?>"></a>
    <?php } ?>
<?php } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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