4

I want to add product image in new order email template.
How can I do this?
I am using my custom template and I want product image also.
so how can I take image on my custom template
Custom template I have created from,

system->configuration->transnational emails
14
  1. First Step

Edit the file: app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/email/order/items.phtml

After this line:

<th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"> <?php echo $this->__('Sku') ?></th>

Add this:

<th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Image') ?></th>
  1. Second Step

Edit the file: app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/email/order/items/order/default.phtml

Note: If this file doesn't exist in your package then you can find this file from base package (app/design/frontend/base/default/template/email/order/items/order/default.phtml)

After this line:

<td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;"><?php echo $this->escapeHtml($this->getSku($_item)) ?></td>

Add this:

<img src="<?php echo Mage::getModel('catalog/product_media_config')  
                ->getMediaUrl($_product->getThumbnail()); ?>"  width="135" height="135" alt="<?php echo $_item->getName() ?>" />  

EDIT


For configurable product parent image display :

Edit the file app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/email/order/items/order/default.phtml

After this line:

<?php $_order = $this->getItem()->getOrder() ?>

Add this:

<?php 

if ($_item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
    $parentId = Mage::getModel('catalog/product_type_configurable')
                       ->getParentIdsByChild($_item->getProductId());  
    $_product = Mage::getModel('catalog/product')  
                       ->setStoreId($_item->getOrder()->getStoreId())  
                       ->load($parentId);
} else {
    $_product = Mage::getModel('catalog/product')  
                       ->setStoreId($_item->getOrder()->getStoreId())  
                       ->load($_item->getProductId());  
}

?>

Then, if not already done, after this line:

<td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;"><?php echo $this->escapeHtml($this->getSku($_item)) ?></td>

Add this line:

<img src="<?php echo Mage::getModel('catalog/product_media_config')  
                ->getMediaUrl($_product->getThumbnail()); ?>"  width="135" height="135" alt="<?php echo $_item->getName() ?>" />  
  • glad to help you@sipl – Keyur Shah Jul 28 '15 at 10:53
  • Wow, nice, it works very good! I have only a little problem: if a have a configurable product, how can i show only the image of configurable product, without the images of sub-items? Thansk! – Simbus82 Jan 18 '16 at 11:16
  • Check my edit @Simbus82 – Keyur Shah Jan 18 '16 at 12:14
1

(Magento 2 get Product Image By ID in Order)

Please follow code after:

$_item = $block->getItem();

$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_page_image_small')->setImageFile($_product->getImage())->resize(100, 100)->getUrl();

100% success :) ! Please view link ! Hope to help you!

0
$_productThumbnail = '';

if ($_item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && count($_item->getChildrenItems()) > 0) {
    $_productThumbnail = $_item->getChildrenItems()[0]->getProduct()->getThumbnail();
}

if ($_productThumbnail == '' || $_productThumbnail == 'no_selection')
{
    $_productThumbnail = $_item->getProduct()->getThumbnail();
}

And then

<img src="<?php echo Mage::getModel('catalog/product_media_config')  
                ->getMediaUrl($_productThumbnail ); ?>"  width="135" height="135" alt="<?php echo $_item->getName() ?>" />
0

my solution example:

email/order/items/order/default.phtml

after line <?php $_order = $this->getItem()->getOrder() ?> insert:

<?php
if ($_item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
    $_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$_item->getSku());
    $_product_image = (string) Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(30);

} else {
    $_product = $_item->getProduct();
    $_product_image = Mage::getModel('catalog/product_media_config')->getMediaUrl($_product->getThumbnail());
}
?>

and somewhere insert something like this:

<p class="product-name"><img src="<?php echo $_product_image; ?>"  width="35" height="35" alt="<?php echo $_item->getName() ?>" /><?php echo $this->escapeHtml($_item->getName()) ?></p>

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.