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

时间:2012-07-09 10:44:22

标签: php magento

我创建了一个“公司名称”属性,该属性会在我的客户帐户信息中添加,并且是必填字段。

它可以很好地填写注册,表格和编辑页面,并在后端的客户网格上显示。

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

我认为这是因为我的订单表中既没有任何名为'companyname'的列,也没有任何自定义变量,我可以将其传递到订单/发票/发货模板,以便在客户的产品线旁边显示公司名称名。

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

由于

1 个答案:

答案 0 :(得分:19)

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

应用程序/代码/核心/法师/销售/型号/ 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*/
 }

进行此更改后。我编辑了我的交易电子邮件以包含此参数。由于我想在Shipping Address中显示,我在

中将此变量放在此行之前
   System > Transactional Emails > New Order Email 

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

如果您的公司名称已作为客户信息的一部分保存,那么这将在开始时的“送货地址”信息中显示在您的订单电子邮件中。

您可以对发票和发货电子邮件执行相同的操作。

希望这有助于某人! : - )