I have added a currency switcher as per the inchoo tutorial

The issue is though when a customer changes the currency, the call is a physical page load and not an Ajax call which in turn means if they use the browser's back button they need to click it twice to actually go back to the last page.

Is there a way to change this or what's the best way to change the currency via Ajax?


The problem is the build in currency switcher, redirects back to the homepage, so you can't use it for an Ajax call. But it's not to hard to create the same switch URL without a redirect.

To make it possible to switch the currency by an ajax call you need to recreate the Mage_Directory_CurrencyCpntroller, only without the redirect. You can do so by creating your module registration in app/etc/modules/Hans_SwitchCurrency.xml:

<?xml version="1.0"?>

Then create your module config app/code/community/Hans/SwitchCurrency/etc/config.xml:

<?xml version="1.0"?>

And the controller in app/code/community/Hans/SwitchCurrency/controllers/SwitchController.php:

class Hans_SwitchCurrency_SwitchController extends Mage_Core_Controller_Front_Action
    public function indexAction()
        if ($curency = (string) $this->getRequest()->getParam('currency')) {

Then you can create your Ajax call to <?php echo $this->getUrl('currencyswitch/switch', array('currency' => $_code)); ?>, to switch the currency without redirecting back to the homepage. Instead you could create a page refresh using javascript or something.

Hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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