1

I am trying to add product image in the sales order email template with overriding in the path

/app/design/frontend/vendor/Mytheme/Magento_Sales/templates/email/items/order/default.phtml.

Code Written:

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $_product = $objectManager->get('Magento\Catalog\Model\Product')->load($_item->getProductId());
    $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');
    $image_url = $imageHelper->init($_product, 'product_thumbnail_image')->setImageFile($_product->getFile())->resize(100, 100)->getUrl();?>
<img src="<?php echo $image_url;?>"/>

Unfortunately, I am getting this in the mail. originals source is overridden by src which is getting generated. Not able to get an image in the mail.

Inspected element:

<img data-imagetype="External" **src="/actions/ei?u=http%3A%2F%2F...%3A1080%2FQPwebstore%2Fpub%2Fmedia%2Fcatalog%2Fproduct%2Fb%2Fa%2Fballpen_with_stylus1.jpg&amp;d=2019-04-16T13%3A15%3A46.063Z"** 
 **originalsrc="http://......./pub/media/catalog/product/b/a/ballpen_with_stylus1.jpg"** data-connectorsauthtoken="1" data-imageproxyendpoint="/actions/ei" data-imageproxyid="" class="x_product-image-photo" width="200" height="200" alt="Stylus Pen" style="border:0; height:auto; line-height:100%; outline:none; text-decoration:none">

Kindly help me to resolve this issue..

  • <img data-imagetype="External" src="/actions/ei?u=http%3A%2F%2F...%3A1080%2FQPwebstore%2Fpub%2Fmedia%2Fcatalog%2Fproduct%2Fb%2Fa%2Fballpen_with_stylus1.jpg&amp;d=2019-04-16T13%3A15%3A46.063Z" originalsrc="http://......./pub/media/catalog/product/b/a/ballpen_with_stylus1.jpg" data-connectorsauthtoken="1" data-imageproxyendpoint="/actions/ei" data-imageproxyid="" class="x_product-image-photo" width="200" height="200" alt="Stylus Pen" style="border:0; height:auto; line-height:100%; outline:none; text-decoration:none"> ..........this is the element while inspecting – SUBBULAKSHMI G Apr 16 at 13:39
0

copy vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml to yout template folder app/design/frontend/[VENDOR]/[TEMPLATE]/Magento_Sales/templates/email/items/order/default.phtml and adding the image column there...

$_item = $block->getItem();
$_order = $_item->getOrder();
$_store = $_order->getStore();


$_imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Catalog\Helper\Image');
$_baseImageUrl = $_store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'catalog/product';

and right below

<img src="<?= $_imageHelper->init($_item->getProduct(), 'small_image', ['type'=>'small_image'])->keepAspectRatio(true)->resize('65','65')->getUrl();?>" alt="<?= __('Product Image');?>">
  • i have tried .. i am getting same issue – SUBBULAKSHMI G Apr 16 at 13:52
  • any error generate ? – Rk Rathod Apr 16 at 13:53
  • no error........... i am getting below one while inspecting in mail.........<img data-imagetype="External" src="/actions/ei?u=http%3A%2F%2F...%3A1080%2FQPwebstore%2Fpub%2Fmedia%2Fcatalog%2Fproduct%2Fb%2Fa%2Fballpen_with_stylus1.jpg&amp;d=2019-04-16T13%3A15%3A46.063Z" originalsrc="http://......./pub/media/catalog/product/b/a/ballpen_with_stylus1.jpg" data-connectorsauthtoken="1" data-imageproxyendpoint="/actions/ei" data-imageproxyid="" class="x_product-image-photo" width="200" height="200" alt="Stylus Pen" style="border:0; height:auto; line-height:100%; outline:none; text-decoration:none"> – SUBBULAKSHMI G Apr 16 at 14:08

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.