5

The new order email template is rendering everything except the product image of the order.

This is how the template was trying to call it by default, which doesn't work:

{{layout handle="sales_email_order_items" order=$order}}

This is the error:

enter image description here

Can anyone advise on what might be the problem.

This is the function i worte:

app/design/frontend/base/default/template/email/order/items/order/default.phtml

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());  
}

?>

this is display code:

<img src="<?php echo Mage::getModel('catalog/product_media_config')  
                        ->getMediaUrl($_product->getThumbnail()); ?>"  width="135" height="135" alt="<?php echo $_item->getName() ?>" />  
5
  • 1
    No one know this
    – Ramesh S
    Mar 24, 2017 at 5:40
  • Can you see value for src in your email when you inspect? Mar 24, 2017 at 7:34
  • Oh god thank you for replay @JaiminSutariya. Yeah i see the value of src this is that https://www.domain.in/media/catalog/product/ ( for eg: www.domain.in)
    – Ramesh S
    Mar 24, 2017 at 7:37
  • 1
    Did you try with echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(135)->__toString(); as your image src value? Mar 24, 2017 at 7:40
  • Yeah working but image does not exit
    – Ramesh S
    Mar 24, 2017 at 8:01

3 Answers 3

1

Did you get it working yet? I think the reason for product showing wrong image is this function written in

app/design/frontend/base/default/template/email/order/items/order/default.phtml

The mentioned code, checks for configurable product and then tries to get its parent ids. It should be the other way round. Check this edited code

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

Thanks

3
  • Its working but in bundle product order it's not working. Any way thank you mskhan
    – Ramesh S
    Mar 28, 2017 at 9:57
  • Glad to know that. Cheers!! :)
    – mskhan
    Mar 28, 2017 at 10:51
  • 1
    Any solution for bundle products...?
    – Ramesh S
    Mar 29, 2017 at 4:38
4

Try replacing your code,

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

to

<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(135)->__toString(); ?>"  width="135" height="135" alt="<?php echo $_item->getName() ?>" />
9
  • It's working but showing wrong image like Image does not exit image
    – Ramesh S
    Mar 24, 2017 at 8:00
  • 1
    can you confirm if thumbnail image is added. or you can use small_image instead of thumbnail Mar 24, 2017 at 8:09
  • I checked in admin panel catalog->manage products->productname-> in product information images section selected thumbnail
    – Ramesh S
    Mar 24, 2017 at 8:11
  • you can also try adding image in place of thumbnail as @murtuza suggested. Mar 24, 2017 at 8:18
  • 1
    The reason for not showing image can only be that the product does not have image selected in its detail page. Try refreshing your image cache from admin. Mar 24, 2017 at 8:35
2

For thumbanil it is compulsory to select thumbnail image at back end other wise you get default image

you can fetch main image and resize that image for your requirement

 <?php echo Mage::helper('catalog/image')->init($_product, 'image')->resize($size)->__toString(); // here $size is your image size ?>  

Try below solution may it works

$backendModel = $collection->getResource()->getAttribute('media_gallery')->getBackend();
 $backendModel->afterLoad($_product);

and then try below code

 <?php echo Mage::helper('catalog/image')->init($_product, 'image')->resize($size)->__toString(); // here $size is your image size ?>    
7
  • Thanks @Murtuza Zabuawala image showing but that image not product image see this link image
    – Ramesh S
    Mar 24, 2017 at 8:23
  • @RameshS in your code replace thumnail to image and try and also do reindexing Mar 24, 2017 at 8:27
  • This is the code <img src="<?php echo Mage::helper('catalog/image')->init($_product, 'image')->resize(135)->__toString(); ?>" width="135" height="135" alt="<?php echo $_item->getName() ?>" /> is this right..?
    – Ramesh S
    Mar 24, 2017 at 8:30
  • @RameshS see updated answer Mar 24, 2017 at 8:41
  • Its showing same image now im try to clear image cache in admin. But your ans also right. Any possible for select two ans in magento.stack overflow
    – Ramesh S
    Mar 24, 2017 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.