在订单电子邮件模板中添加自定义属性 - Magento

Add custom attribute in order email templates - Magento(在订单电子邮件模板中添加自定义属性 - Magento)
本文介绍了在订单电子邮件模板中添加自定义属性 - 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.

我相信这是因为我的订单表中既没有任何名为公司名称"的列,也没有任何自定义变量可以传递给订单/发票/发货模板以在客户的行旁边显示公司名称名字.

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.

谁能指出我可以在其中创建包含自定义公司名称"属性的自定义变量并将其传递给所有类型的销售电子邮件模板的文件

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

谢谢

推荐答案

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)