【问题标题】:Can't pass variable in block directive from transactional email template无法在交易电子邮件模板的块指令中传递变量
【发布时间】:2014-03-29 03:35:03
【问题描述】:

我已加载新订单交易电子邮件以插入自定义块。我将它插入到订单项目表布局句柄调用下,并尝试将其传递给$order 变量。

{{layout handle="sales_email_order_items" order=$order}}
...
{{block type="mymodule/sales_order_email_description" order=$order}}

在我写的 Mymodule_Block_Sales_Order_Email_Description 类中:

protected function _construct() {        
    $this->setTemplate('email/order/description.phtml');
}

最后在 description.phtml 中我尝试访问订单:

$order = $this->getOrder();
...
$order->getId()

此时,异常上升: Fatal error: Call to a member function getId() on a non-object ... ...

我遵循了几个教程,例如 magento email templates,但我仍然遇到这个致命错误。

有什么想法吗?

【问题讨论】:

    标签: magento email block transactional-email


    【解决方案1】:

    我们来看看;

    您可以使用模板定义块,不再需要构造。 {{block type="mymodule/sales_order_email_description" template="email/order/description.phtml" order=$order}}

    确实,您可以使用$this->getOrder() 获取参数值。但是$order->getId() 可能不起作用,$order->getEntityId()。 或许你可以试试 var_dump 看看有没有订单数据。

    【讨论】:

      【解决方案2】:

      在你的 .phtml 文件中试试这个:

      $order = $this->getData('order');
      

      如此处所述:http://www.webspeaks.in/2011/06/customize-new-order-email-template-in-magento.html

      【讨论】:

        猜你喜欢
        • 2019-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-06
        • 2015-12-11
        • 2017-05-13
        • 2013-02-13
        相关资源
        最近更新 更多