1

Am using Magento 1.8 here i want to send product image in order email. I refer this link Add product image in new order email.

this is the code:

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

default.phtml

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

?>

And here am showing image

<td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
      <img src="<?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl($_product->getThumbnail()); ?>" width="135" height="135" alt="<?php echo $_item->getName() ?>" />
</td>

But i got mail like this

enter image description here

Its not working for simple, configurable and bundle product also

How can i fix this error?

Note: This question already asked but am not get the correct answer.

1 Answer 1

1

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

For information please visit following URLs:-

New order email missing product image {{layout handle="sales_email_order_items" order=$order}}

Add product image in new order email

I hope this is helpful for you.

2
  • Thank you for the reply. I tried your code, I got the same error. And i checked that image url in gmail. This is the url https://ci6.googleusercontent.com/proxy/ng51G6Tb9l9E1eg2PtEvgGZgr0jK9ur_pZ7vrJYk3uUIBqJRvB5AxeL8ZzAGi773v79Tgi1xFhfuf9uWq78zQ0eXYdOhsUFDfVkQp7rSb2ka=s0-d-e1-ft#http://127.0.0.1/ramesh/my_store/media/catalog/product/
    – Madhumitha
    May 17, 2017 at 7:41
  • Try this You can use getSmallImage(), getThumbnail() for different images of the product. Please visit this URL:- magento.stackexchange.com/a/75873/52231 May 18, 2017 at 7:03

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.