Magento - Email Template Script

One of the most 'curious' tasks in getting a magento eCommerce shop ready to go live is the task of getting all of the email templates altered so that they contain the correct information for your new shop. There's millions of these templates with rather annoying literal strings in 'em like 'Demo Store' etc. For some strange reason the default templates do not pull things like the store name etc. from the (available) backend variables.

We have found that the best way to get these templates changed is not to edit them by hand but to use a script to automatically change the text. We use a shell script based on the one detailed here:

http://www.magentocommerce.com/boards/viewthread/6177/P15/#t69549

See post #26 from a very kind charlesrg1

The strange thing is that it seems that over the course of some minor magento releases some of the text in the default templates changed thus breaking part of this script and others like it, for example 'Magento Demo Store' got changed to 'Demo Store'. I am not going to hazard a guess as to why this text was changed (and hence the scripts broken) instead I will include the script that we used sucessfully with magento version 1.3.2.2 in the hope that it might help someone:

#!/bin/sh
phone="025 46791"
office_hours=""
email="info@{{var order.getStoreGroupName()}}"
locale="en_US"
tpath="app/locale/$locale/template/email"
fops="-type f -exec sed -r -i"
#
find $tpath/sales $fops 's/alt="Magento"/alt="{{var order.getStoreGroupName()}}"/g' {} \;
find $tpath/sales $fops 's/Magento Demo Store/{{var order.getStoreGroupName()}} /g' {} \;
find $tpath/sales $fops 's/Demo Store/{{var order.getStoreGroupName()}} /g' {} \;
find $tpath/sales $fops "s/mailto:magento@varien.com/$email/g" {} \;
find $tpath/sales $fops "s/dummyemail@magentocommerce.com/$email/g" {} \;
find $tpath $fops 's/alt="Magento"/alt="{{var customer.store.name}}"/g' {} \;
find $tpath $fops 's/Magento Demo Store/{{var customer.store.name}} /g' {} \;
find $tpath $fops 's/Demo Store/{{var customer.store.name}} /g' {} \;
find $tpath $fops "s/mailto:magento@varien.com/$email/g" {} \;
find $tpath $fops "s/dummyemail@magentocommerce.com/$email/g" {} \;
find $tpath $fops "s/\(0?800\) ?DEMO-(STORE)|(NUMBER)/$phone/g" {} \;
find $tpath $fops "s/\(555\) 555-0123/$phone/g" {} \;
find $tpath $fops "s/ ?Monday - Friday, 9am - 5pm PST/$office_hours/g" {} \;
find $tpath $fops "s/ ?Monday - Friday, 8am - 5pm PST/$office_hours/g" {} \;
find $tpath $fops 's/logo_email.gif/logo.gif/g' {} \;

There are variables at the top through which you can specify your store's phone number, office hours and target locale. Also, remember to set the store in the Magento Admin as the templates will now use it.

Remember to back up your templates before throwing the script at them and also that your updated templates may be overwritten if you upgrade your magento installation - so keep a backup of your altered email templates and upload them again after an upgrade (if required).

Let us know if it works ok for you or if you find any problems with it, with the feedback I will try to keep the script current & correct.

magento_logo.gif
Mcdaddy (not verified)
Mcdaddy's picture
Clean and neat. This script

Clean and neat. This script is truly useful for every commerce site.

Stranger
Stranger's picture
Question from Newbie

Hi,

I'm not a programmer so hope you can answer my very basic question.

I want to change all emails using this script. How do I use it? Do I create a file with the above codes? And then put the file in the folder :

/public_html/capsuco.com/app/locale/en_US/template/email

??

If yes. What is this file type and how can I create it?

Thanks,
Alvin

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Pride on FacebookPride on TwitterPride on TwitterPride on Twitter

Join Our Newsletter

* indicates required

Irish Internet Association

finalist.png
phone-number.png