Saturday, June 4, 2011

Customize 'New Order' Email template in Magento

6/04/2011

Customizing the 'New Order Confirmation Email' template in Magento may be a havoc for the first time if you do not know the write way. But it is as easy as anything. Recently I needed to customize the item information in the 'New Order Confirmation Email'. I googled a number of links but found nothing useful. Then I decided to find my own way, and after 2 hours of hard work I found a simple way. Here are the steps to customize the email template:



1. In the Magento Admin panel go to 'System > Transactional Emails' and click on 'Add New Template'.
2. In the 'Load default template' container select 'New Order' in the 'Template' dropdown. Alse select our desired 'Locale'.
3. Click on 'Load Template'. It will load the Default email template to edit for you. Now you can edit the 'Template Subject' and 'Template Content' to suit your needs. See the following screenshot:

Here we want to edit the item information in the order email. The email template calls a layout file as:
{{layout handle="sales_email_order_items" order=$order}}
for the item information. So we will replace this line so that we can call our own custom template in place of the default layout file.
Replace
{{layout handle="sales_email_order_items" order=$order}}
with
{{block type='core/template' area='frontend' template='<module_name>/orderemail.phtml' order=$order}}
where template='<module_name>/orderemail.phtml' tells Magento the path of template file to be called. We have also passed order variable in the call as order=$order, so the $order variable is available to us in the template file that holds the current order information.
Save the template.

4. Now create orderemail.phtml in the template directory of your custom module.
Full file path: app\design\frontend\default\default\template\<module_name>\orderemail.phtml
In this template file we have $order available to user. You can access the order id from $order variable as:

$order_id = $this->getData('order')->getRealOrderId();
Now you can access all order information here and write your custom HTML format to be shown in the email. You can change the way the item information is shown or add more item information in the email template.

5. Now in Magento Admin panel go to 'System > Configuration > Sales Emails'. In the 'Order' tab select your newly created template in the 'New Order Confirmation Template' dropdown. Save the options.

And you are ready to send the customized email template!!!

Written by

Arvind is a web developer, programmer and blogger. He has expertise in PHP, Magento, WordPress, jQuery, JavaScript, HTML5 and CSS3. He loves to develop good looking websites with strong backend.

20 comments :

  1. Nice post brother !!!

    Keep up the good work !!!

    ReplyDelete
  2. Nice post!
    However I cannot make it to work.
    Strange thing - the block is loaded into template (I can see it in email when debugger is on).
    But no content is loading from this block.
    Do you know what issue this may be?

    ReplyDelete
    Replies
    1. This is so strange, but suddenly i am having this problem too. i know this is old, but can you tell me how you fixed it?

      Delete
    2. This is so strange, but suddenly i am having this problem too. i know this is old, but can you tell me how you fixed it?

      Delete
    3. @Igor, Blogger
      Your issue seems to be a coding glitch. I dont think anyone can guess it without diving into the code. Otherwise it works absolutely fine.

      Thanks.

      Delete
  3. Is it possible to add custom product attributes to the transactional emails?

    ReplyDelete
  4. It is not necessary to set up a new module. Simply copy

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

    and

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

    to your custom theme folder.

    ReplyDelete
  5. check this, this may work
    http://blog.free-extension.com/2011/04/07/adding-attribute-to-the-new-order-notification-email-in-magento/

    ReplyDelete
  6. You save my lot of time and found great knowledge which is helpful to many projects.
    Thanks for sharing such a great knowledge with us.

    ReplyDelete
  7. everything was ok since the site went live, suddenly there are some order confirmation email are not sending, 4/5 out of 10 order the confirmation email not sending, struggling to solve this issue, can any one help me out please
    Thanks

    ReplyDelete
    Replies
    1. @Fozla Alahi Bhuyain, I dont think anyone can see to this issue without having access to the actual code.

      Delete
  8. Hi,
    How can we send automatically an email to the suppliers whose order has been placed by the customer. For example: suppose i have three suppliers A, B and C.
    A supplier has one product. B has also one product. But C has more than 5 products. Now suppose as a client i give an order for the products from Supplier A (one item) and C (3 items). Now what i want that suppliers will receive mails (Supplier A will receive one mail and Supplier C will receive 3 mails for 3 different products) for theirs products automatically. I will be thankful to you if you can help me out.

    ReplyDelete
  9. ala lakhota upload kar ni

    ReplyDelete
  10. Thank you for your post!

    This one seems much easier: http://shamimcse05.wordpress.com/2011/04/07/adding-attribute-to-the-new-order-notification-email-in-magento/

    ReplyDelete
  11. Nice post, I spent a lot of time looking for where to save a new email template. If you're looking for a way to create a better looking template for new order emails, we built a free template creator specifically for Magento. You can give it a try at http://www.klaviyo.com/magento-email-templates.

    ReplyDelete
  12. Nice post, I spent a lot of time looking for where to save a new email template. If you're looking for a way to create a better looking template for new order emails, we built a free template creator specifically for Magento. You can give it a try at http://www.klaviyo.com/magento-email-templates.

    ReplyDelete
  13. We spent a bunch of time figuring out these instructions, so nice to have them in one place.

    If anyone's looking for an easy/free way to create a better looking new order template, we built a template creator you case use: http://www.klaviyo.com/magento-email-templates.

    ReplyDelete
  14. Very Nice Article

    ReplyDelete

We would love to hear from you...

 

© 2014 Web Speaks . All rights resevered. Designed by Templateism