I've accomplished this without creating a module. Hope this may helps somebody
- I created custom product attribute. which allows user to choose manufacturer from 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 image and display.
From admin menu, Stores->Attributes->product
Create 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 name into lowercase and replaces underscores with spaces.
$manufacturerName=str_replace(' ', '_',$manufacturerName);
I get image path
//php tag is closed?>
_Finally display image with
<img class="img-responsive" src="<?php echo $imgPath ?>.png" alt="<?php echo $manufacturerName; ?>" /></a>
I hardcoded image extension as .png