I've accomplished this without creating a module. Hope this may help somebody
- I created a custom product attribute. which allows the user to choose a manufacturer from the dropdown list.
- I get image from app->design>[my vendor]->[my theme]->web->images->products, and image name will be equal to name selected from above dropdown.
- Added layout in XML where I need this image should be.
- used phtml file to locate images and display.
From admin menu, Stores->Attributes->product
Create a new attribute.
Default Label(your name),
Catalog Input Type for Store Owner(dropdown),
Values Required(No). under
Manage Options (Values of Your Attribute) you can add your options.
You can choose any location as you need.
This could be different for your needs,
<referenceContainer name="product.details.section" >
<container name="brand.logo" htmlTag="div" htmlClass="right-brand" before="-">
<block class="Magento\Catalog\Block\Product\View" name="customBrandLogo" template="product/view/custombrandlogo.phtml"/>
in my case, phtml file is custombrandlogo.phtml located at
I get manufacturer name from backend menu,
$_product = $this->getProduct();
$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();
//php close tag will be at the end
I convert the name into lowercase and replace underscores with spaces.
$manufacturerName=str_replace(' ', '_',$manufacturerName);
I get image path
//php tag is closed?>
_Finally display an image with
<img class="img-responsive" src="<?php echo $imgPath ?>.png" alt="<?php echo $manufacturerName; ?>" /></a>
I hardcoded image extension as .png