Welcome TO magento1 and magento2 store market
Getting in touch with clients using Email is an inexpensive and widely used form of highly effective business communication compared to others communication channels. Out of the box, Magento comes with built-in functionality to notify customers of each and every order status like order, invoice, shipment and credit memo. Generally, this Email is made up of various details like customer information, ordered products, subtotal and purchase amount, but it doesn’t contain product images that’s why it is difficult to identify the product from the product list. One of our clients suggested us to add functionality of including product thumbnail image to Email, so when there is a bulk order or thousands of products in an Email, it becomes easier for their customers to identify the products they are looking for.
After spending some time to develop such functionality, finally, we came out with a tiny piece of code. Here I am sharing the easiest way to add product images in all transactional Emails sent to customers in Magento 2.
Just paste the following code to default.phtml file available on below path.
app/design/frontend/[theme name]/Magento Sales/templates/email/items/order
$_item = $block->getItem();
$_order = $_item->getOrder();
$imageSize = (int)$block->getConfig('sales_email/imageconfig/image_resize');
$imageSize = 135;
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
if($childProd = current($_item->getChildrenItems()))
$productImage = $_imagehelper->init($childProd->getProduct(), 'category_page_list', array('height' => $imageSize , 'width'=> $imageSize))->getUrl();
$productImage = $_imagehelper->init($_item->getProduct(), 'category_page_list', array('height' => $imageSize , 'width'=> $imageSize))->getUrl();
And add the image tag like below under the hood of product name.
<img src="<?=$productImage?>" title="<?= $block->escapeHtml($_item->getName()) ?>" alt="<?= $block->escapeHtml($_item->getName()) ?>" />
Once you have implemented above code successfully, it will automatically identify and send product image to each & every order transactional mail that are done via Magento 2 environment. Now just clear the cache and you are ready to go.
Let the stars below to shine and if you face any issue while implementing code, I will be glad to help you.