I am using Magento 2.2.2
I have created one attribute "Manufacturer". Input type of this attribute is visual swatch. I have added values with swatch images in this attribute.
I have selected different values of this attribute in different products. Now I am trying to display this images in listing page. See below code:
<?php $_productCollection = $block->getLoadedProductCollection(); ?>
<?php foreach ($_productCollection as $_product): ?>
<?php $m = $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product);
$swatchCollection = $objectManager->create('Magento\Swatches\Model\ResourceModel\Swatch\Collection');
$swatchHelper= $objectManager->get("Magento\Swatches\Helper\Media");
$item = $swatchCollection->getFirstItem();
$SwatchImage = $swatchHelper->getSwatchAttributeImage('swatch_image', $_product->getValue());
$thumbImage = $swatchHelper->getSwatchAttributeImage('swatch_thumb', $_product->getValue());
?>
<?php /*?><div class="brand"> <img src="<?php echo $this->getViewFileUrl('images/product_brand_logo.jpg'); ?>" alt="" /> </div><?php */?>
<div class="brand"> <img src="<?php echo $thumbImage; ?>" alt="" /></div>
<?php endforeach; ?>
I have added this code in list.phtml
file but I am not getting swatch image for corresponding product in listing page. So how can I solve this issue?