How to add currency selector in header of Magento

07 / Mar / 2013 by amatya 2 comments

In magento by default currency selector renders in right side bar. To show it in the header is not a hard job. This blog will let you know about moving it to header of magento.

First of all setup your desired currencies for your store from magento admin. Now create a new template file and put it under following directory structure :

app/design/frontend/your_package/your_theme/template/currency/currency.phtml

<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-language">
    <label for="currency-selector"><?php echo $this->__(Currency') ?></label>
    <select onchange="window.location.href=this.value" name="currency-selector" id="currency-selector">
        <?php foreach ($this->getCurrencies() as $code => $name): ?>
        <option value="<?php echo $this->getSwitchCurrencyUrl($code)?>"
            <?php if($code == $this->getCurrentCurrencyCode()): ?>
                selected="selected"
            <?php endif; ?>>
            <?php echo $name ?>
        </option>
        <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

Now create following file so that magento use this file to render currency selector.

app/design/frontend/your_package/your_theme/layout/local.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="header">
            <block type="directory/currency" name="my_currency_selector" template="currency/currency.phtml"/>
        </reference>
    </default>
</layout>

Now open app/design/frontend/your_package/your_theme/page/html/header.phtml and add following line :

<?php echo $this->getChildHtml('my_currency_selector') ?>

That’s it. Hope this will help you.


Regards,
Amatya Trivedi
amatya@intelligrape.com

Tag -

FOUND THIS USEFUL? SHARE IT

comments (2)

Leave a comment -