Editing Magento sales e-mail payment block

14,828

Solution 1

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}}

Solution 2

In /app/code/core/Mage/Sales/Model/Order.php there is a method called "sendNewOrderEmail". This is what you need to affect. You will find code simmilar to the following:

$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$this->getStoreId()))
                ->sendTransactional(
                    $template,
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $this->getStoreId()),
                    $recipient['email'],
                    $recipient['name'],
                    array(
                        'order'         => $this,
                        'billing'       => $this->getBillingAddress(),
                        'payment_html'  => $paymentBlock->toHtml(),  //Just change this line
                    )
                );

You can see that this is where the "payment_html" data gets set. Just swap it out to what you want it to be.

Share:
14,828
djdy
Author by

djdy

Updated on June 09, 2022

Comments

  • djdy
    djdy almost 2 years

    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?