Product Thumbnails in
Magento Order Emails

Category: Magento
Product Thumbnails in Magento Order Emails
Product Thumbnails in Magento Order Emails

To add product thumbnails to your order emails, edit following files:

Magento_Sales/templates/email/items/order/default.phtml
Magento_Sales/templates/email/items/invoice/default.phtml
Magento_Sales/templates/email/items/shipment/default.phtml

Add the following snippet of code before the php closing tag:

/**
 * Add product thumbnails on Magento sales emails by ThemesEmail
 * More tips: https://themes.email/magento.html
 */

$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', array('height' => $imageSize , 'width'=> $imageSize))->getUrl();
} else {
    $productImage = $_imagehelper->init($_item->getProduct(), 'category_page_list', array('height' => $imageSize , 'width'=> $imageSize))->getUrl();
}

To get the product thumbnail, use the following snippet of code and insert it where you want the thumbnail to be displayed.

<img src="<?=$productImage?>" title="<?= $block->escapeHtml($_item->getName()) ?>" alt="<?= $block->escapeHtml($_item->getName()) ?>" style="vertical-align:top;" />

Tutorials

Purchase Email Templates

Each purchase of MET comes with 20 different styles —
and a lifetime of free fresh designs & bug-fix updates.

One purchase for all your future projects.