Friday, August 5, 2011

Currency drop down selector in header, Magento

Step 1

You will need to create a new directory, named “directory” and create a new file called “currency-top.phtml“:


/app/design/frontend/template/default/YOUR-TEMPLATE-NAME/template/directory/currency-top.phtml and write the following code in it :-


<?php if($this->getCurrencyCount()>1): ?>

<div class="box language-switcher" style="margin-left:15px">

<label for="select-language">Your Currency: </label>

<select name="currency" onchange="changeCurrency(this)">

<?php foreach ($this->getCurrencies() as $_code => $_name): ?>

<option value="<?php echo $_code ?>"<?php if($_code==$this->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?>>

<?php echo $_name ?> - <?php echo $_code ?>

</option>

<?php endforeach; ?>

</select>

</div>

<script type="text/javascript">

//<![CDATA[

function changeCurrency(sObject){

if(sObject.value){

setLocation('<?php echo $this->helper('directory/url')->getSwitchCurrencyUrl() ?>currency/'+sObject.value);

}

}

//]]>

</script>

<?php endif; ?>




Step 2


/app/design/frontend/template/default/YOUR-TEMPLATE-NAME/layout/page.xml


Add currency_top block after store_language block inside header block of page.xml present around line #66 :-


<block type="page/html_header" name="header" as="header">

<block type="page/template_links" name="top.links" as="topLinks"/>

<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>

<block type="directory/currency" name="currency_top" template="directory/currency-top.phtml"/>

<block type="core/text_list" name="top.menu" as="topMenu"/>

</block>




Step 3:


Add getChildHtml(‘currency_top’) below getChildHtml(’store_language’) in


/app/design/frontend/template/default/YOUR-TEMPLATE-NAME/template/page/html/header.phtml like below :-


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

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

No comments:

Post a Comment