app\locale\en_US\template\email\sales\order_new.html
is the file in question.
How would one go about editing {{var payment_html}} without affecting other sections of the site?
It seems like the section comes from: app\design\frontend\base\default\template\payment\info\default.phtml
Am I correct about this? But that file is used in other places on the site. Is that correct too?
I want to create a separate file, say default_email.phtml
, style it separately, and have order_new.phtml include the new file instead.
I assume that I need to include my default_email.phtml
file in layout\***.xml
. Where would I do this?
In order to manage the transactional emails in Magento 2 go to Admin Panel > Marketing > Communications > Email Templates. Then, choose an email template you want to edit or you can add a new one by pressing the Add New Template button.
Containers represent the placeholders within that web page structure (2). And blocks represent the UI controls or components within the container placeholders (3).
Enabling the “Asynchronous email notifications” setting moves processes that handle checkout and order processing email notifications to the background. For my personal experience, it is also recommended to configure emails sending to be asynchronous to avoid having unsent emails.
The first thing I did was a search in the source code of Magento. Assuming the {{var payment_html}}
is processed somewhere I searched on payment_html
.
Several results are matching the search;
Mage_Sales_Model_Order
Mage_Sales_Model_Order_Creditmemo
Mage_Sales_Model_Order_Invoice
Mage_Sales_Model_Order_Shipment
So the information for that payment block has to be in there. I took Mage_Sales_Model_Order
and checked the variable $paymentBlockHtml
. This is pointed to further logic to fill the payment block by payment information. It's creating a block and it looks like this is not easy to extend/change/modify on the first look.
Yes, we can apply a template to the specific (payment) block type since there’s a block created, but we can’t easily check which block we want to load. Also the template is overruled in the construct of Mage_Payment_Block_Info
Let’s check the other way.
Let’s do something cool, why we don’t add a block to the email which contains the correct information but more important where it’s possible to make a switch to the correct case. Since template parser is used for parsing the variables and layout handles we could add the following on instead of the {{var payment_html}}
block and retrieving that information in the block itself.
{{block type='core/template' template='email/templatename.phtml'}}
The above code is parsing the email/templatename.phtml into the email, which means that you could do anything in that template to show the correct data. Before we can retrieve the payment data in this template we have to add the order argument with the order data. That’s quite simple;
{{block type='core/template' order=$order template='email/templatename.phtml'}}
In the template we can do $this->getOrder()->getPayment()
to retrieve the payment information, or $this->getOrder->getPayment()->toHtml()
or process the data in another way.
Bonus; Another solution is working with layout handles and set the correct template and type in the layout.xml, below an example for the order items in the same email. It’s working the same as the block, but only with some settings in the layout xml.
{{layout handle="sales_email_order_items" order=$order}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With