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

zaw
  • 101
  • 3

1 Answers1

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

Amit Bera
  • 77,456
  • 20
  • 123
  • 237
  • 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 ? – zaw Jun 24 '15 at 07: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 – zaw Jun 24 '15 at 07: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 – zaw Jun 24 '15 at 07:17
  • just add this code and check your refere url is right or wrong – Amit Bera Jun 24 '15 at 07:46
  • I found the problem its actually magneto base64_decode returning blank – zaw Jun 24 '15 at 07:58
  • in /app/code/Mage/Core/Helper/Abstract.php url encode function is working fine but url decode function seems not returning anything – zaw Jun 24 '15 at 08:01