問題描述
我創建了一個公司名稱"屬性,該屬性會添加到我的客戶帳戶信息中,并且是必填字段.
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!