0

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.

2 Answers 2

1

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.

10
  • The reason why I am doing is: I would like to send products feeds but the TheFeed.com and Google Shopping website accepts USD currency. My website base currency is CAD (cad dollar). When I switch to USD currency, it does not reflect in the link URL that the prices are in USD. If I send these urls to thefeed.com the website will upload default prices which are in CAD rather than USD. So I want to send links with suffixes www.example.com/sport-equipment/soccer-ball/?currency=usd. This way it will for sure upload US prices to the feeds.
    – philtak
    Jul 22, 2014 at 21:32
  • Could you please help me out, which line to edit so all product links will have suffix "?currency=usd" at the end when I switch to US prices.
    – philtak
    Jul 22, 2014 at 21:41
  • 1
    Well if your base currency is CAD with single store, technically the result is correct. You should create a separate website with website pricing for USD and use that as the basis of the feeds.
    – user2935
    Jul 22, 2014 at 21:44
  • Do you think its possible to edit the code, so the Url links have this code "?currency=usd" when switched USD ? Instead of creating a separate website ? To make it simple, all i need is some kind of ending at the end of the url when I switch to USD currency. This way I know for sure the page will show US prices.
    – philtak
    Jul 22, 2014 at 21:48
  • Setting a different website would probably be the smartest way to go.
    – pspahn
    Jul 22, 2014 at 21:51
1

I've had the same problem and I've solved it like this:

The controller_action_layout_load_before event, which is fired on every page load is observed. The observer method checks if the currency parameter is present in the current URL.

If it is, it first checks if the currency code from the URL parameter is an allowed currency with the Mage_Core_Model_Store::getAvailableCurrencyCodes method. If the currency is allowed, it switches the current currency for the store by calling the Mage_Core_Model_Store::setCurrentCurrencyCode method.

I've packed it up into an extension on Github: https://github.com/mobweb/MobWeb_SwitchCurrencyByURL.

1
  • You're welcome. :) Feel free to "Accept" my answer if you feel that it solved your problem.
    – Louis B.
    Jan 14, 2015 at 16:34

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.