Add custom attribute to create email templates - Magento

I created the "Companyname" attribute, which is added to my customer account and is required.

It is filled during registration, forms and edits the pages in order and is displayed in the client grid in the background.

However, I cannot display the Company name in any of my order email templates.

I believe this is because there is not a single column called “companyname” in my order tables and I don’t have any custom variable that I can pass to order / invoice / shipment templates to display the company name directly next to the line after the customer name.

Is it possible to specify a file in which I can create this custom variable containing my custom attribute "companyname" and pass it to all types of sales email templates.

thanks

+7
source share
1 answer

After a little search, I found the correct file to make the changes. Since I already had "companyname" as one of my attributes, I got the value of this field and passed it as a parameter in the following function

Application / 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 enable this option. Since I wanted to display the delivery address, I placed my variable immediately before this line in

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

If your company name is saved as part of customer information, it will be displayed in your order email in the "Delivery address" field right at the start.

You can do the same for invoices and shipments.

Hope this helps someone !!! :-)

+17
source

All Articles