Add custom attribute in order email templates - Magento

前端 未结 1 2007
忘掉有多难
忘掉有多难 2020-12-29 14:55

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, for

相关标签:
1条回答
  • 2020-12-29 15:11

    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

    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 !!! :-)

    0 讨论(0)
提交回复
热议问题