Question

I am stuck in my custom code.

I want to pass a custom variable from email template to pthml file.

Edit file

app/code/local/Mage/Sales/Model/Order.php

in this function :

public function sendNewOrderEmail()
  {

--- default code start ----
$mailer->setTemplateParams(array(
                'order'        => $this,
                'test'        => 'XXXXX',
                'billing'      => $this->getBillingAddress(),
                'payment_html' => $paymentBlockHtml
            )
        );
--- default code end ----
}

and then I put this code in New Order email template:

{{layout handle="sales_email_order_items" order=$order  test=$test}}

template file located here :

app/locale/en_US/template/email/sales/order_new.html

and I am trying to get test variable Here:

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

like this: $test = $this->getItem()->getTest()

but not get success. Please let me know where am I wrong? or what to do need to access this variable in phtml file?

Was it helpful?

Solution

Your problem here is that the 'test' value goes to the main block Mage_Sales_Block_Order_Email_Items that uses "email/order/items.phtml" tempalte.

In there you can find the data using:

<?php $test = $this->getTest(); // or $this->getData('test') ?>

You can then add this data into a registry.

But a better way is to send set this info onto the order items before the email. So, in email function before $mailer->setTemplateParams(); add a code like:

//$this = current order if you are in Mage_Sales_Model_Order
foreach ($this->getAllVisibleItems() as $item) {
    $item->setData('test', 'test_value_10');
}

OTHER TIPS

To get variable in your email template

{{var test}}

Take a look @ Defining Transactional Variables

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top