Magento 2 – Add Manufacturer Image to Details Page

magento-2.1manufacturerproduct-attribute

In Magento 2.1, I need to add manufacturer's logo in product detail page. Now, I added an attribute manufacturer from the backend.

I did that by going to Stores -> Attribute set then choosing Default. then there was two Unassigned Attributes, Color and Manufacturer. I dragged manufacturer into Product Details under Groups. Now I have a dropdown list at the backend's product catalog page (Product -> catalog -> edit/add the product ).

Now I need to implement when I choose a manufacturer from that dropdown, in that product's, product detail page manufacturer image should be displayed.

How do I accomplish that?

Best Answer

Create a module for this task.

Store all your Manufacturer images at path Company/Module/view/frontend/web/images/ with the exact name of menufacturer.

Then, you need to override template file for the product page and get Manufacturer Label in that template file:

$menufacturer = $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product);

Then, you can insert image like this:

<img src='<?php echo $this->getViewFileUrl('Company_Module::images/' . $menufacturer . '.png'); ?>' alt="<?php echo $menufacturer ?>" width="30" height="25">
Related Topic