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
getItem(); $_order = $_item->getOrder(); $imageSize = (int) $block->getConfig('sales_email/imageconfig/image_resize'); if ($imageSize <= 10) { $imageSize = 135; } $_imagehelper = $this->helper('Magento\Catalog\Helper\Image'); if ($childProd = current($_item->getChildrenItems())) { $productImage = $_imagehelper ->init($childProd->getProduct(), 'category_page_list', ['height' => $imageSize, 'width' => $imageSize]) ->getUrl(); } else { $productImage = $_imagehelper ->init($_item->getProduct(), 'category_page_list', ['height' => $imageSize, 'width' => $imageSize]) ->getUrl(); } // Display the image tag if enabled in the configuration if ($block->getConfig('sales_email/imageconfig/enabled')): ?>
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.
Happy Mailing!
Hello Dhiren,
Having the exact requirment as mentioned in this article but i can not add the code mentioned in default.phtml file.
I am using Magento version 2.3.3 and not having the path mentioned :
app/design/frontend/[theme name]/Magento Sales/templates/email/items/order
Please suggest what to do ?
If you have don’t have the file on this location, then you can create one and copy the file from magento default extension and then add code there.
Hello, I want the same thing but it’s not working. and I have default luma theme, I do not see /design/frontend[THEME NAME] here, only one empty “Magento” directory exists in ‘app/code/design/frontend/[Magento]”. and its empty.
So I am not sure where the luma theme files exist. I added this code in >> vendor/magento/module-sales/*templates*email*item*order/default.phtml” file, but I dont get picture along with the product.