Question

I have a requirement in Magento 1.7, My site has multiple currencies, Suppose I checkOut with GBP whereas my default currency is USD. Now, the Order email has the following texts

Grand Total                   £93.66
Grand Total to be Charged    $169.70

Both the values are equal to each other with respect to their conversion value [todays's rate]. But when the Invoice mail is generated, the last line "Grand Total to be Charged" is not appearing. I need that line to appear on all other transaction emails including Invoice emails [ in cases of products being purchased in currency other than default currency ].

How can I achieve that? Any help is highly appreciated.

Was it helpful?

Solution

I found a solution to this problem.

How I found the solution ::

A). The Invoice Email template invoice_new.html has the following line :

{{layout handle="sales_email_order_invoice_items" invoice=$invoice order=$order}}

whereas the Order email template order_new.html has the following line :

{{layout handle="sales_email_order_items" order=$order}}

B). In sales.xml, layout handle 'sales_email_order_invoice_items' has a block template 'email/order/invoice/items.phtml' ... this item.phtml file has the following line ::

echo $this->getChildHtml('invoice_totals');

and sales.xml again says ::

<block type="sales/order_invoice_totals" name="invoice_totals" template="sales/order/totals.phtml">   

C). Again, in sales.xml, layout handle 'sales_email_order_items' has a block template 'email/order/items.phtml' .. this item.phtml file has the following line ::

echo $this->getChildHtml('order_totals');

and sales.xml again says ::

<block type="sales/order_totals" name="order_totals" template="sales/order/totals.phtml">

D). So, both Order and Invoice emails dynamically loads "sales/order/totals.phtml" file. Now in totals.phtml file, we have a line like this ::

foreach ($this->getTotals() as $_code => $_total):

The above function getTotals() loops through the array containing Total Pricing structure including base price, shipping expenses, tax, discounts, Base price in other currencies etc.

E). As the Base Price (with BASE currency as set in Admin Panel) was coming properly in Order email, I checked the class ( from block type='sales/order_totals' ) Mage_Sales_Block_Order_Totals found in Mage/Sales/Block/Order/Totals.php. The getTotals() function is just iterating the property '$this->_totals'. I also checked how this '$this->_totals' array was created through '_initTotals()' method. In this '_initTotals()' method, $this->_totals['base_grandtotal'] has been created which is responsible for printing the Order price in Base Currency and this is what I was looking for. However, this Base price was not coming in Invoice emails. Hence I opened the Class 'Mage_Sales_Block_Order_Invoice_Totals'

F). The class 'Mage_Sales_Block_Order_Invoice_Totals' ( existing in file 'app/code/core/Mage/Sales/Block/Order/Invoice/Totals.php' ) inherits from the class 'Mage_Sales_Block_Order_Totals' and overrides the function _initTotals() which created the pricing array. However in this function, there is a line ::

$this->removeTotal('base_grandtotal');

The above line is removing the Base Price section from the _totals array. Simply commenting the line finally solved my problem.

OTHER TIPS

This should be proper way to get expected behaviour without changing Magento code.

For this create your own extension. Let's call it Easylife_Sales (feel free to change the namespace) with the following file: app/etc/modules/Easylife_Sales.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Sales>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </Easylife_Sales>
    </modules>
</config>

app/code/local/Easylife/Sales/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Sales>
            <version>0.0.1</version>
        </Easylife_Sales>
    </modules>
    <global>
        <blocks>
            <sales>
                <rewrite>
                    <order_totals>Easylife_Sales_Block_Order_Totals</order_totals><!-- this tells Magneto to use your block instead the default one-->
                </rewrite>
            </sales>
        </blocks>
    </global>
</config>

app/code/local/Easylife/Sales/Block/Order/Totals.php

<?php
class Easylife_Sales_Block_Order_Totals extends Mage_Sales_Block_Order_Totals
{
    /**
     * Initialize order totals array
     *
     * @return Mage_Sales_Block_Order_Totals
     */
    protected function _initTotals()
    {
        $source = $this->getSource();

        $this->_totals = array();
        $this->_totals['subtotal'] = new Varien_Object(array(
            'code'  => 'subtotal',
            'value' => $source->getSubtotal(),
            'label' => $this->__('Subtotal')
        ));


        /**
         * Add shipping
         */
        if (!$source->getIsVirtual() && ((float) $source->getShippingAmount() || $source->getShippingDescription()))
        {
            $this->_totals['shipping'] = new Varien_Object(array(
                'code'  => 'shipping',
                'field' => 'shipping_amount',
                'value' => $this->getSource()->getShippingAmount(),
                'label' => $this->__('Shipping & Handling')
           ));
        }

        /**
         * Add discount
         */
        if (((float)$this->getSource()->getDiscountAmount()) != 0) {
            if ($this->getSource()->getDiscountDescription()) {
                $discountLabel = $this->__('Discount (%s)', $source->getDiscountDescription());
            } else {
                $discountLabel = $this->__('Discount');
            }
            $this->_totals['discount'] = new Varien_Object(array(
                'code'  => 'discount',
                'field' => 'discount_amount',
                'value' => $source->getDiscountAmount(),
                'label' => $discountLabel
            ));
        }

        $this->_totals['grand_total'] = new Varien_Object(array(
            'code'  => 'grand_total',
            'field'  => 'grand_total',
            'strong'=> true,
            'value' => $source->getGrandTotal(),
            'label' => $this->__('Grand Total')
        ));

        /**
         * Base grandtotal REMOVED
         */
        return $this;
    }
}
?>

Clear the cache and disable the compilation if it's enabled.

Copied and inspired by proper solution: https://magento.stackexchange.com/a/2925/29024 PHP code based on Magento 1.9.0.2

Goto app/code/core/Mage/Sales/Block/Order/Totals.php

(I would recommend that you override the file)

Find following code

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,
        ));
    }

and Replace it by

//if ($this->getOrder()->isCurrencyDifferent()) {
if(false){
        $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,
        ));
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top