I am new to Magento and I am trying to find a way how to include a picture of the product the customer ordered from my website in the order confirmation email?
3 Answers
You have file: app/design/frontend/base/default/template/email/order/items/order/default.phtml
Copy this file to your package/theme and add this piece of code below of foreach:
<?php
$_product = Mage::getModel('catalog/product')
->setStoreId($_item->getOrder()->getStoreId())
->load($_item->getProductId());
?>
Add this code to show image of product:
<img src="<?php echo Mage::getModel('catalog/product_media_config')
->getMediaUrl($_product->getThumbnail()); ?>"
alt="<?php echo $_item->getName() ?>" />
-
Thank you for your reply! Where is app/design.../default.phtml is normally located in Magento admin panel? Thank you!– KateCommented Jul 15, 2015 at 23:01
-
Is a magento filesystem design basis: blog.nodwell.net/wp-content/uploads/2013/07/…– osrecioCommented Jul 15, 2015 at 23:08
Maegento does not save product image on Sales Item model(Mage_Sales_Model_Order_Item)
That why you cannot get image from sales item
.
If you need then with out product Model load
you cannot get it at email
So you need add below code at app/design/frontend/YourPackage/YourTheme/template/email/order/items/order/default.phtml
<?php
$_product = Mage::getModel('catalog/product')
$_product ->setStoreId($_item->getOrder()->getStoreId())
->load($_item->getProductId());
// check product id is exit or not
if($_product->getId()):
<img src="<?php echo Mage::getModel('catalog/product_media_config') ->getMediaUrl($_product->getThumbnail()); ?>"
alt="<?php echo $_pr->getName() ?>" />
endif;
?>
Get Image in sale order email
Please view below code :
- $_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->getFile())->resize(100, 100)->getUrl();
End add : <img src="<?php echo $image_url; ?>" alt="" />
Good look !