0

I have got currency switch dropdown set up on header.phtml and its working fine and changing the currency correctly but its keep redirecting back to home page every time I switched the currency. How can I prevent it from going back to home page and stay in current page after page reload?

in my browser this url was 302 before I get redirected to home page http://myshop//directory/currency/switch/currency/USD/uenc/aHR0cDovL... 302 moved temporarily

1 Answer 1

2

Basically,magento is change the currency at Mage_Directory_CurrencyController on switchAction() function.

And using _redirectReferer() is redirect to previous page.

May the REFERER url getRefererUrl() is not working thus magento redirect to home page .

And as send a site url has been send as option url for redirection after currency change thus it redirect to home page.

see Mage_Core_Controller_Varien_Action on function.

 protected function _redirectReferer($defaultUrl=null) { $refererUrl = $this->_getRefererUrl(); if (empty($refererUrl)) { $refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl; } $this->getResponse()->setRedirect($refererUrl); return $this; } 

Solution:

you need check previous page url value by adding code:

 $refererUrl = Mage::helper('core')->urlDecodeAndEscape( $this->getRequest()->getParam('uenc')) ); 

at Mage_Directory_CurrencyController. it should be give you previous page url

6
  • Yea I am also digging into the core code and saw this but how to replace with $this->_redirectReferer(Mage::getBaseUrl()); to user current url ? Commented Jun 24, 2015 at 7:10
  • is there a core magento function that get current url? $currentUrl = Mage::helper('core/url')->getCurrentUrl(); i'm not sure but gonna give this a try Commented Jun 24, 2015 at 7:13
  • I am not seeing this code $refererUrl = Mage::helper('core')->urlDecodeAndEscape( $this->getRequest()->getParam('uenc')) ); at Mage_Directory_CurrencyController at app/code/Mage/Directory/controllers/CurrencyController.php Commented Jun 24, 2015 at 7:17
  • just add this code and check your refere url is right or wrong Commented Jun 24, 2015 at 7:46
  • I found the problem its actually magneto base64_decode returning blank Commented Jun 24, 2015 at 7:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.