Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento adding referer param to getLoginPostUrl()

Tags:

php

magento

I'm trying to create a form that integrates the login into the process as seamlessly as possible.

I'm using Mage::helper('customer')->getLoginPostUrl() at the moment for the login form, if there is something better to use I'm all ears, and it works, but it ends up at the user dashboard.

I looked up the function and its looking for if($this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME)){ but I'm not sure how to give it the param in a way that the function will read it.

I noticed if I use Mage::helper('customer')->getLoginUrl() it adds the referer itself, so I traced it and found how it adds the encoded referer to the url and ended up with this

<?php echo Mage::helper('customer')->getLoginPostUrl(); ?>referer/<?php echo Mage::helper('core')->urlEncode($this->getUrl("frontname/controller/function")); ?>

Which gives me a url that looks like this

http://www.mysite.com/customer/account/loginPost/referer/aHR0cDovL3J5YW4uZGV2L3VzL2Zyb250bmFtZS9jb250cm9sbGVyL2Z1bmN0aW9uLw,,/

Which works, but I'm thinking there has to be a better way. Anyone have any idea?

If not... that works for me, in case anyone else is looking for the same thing.

like image 950
Ryan Avatar asked Nov 05 '12 22:11

Ryan


3 Answers

I've done it in this way, hope this helps for somebody as well:

Mage::getUrl('customer/account/login', array('referer' => Mage::helper('core')->urlEncode($this->getUrl("frontname/controller/function"))))
like image 67
Vladislav Mosalski Avatar answered Nov 11 '22 16:11

Vladislav Mosalski


I had the same problem. Your customers are being redirected to the dashboard because of a setting in your configuration. Go to

System > Configuration > Customers > Customer Configuration > Login Options

And turn "Redirect Customer to Account Dashboard after Logging in" to "No". Magento will start to listen to that referrer parameter and put your customers back to the page they were on before they clicked "Login".

I know this is an old thread and it's probably way to late to help, but this question ranks for the problem, maybe it will help someone else.

like image 38
Markie Avatar answered Nov 11 '22 15:11

Markie


I would combine vladislav-mosalsky's answer with the _current snippet from amardeep-aryan so that you only need one copy of the code to use.

Mage::app()->getFrontController()->getResponse()->setRedirect(
    Mage::getUrl('customer/account/login', array('referer' => Mage::helper('core')->urlEncode(
        Mage::getUrl('', array('_current' => true,'_use_rewrite' => true))
    )))
);
like image 22
Tyler V. Avatar answered Nov 11 '22 15:11

Tyler V.