Hi,
Since I upgraded to 1.9.2.4 a custom variable is not showing in the New Order email anymore. I have spent many hours, searching for an answer and changing code, but now I am running out of ideas.
I overrided the class: Mage_Sales_Model_Order , and placed it in app\code\local\Mage\Sales\Model
Around line 1360 I changed the code to:
$mailer->setTemplateParams(array( 'order' => $this, 'billing' => $this->getBillingAddress(), 'payment_html' => $paymentBlockHtml 'custom_comment' => $firstComment ));
And in the template\email\sales\order_new.html , I placed the code:
{{var custom_comment}}
When placing a new order, the email is sent (that is ok), but the custom variable is not/never showing in the email.
What I already did so far:
- Cleared and refreshed Magento cache after each change.
- Changed core functionality Mage_Sales_Model_Order directly (Its not recommended, but I have no other ideas and it doesn't work anyway)
My questions are:
Do anyone know what I can do to solve this problem?
Is it possible that the custom variable is blocked?
If this is the case, how do I whitelist this variable in System->permissions->variables?
Please help me.
Kind regards,
sealboy
Solved! Go to Solution.
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.
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.
Thanks for your reply.
I missed the step: System > Transactional Emails > New Order Email
And the var is added.
It is working now.
Thanks
Can you please look into this similar post and provide a solution ?