I wish to add small icon image on the product image in magento 2.

  • From which template the product image is loaded in product view page. Please provide me a solution.
  • You want that image, on Product detail's page only right ? – Aditya Shah May 19 '18 at 12:43
  • if my answer solves your concern then there is green right tick mark , hit that tickmark for right ansewer that will help future readers. – Nikunj Vadariya May 24 '18 at 9:33
  • Yes I want it in Product Details page @Aditya Shah – Jaisa May 25 '18 at 5:08
  • I need the exact template file to add my image icon, If you have an idea Please suggest me – Jaisa May 25 '18 at 5:18
  • Yes, got you !! – Aditya Shah May 25 '18 at 5:20

1) Create media image attribute From admin menu, Stores > Attributes > product.

2) Get this attribute to your file.

$_product  = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);  
$attrImage = $_product->getData('my_logo');   

if(isset($attrImage) && $attrImage != 'no_selection' ){
    $productImageAttr = $product->getCustomAttribute( 'my_logo' );
    $productImage     = $this->helper('Magento\Catalog\Helper\Image')->init($product, 'my_logo')->setImageFile($productImageAttr->getValue());?>
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
<?php }?>
  • In Which template is responsible to add my icon image to display on product image – Jaisa May 25 '18 at 5:14

This will work for you, Just add image tag to display custom attribute in product listing page.

  • From this you can add attribute name you want to create as They have given Diamond icons and then select Catalog Input Type as Media image. Now save the attribute.

Let me know if if you have any query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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