简体   繁体   中英

Magento - How to insert product image in transactional email

Basically I would like to include the product image to the New Order Email sent when ordering a product.

I started in email/order/items/order/default.phtml with this code

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

How do I use this code to fetch the image?

Mage::helper('catalog/image')->init($_product, 'image')->resize(250)

thanks for helping :)

Since I found the answer early I should post it here to help other s in need.. :)

<?php //added for sending image with order
        $product = Mage::getModel('catalog/product')
        ->setStoreId($_item->getOrder()->getStoreId())
        ->load($_item->getProductId()); 
    ?>  
        <p align="center"><img src="<?php echo Mage::helper('catalog/image')->init($product, 'image')->resize(50); ?>" width="50" height="50" alt="" /></p>

just put this snippet below

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

NOTE: For gmail users, don't forget to enable Display Image.. :)

Hope this helps!

Get Image in sale order email

Please view below code :

  1. $_item = $block->getItem();
  2. $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();
  3. $_product = $objectManager->get('Magento\\Catalog\\Model\\Product')->load($_item->getProductId());
  4. $imageHelper = $objectManager->get('\\Magento\\Catalog\\Helper\\Image');
  5. $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 !

这也有用吗?

$product = $_item->getProduct()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM