2
votes

I've seen a bunch of articles (mostly 3-5 years old) detailing various methods of getting the customer's first name into the order confirmation email but I just get either a blank, or unparsed PHP.

For example this:

<?php echo $this->__('Hello, %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()); ?>

Renders in the email like this:

__('Hello, %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()); ?>

Could somebody point me in the right direction? This is on Community Edition 1.7.

Thanks

1

1 Answers

6
votes

[EDITED] You can't use PHP code in your email-templates directly. If you want to insert dynamic data into your email-templates, you have two possibilities:

a) In every transactional email you can access the methods of the model, which is in charge for the transactional email, it is: for mails dealing with orders, this is the order-Model, for mails dealing with newsletters, this is the newsletter-model and so on. You can access the methods with the syntax:

{{var model.method()}}

So, in your case, to access the customer's first name in an order confirmation email, you need to look for a suiting method in the order Model, which is getCustomerFirstname() . Then you can call it, following the given syntax:

{{var order.getCustomerFirstname()}}

b) You can include dynamic data into your email-template by creating a custom phtml-template and including it into your email-template via the {{block}} directive (as pointed out by benmarks in the comment below)