Magento – How to add suffix to URL link (/?currency=usd)

magento-1.7magento-1.8

When switching currency between CAD and USD dollars. The product url does not change. It stay the same
www.example.com/sport-equipment/soccer-ball/

I need to add the suffix to produt url such as ?currency=usd or ?currency=cad

When switching the currency to CAD (Canadian dollar) the url link should look like this:
www.example.com/sport-equipment/soccer-ball/?currency=cad

When switching the currency to USD (US dollar) the url link should look like this:
www.example.com/sport-equipment/soccer-ball/?currency=usd

Please help out, I've been trying for the past week, and cannot find a solution.

Best Answer

Why are you trying to do this? Magento reads the current currency from a cookie which is set when you use the currency switcher input at the top of the page. Look at the option value for each currency:

http://example.com/directory/currency/switch/currency/CAD/uenc/some_form_key/

See: https://github.com/OpenMage/magento-mirror/blob/5345da52778cc6f5f31938ffd21fccfdd353435c/app/code/core/Mage/Core/Model/Store.php#L851


Seeing your comment, I think there could be a number of approaches here. Ultimately, you will need to call:

Mage::app()->getStore()->setCurrentCurrencyCode($code)

How you go about doing this is up to you. The problem I'm sure you're running into is that changing the visitor's currency requires a page reload to alter the cookie and those feed service crawlers I'm guessing just ignore the redirect.

You may need to create your own controller that will listen for a currency parameter, set the store's currency, and then load/render the layout making it effectively look like your normal product page. You should also be able to refine the request flow based on the feed service crawler's user agent (which I'm guessing would be unique to that service). That way when someone visits your custom controller, you can just redirect them to the default product page.

Alternatively, you could rewrite the product controller to handle this as well, which might be a little cleaner in this case but you may wish to keep this stuff separate from your normal product controller.