1

I have next string, where I get manufacturer attribute:

$brand = $currentProduct->getResource()->getAttribute('manufacturer');

I need to get attribute swatch image. How can I get it? enter image description here

On product filters I got it:

                        <img class="object-fit-contain w-100 h-100"  src="<?=
                    $objectManager->get('Magento\Store\Model\StoreManagerInterface')
                            ->getStore()
                            ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'attribute/swatch/'.
                    $swatchData['swatches'][$option]['value']?>" alt="<?= /* @escapeNotVerified */ $label['label'] ?>">

1 Answer 1

1

Grab all swatches from attributes

$brand_code="manufacturer";
$brandValue = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId())->getData($brand_code);
$swatchHelper=$objectManager->get("Magento\Swatches\Helper\Data");
$swatchData = $swatchHelper->getSwatchesByOptionsId([$brandValue]);

Displaying image:

<img class="object-fit-contain w-100 h-100"  src="<?=
$objectManager->get('Magento\Store\Model\StoreManagerInterface')
    ->getStore()
    ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).
    'attribute/swatch'.$swatchData[$brandValue]['value']?>" alt="brand"/>

Your Answer

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

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