How to add missing totals?

For example I will use rewards points extension. There is possibility to use points as money. This extension are adding two new lines in order, invoice and credit memo totals block.

1. The first step is to copy layout xml file to our template directory:

From: /app/design/frontend/default/default/layout/mt/email.xml.
To: /app/design/frontend/YOUR/THEME/layout/mt/email.xml.

2. The second step is to find totals block in extension layout file. Your file could be different, I am using reward point extension just for example. Reward points layout's file is located here:

/app/design/frontend/base/default/layout/rewardpoints.xml

In your layout file should be totals' block code, similar like this:

<sales_email_order_items>
    <reference name="order_totals">
        <block type="rewardpoints/totals_order_point" name="rewardpoints.total.point" />
        <block type="rewardpoints/totals_order_label" name="rewardpoints.total.label" />
    </reference>
</sales_email_order_items>

We need to add these blocks to mtemail extension totals block.

<block type="rewardpoints/totals_order_point" name="rewardpoints.total.point" />
<block type="rewardpoints/totals_order_label" name="rewardpoints.total.label" />

3. Open the file

/app/design/frontend/YOUR/THEME/layout/mt/email.xml

and insert these lines

<block type="rewardpoints/totals_order_point" name="rewardpoints.total.point" />
<block type="rewardpoints/totals_order_label" name="rewardpoints.total.label" />

to this block

<block type="sales/order_creditmemo_totals" name="creditmemo_totals" template="sales/order/totals.phtml">
    <action method="setLabelProperties"><value>colspan="3" align="right" style="padding:3px 9px"</value></action>
    <action method="setValueProperties"><value>align="right" style="padding:3px 9px"</value></action>
    <block type="tax/sales_order_tax" name="tax" template="totals/tax.phtml">
        <action method="setArea"><value>frontend</value></action>
    </block>
</block>

like this

<block type="sales/order_creditmemo_totals" name="creditmemo_totals" template="sales/order/totals.phtml">
    <action method="setLabelProperties"><value>colspan="3" align="right" style="padding:3px 9px"</value></action>
    <action method="setValueProperties"><value>align="right" style="padding:3px 9px"</value></action>
    <block type="tax/sales_order_tax" name="tax" template="totals/tax.phtml">
        <action method="setArea"><value>frontend</value></action>
    </block>

    <block type="rewardpoints/totals_order_point" name="rewardpoints.total.point" />
    <block type="rewardpoints/totals_order_label" name="rewardpoints.total.label" />    
</block>

4. You have to repeat step 3 but add the lines to this file:

/app/design/adminhtml/default/default/layout/mt/email.xml

5. You have to repeat 2,3,4 steps with invoice and creditmemo totals. The example is only with order totals but the process is the same.

How to remove "Grand Total to be Charged" from totals block?

This line is coming from magento. You have to create the local copy of core file and remove it.

1. Make a copy of file

From: app/code/core/Mage/Sales/Block/Order/Totals.php
To: app/code/local/Mage/Sales/Block/Order/Totals.php

Remove this part of code

/** * Base grandtotal */
 if ($this->getOrder()->isCurrencyDifferent()) {
     $this->_totals['base_grandtotal'] = new Varien_Object(array(
         'code' => 'base_grandtotal',
         'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
         'label' => $this->__('Grand Total to be Charged'),
         'is_formated' => true,
     ));
 }


How to add custom block?

In this article we will add new, two columns, text block. 


1. Create a thumbnail of the block.

You can download it here


This file should be placed to this directory:
skin/adminhtml/default/default/mt/email/theme/default/block/images/grid2.png

2. Create the block template (.phtml) file

Please create new file called grid2.phtml here:
app/design/frontend/base/default/template/mt/email/theme/default/block/grid2.phtml

The content of the file grid2.phtml you can download here, and copy it to the file.


3. Layout updates

The next thing what you need to do is to update the layout files. Just copy and paste this code. Important parts are in bold.
<mt_email_block_grid2>
        <block type="mtemail/email_block" name="block" template="block.phtml" >
                <block type="mtemail/email_block_template" name="grid2" template="block/grid2.phtml"/>
        </block>
</mt_email_block_grid2>
in these two files files:
app/design/frontend/base/default/layout/mt/email.xml
and 
app/design/adminhtml/default/default/layout/mt/email.xml

after this line:

<layout version="0.1.0">


4. Add this block to the email template

All mt emails templates are under this directory:

app/locale/en_US/template/email/mt/email/default

If you want to add the block to each template you have to add the code, which are bellow, to each template file.
In this example I will show how to add it to the custom.html template. The process is the same with other files.

The code of the block:
"layout handle=\"mt_email_block_grid2\" theme=\"default\" template_id=$this.id block_id=0 block_name=\"mt_email_block_grid2\" ":"mt_email_block_grid2",
"mt/email/theme/default/block/images/grid2.png":"mt_email_block_grid2_image",
You have to add this code after this line:
"mt/email/theme/default/block/images/text2.png":"mt_email_block_text2_image",

That's all! Now you can do some tests.