Handling Currency Conversions in Magento Invoice Emails
In Magento 1.7, handling multiple currencies can lead to some interesting scenarios, especially when it comes to transactional emails like invoices. If you’re facing issues with the “Grand Total to be Charged” line not appearing in your invoice emails for orders placed in non-default currencies, I’ll guide you through a solution.
Understanding the Issue
The problem arises from how Magento handles email templates. The default template for invoices doesn’t include the “Grand Total to be Charged” line that you see in the order emails. This line is added by the observer that triggers when an order is placed, but this observer isn’t triggered for invoice emails.
Solution: Override the Email Template
To resolve this issue, we’ll need to override the default invoice email template and add the necessary line manually. Here’s a step-by-step guide:
-
Create a new file: In your theme directory (usually located at
app/design/frontend/{package}/{theme}/template/email/invoice.phtml), create a copy of the defaultinvoice.phtmlfile and name it something likeinvoice_custom.phtml. -
Add the missing line: Open the newly created file (
invoice_custom.phtml) and locate the following lines, specifically where the grand total is printed:
<?php echo $this->getValue($_order, 'grand_total'); ?>
- Include the conversion: You need to convert the default currency (USD) into the order’s currency before printing the “Grand Total to be Charged” line. Add these lines right after the grand total:
$rate = Mage::getModel('directory/currency')->load($_order->getOrderCurrencyCode())->getRate($_order->getBaseCurrencyCode(), $_order->getStoreId());
$grandTotalInOrderCurrency = $_order->getGrandTotal() * $rate;
- Print the converted total: Now, print the converted value as a new line:
<p><strong>Grand Total to be Charged:</strong> <?php echo Mage::helper('core')->currency($grandTotalInOrderCurrency, true, false); ?></p>
- Update the email template layout: Finally, you need to tell Magento to use your custom template instead of the default one. Open
app/design/frontend/{package}/{theme}/layout/sales_email_order_invoice.xmland add this line inside the `
<reference name="email_template">
<action method="setTemplate" ifconfig="sales_email/order/invoice/enabled">custom.phtml</action>
</reference>
Remember to replace {package} and {theme} with your actual theme package and theme.
Conclusion
This approach ensures that the “Grand Total to be Charged” line appears in all invoice emails, regardless of the currency used for the order. It’s important to note that this is a customization to your theme, so it won’t apply if you switch themes or update Magento.
For more advanced currency management and conversion strategies, consider exploring the capabilities of Magento’s built-in currency functionality or third-party extensions available on marketplaces like Laravel Company.