在订单电子邮件模板中添加自定义属性-Magento [英] Add custom attribute in order email templates - Magento

查看:86
本文介绍了在订单电子邮件模板中添加自定义属性-Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个公司名称"属性,该属性被添加到我的客户的帐户信息中,并且是必填字段.

I have created a 'Companyname' attribute which gets added up in my Customer's Account information and is a required field.

它可以很好地完成注册,表单和编辑页面的操作,并且也可以在后端的客户网格中显示.

It gets filled up on registration, form and edit pages fine and gets displayed on Customer's Grid in the back-end too.

但是,我无法在任何订单电子邮件模板中显示公司名称.

However I am not able to display the Company name in any of my order email templates.

我认为这是因为在我的订单表中既没有名为"companyname"的列,也没有任何自定义变量,我可以将其传递给订单/发票/装运模板以在客户"之后的行旁边显示公司名称名称.

I believe this is because there is neither any column called 'companyname' in my order tables nor do I have any custom variable which I can pass to order/invoice/shipment templates to display Company name right next to the line after Customer's name.

任何人都可以指出一个文件吗,我可以在其中创建包含我的自定义"companyname"属性的自定义变量,并将其传递给所有类型的销售电子邮件模板

Can any one point out the file where I can create this custom variable containing my custom 'companyname' attribute and pass it to all types of sales email templates

谢谢

推荐答案

稍作搜索后,我找到了进行更改的正确文件.由于我已经将"companyname"作为我的属性之一,因此我检索了该字段的值并将其作为参数传递给以下函数

After a little bit of searching I found the right file to make the changes. Since I already had 'companyname' as one of my attributes I retrieved the value of this field and passed it as a param in the following function

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

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

public function sendNewOrderEmail()
{
 /*Existing Code*/
 if ($this->getCustomerIsGuest()) {
        $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
        $customerId = Mage::getModel('customer/customer')->load($this->getCustomerId());
        $companyname = $customerId->getCompanyname();
        $customerName = $this->getBillingAddress()->getName();
    } else {
        $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
        $customerId = Mage::getModel('customer/customer')->load($this->getCustomerId());
        $companyname = $customerId->getCompanyname();
        $customerName = $this->getCustomerName();
    }
    /*Existing Code*/
    $mailer->setTemplateParams(array(
      'order'        =>  $this,
      'billing'      =>  $this->getBillingAddress(),
      'payment_html' => $paymentBlockHtml,
      'companyname'  => $companyname
   ));
   /*Rest of the code remains the same*/
 }

进行此更改后.我编辑了交易电子邮件"以包含此参数.由于我想在收货地址中显示,因此将变量放在此行之前

After making this change. I edited my Transactional Email to include this param. Since I wanted to display inside Shipping Address, I placed my variable just before this line in

   System > Transactional Emails > New Order Email 

     {{ var companyname }}
     {{var order.getShippingAddress.format('html')}}

如果您的公司名称被保存为客户信息的一部分,那么该名称将立即显示在您的订单电子邮件中送货地址"信息中.

If your companyname is getting saved as a part of Customer Information then this would get displayed in your Order Email in 'Shipping Address' Information right at the Start.

您可以对发票和托运电子邮件执行相同的操作.

You can do the same for Invoice and Shipment Emails.

希望这对某人有帮助!!! :-)

Hope this helps someone !!! :-)

这篇关于在订单电子邮件模板中添加自定义属性-Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆