【问题标题】:Add custom attribute in order email templates - Magento在订单电子邮件模板中添加自定义属性 - Magento
【发布时间】:2012-07-08 18:12:31
【问题描述】:

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

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

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

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

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

谢谢

【问题讨论】:

    标签: php magento


    【解决方案1】:

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

    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*/
     }
    

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

       System > Transactional Emails > New Order Email 
    
         {{ var companyname }}
         {{var order.getShippingAddress.format('html')}}
    

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

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

    希望这可以帮助某人! :-)

    【讨论】:

    • 在任何情况下,您都不应该编辑核心文件! …如果您没有看到任何其他更改核心代码的机会,请复制该文件并将其放入 app/code/local/Mage/Sales/Model/Order.php
    猜你喜欢
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    相关资源
    最近更新 更多