Friday, April 30, 2010

Add new variable to order update e-mail

possible solution:

You need to override the Order model (app/code/core/Mage/Sales/Model/Order.php) and for the sendOrderUpdateEmail() method
you need to change this section
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store' => $this->getStoreId()))
->sendTransactional(
$template,
Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $this->getStoreId()),
$recipient['email'],
$recipient['name'],
array(
'order'     => $this,
'billing'   => $this->getBillingAddress(),
'comment'   => $comment
)
);
to this:
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store' => $this->getStoreId()))
->sendTransactional(
$template,
Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $this->getStoreId()),
$recipient['email'],
$recipient['name'],
array(
'order'     => $this,
'billing'   => $this->getBillingAddress(),
'comment'   => $comment,
'your_var_name'=>'SOMETHNG'
)
);

In the e-mail template you can show the new var like this

{{var your_var_name}}

4 comments:

  1. I'm sorry about that. It worked for me this way

    ReplyDelete
  2. Hey, I'm a bit confused with your explanation. Seems we're adding a function parameters, and add this variable in the email template but never pass this value to the function?

    I've added a combox box, and 2 textbox to my order page. I want to display the text from the combobox and the text from my textboxes inside my email template.

    I'm using Magento 1.4.1.0. Hoping you can explain this to me, seems there's a missing part. :P

    ReplyDelete
  3. Actually no other param is added. It's just an other value (actually a pair key=> value) to an array.

    This array contains all the vars passed to the email template.

    ReplyDelete