1

Can someone tell me in a multi-currency store, lets say on CMS page I want to write "Today's Deal XYZ product in USD 100. Now I want this "USD 100" to change based on store currency selected. How can i achieve this on a CMS page? Is it also possible to do this on static block?

Thanks in advance for your help!

3 Answers 3

2

You can include in your cms page a block rendered by a template:

{{block type="core/template" template="path/to/file.phtml"}}

And in the file path/to/file.phtml you can add what ever you want. Here is an example:

<?php if (Mage::app()->getStore()->getCurrentCurrency()->getCode() == 'EUR') : ?>
    <?php echo $this->__('Prices from 100 E')?>
<?php else : ?>
    <?php echo $this->__('Prices from 100 $')?>
<?php endif; ?>
0

I needed to recalculate shipping costs on a CMS page based on the chosen currency. And while Mariu's solution works, I prefer to keep my content in the CMS, instead of an external template. So I wrapped the currency strings and symbols in tags and wrote a jQuery function, that replaces these strings on page load:

This is the HTML Code in my CMS page:

<span class="currency-symbol">$ </span><span class="currency-calculate">15.00</span></td>

And this is the jQuery Function, which I added in app/design/frontend/default/{mytemplate}/template/cms/content_heading.phtml (so it would only get loaded in CMS pages), but if it should always get loaded, you could add it to: /app/design/frontend/default/{mytemplate}/template/page/html/head.phtml

<? //define PHP variables
$currency_rate = Mage::app()->getStore()->getCurrentCurrencyRate();
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$currency_symbol_mage = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();

//replace currency symbol, if there is a currency symbol - otherwise use the currency code:
if( $currency_symbol_mage == "") {
$currency_symbol = $currency_code." ";
} else {
$currency_symbol = $currency_symbol_mage;
}
?>
<script>
jQuery(document).ready(function($) {
  //replace currency symbols
  jQuery('.currency-symbol').text('<?=$currency_symbol;?>');

  //recalculate + replace price in each .currency-calculate occurrence
  jQuery('.currency-calculate').each(function() {
    original_price = parseFloat(jQuery(this).text());
    currency_rate = parseFloat(<?=$currency_rate;?>);
    new_price = (original_price * <?=$currency_rate;?>).toFixed(2);
    jQuery(this).text(new_price);
    //somehow my function got triggered twice, so removing the class is a fix to make sure this doesn't happen:
    jQuery(this).removeClass('currency-calculate');
    });
});

0

the trick works great at CMS page level but if I try to place the code in the HEAD (I need it in every page) it doesn't work.

The function is working but it doesn't change the text in the tag.

<script type="text/javascript">
jQuery(document).ready(function($) {
  //replace currency symbols
  jQuery('.currency-symbol').text('AU$');

  //recalculate + replace price in each .currency-calculate occurrence
  jQuery('.currency-calculate').each(function() {
    original_price = parseFloat(jQuery(this).text());
    currency_rate = parseFloat(1.708100000000);
    new_price = (original_price * 1.708100000000).toFixed(2);
    jQuery(this).text(new_price);
    //somehow my function got triggered twice, so removing the class is a fix to make sure this doesn't happen:
    jQuery(this).removeClass('currency-calculate');
    });
});

</script>

and then in the html stays at it is...

Any suggestion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.