2

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 get success. Please let me know where am I wrong? or what to do need to access this variable in phtml file?

Thanks in advance!

2
  • What exactly is the "test variable" is it a customer attribute, product attribute, a block of test, etc?
    – kab8609
    Dec 26, 2013 at 15:36
  • it's a merchant emails array Dec 27, 2013 at 4:47

1 Answer 1

9

When passing a variable this way:

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

You make it available in the email/order/items.phtml template only.
You are able to get it there with: $this->getTest() or $this->getData('test').
To pass it further to the email/order/items/order/default.phtml edit the items.phtml file and add this

$item->setTest($this->getTest());

before calling

<?php echo $this->getItemHtml($_item) ?>

To make it shorter, replace:

<?php echo $this->getItemHtml($_item) ?>

with

<?php echo $this->getItemHtml($_item->setTest($this->getTest())) ?>
1
  • You save my time.... Genius :) Apr 17, 2019 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.