Web International Awards

payday loan


APR 2011 0

Dealing with Magento’s Transactional Email preview issues

We've recently had to tackle a issue with transactional emails in Magento for a client of ours. Magento has a nice way you can configure transactional emails in admin and preview them before using them in production. However, every once in a while things start to go really wrong and the following error is well known throughout the Magento community:

PHP Fatal error: Call to a member function getAllItems() on a non-object in …template/email/order/items.phtml on line 38

If you look inside the code for items.phtml, on that specific line you'll find a for statement trying to loop through the items in an object that can be nil and it isn't tested for nil. I assume Magento's developers really considered that there can't be a single case when that object can be nil. Unfortunately it can and unfortunately it will throw nasty errors in the view.

Attempt 1: New Order Confirmation Template settings

The error may be triggered because you've missed to assign the (new) transactional email to the order in Magento's Admin section (Admin >> System >> Configuration >> Sales >> Sales Emails >> New Order Confirmation Template). If you get to Sales Emails tab in Magento's admin, you'll find a drop down for New Order Confirmation Template. Select the desired option then go to cache management and clear your cache. After you do these steps the previews should work just fine.

But what do you do if they don't work just fine?

Attempt 2: copy original files from frontend

It may be the case that the files required to process the preview got corrupted or messed up somehow. A fix for this issue would be to back up all the files that you have in your Magento installation {root}/app/design/adminhtml/default/default/template/email/order/ . Once you've backed them up copy the contents of /home/{user_account}/public_html/app/design/frontend/default/default/template/email/order to /home/{user_account}/public_html/app/design/adminhtml/default/default/template/email/order and things should resume their normal behaviour. Perhaps you should once again clear your cache.

Still not working?

Magento requires a lot of resources and some installations may be using Memcached. I even recommend you start using it if you don't. But when you're debugging Memcached may make you really unhappy if you forget about it. You should check if you're using Memcached or not, and if yes, you should log in to your server via ssh, then flush Memcached and voila, the transactional emails preview will work like a glove and the ugly "PHP Fatal error: Call to a member function getAllItems() on a non-object in …template/email/order/items.phtml on line 38 " error be gone.

In order to flush Memcached you should telnet to the service. Usually it's easily done by running telnet localhost 11211 and then flush_all. Once you do this you can quit telnet or just before that check your Memcached status using stats

Published on Friday, April 15th, 2011 at 9:17 am in Magento, tutorials.

About Bogdan Pop

Bogdan Pop is a young Romanian entrepreneur who runs WebRaptor. He is a web developer with awesome design skills, who enjoys writing about everyday's work and usability. He relaxes by taking photos every once in a while and by mixing french electronic music. Connect with him via Twitter.

There are no comments. You can be the first to post one.

Save time next time! You won't have to fill out all these fields again. Register in just a few clicks and then login.

If you do not have a username, you can register in just a few clicks.