Magento – How to reflect type of currency in URL links

currencymagento-1.7

As many of you know when switching currency in MAGENTO store, it does not reflect in URL's.

Let say your BASE store currency is in CANADIAN DOLLARS, when sending links by Email to customers in EUROPE, the page they will open will show CAD (Canadian dollar) prices rather than EURO. They have to manually switch currency in the top right corner of the website.

What to add at the end of all links so the prices are shown in EURO ?
I need an ending like: ?_currency=EURO

www.exmaple.com/sport-equipment/soccerball/?_currency=EURO

Best Answer

There is a way of doing that, but it's a bit ugly.
The url must look like this:

{ROOT}/directory/currency/switch/currency/{CURRENCY_CODE}/uenc/{ENCODED REDIRECT URL}/

So if your url is http://www.exmaple.com/sport-equipment/soccerball/, the url you send in the e-mail for EUR must look like this:

http://www.exmaple.com/currency/switch/currency/EUR/uenc/aHR0cDovL3d3dy5leG1hcGxlLmNvbS9zcG9ydC1lcXVpcG1lbnQvc29jY2VyYmFsbC8,

You can build this url starting from your url like this.

$currency = 'EUR';
$redirect = 'http://www.exmaple.com/sport-equipment/soccerball/';
$mageBaseUrl = `http://www.exmaple.com/`
$emailUrl = $mageBaseUrl.'directory/currency/switch/currency/'.$currency.'/uenc/'.strtr(base64_encode($redirect), '+/=', '-_,');

It's easier if you build the url in a magento environment:

$currency = 'EUR';
$redirect = 'http://www.exmaple.com/sport-equipment/soccerball/';
$emailUrl = Mage::getUrl('directory/currency/switch', array(
    'currency' => $currency,
    Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core')->urlEncode($redirect)
));
Related Topic