3

I'd like to show the product thumbnail in the new orders emails. I tried this code:

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

It doesn't work. Any helps?

2

3 Answers 3

3
+25

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 ?>    
2

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() ?>" />

You can use thumbnail or image or small_image.
Refresh your Image Cache.

1

Well, I think you should detail a little bit more your question, e.g. I don't know where did you place the code you mention. Anyway, have you tried to do this:

In the file

app/design/frontend/your-package/your-theme/email/order/items/order/default.phtml

which should be based on

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

you can place this code after <?php $_order = $this->getItem()->getorder(); ?>

<?php $_product = Mage::getModel('catalog/product')
            ->setStoreId($_item->getOrder()->getStoreId())
            ->load($_item->getProductId());?>

and then, wherever you want to place your product image you should place

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

Hope this helps you!

1

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.