AccountController override not working on new Action and doing 302 redirection
You get redirected because you call parent::preDispatch()
in your code.
This calls the initial method and it does not pass the validation because you action is not in the list of allowed actions
$openActions = array(
'create',
'login',
'logoutsuccess',
'forgotpassword',
'forgotpasswordpost',
'resetpassword',
'resetpasswordpost',
'confirm',
'confirmation'
);
But why do you need to rewrite the default account controller? Can't you just have your own controller that does not depend on the functionality of the default one? You controller should only contain ajaxloginPostAction()
that does what you need. I assume it should be something like the loginPostAction
does but returns the response as json.
It should work in theory.
Reset Header
I got this the solution by changing header response content type.
- First clear current header by
$this->getResponse()->clearHeaders()
- Then set header response with
content type
->application/json
So change doing from :
$this->getResponse()->setHeader('Content-type', 'application/json');
to
$this->getResponse()->clearHeaders()->setHeader('Content-type','application/json',true);
And give 302 redirection with required result json data.
Follow:
Alan Storm answer: https://stackoverflow.com/a/4442879/2940291
& @philwinkle https://magento.stackexchange.com/a/16238
Got i got the idea from their
Still Show 302 redirection:
After add this it show the 302 redirection but it given json data as i want.
Still 302 header redirection with return proper.
Solution:
Now it remember that i have set indexAction as temp action
for ajaxloginPostAction()
. which may be create issue.
$TempAction= $this->getRequest()->setActionName('index');
And it is right.I have change it loginAction
which is open action
in
Mage_Customer_AccountController and my Override controller Bluehorse_Ajaxlogin_AccountController
Now change to
$TempAction= $this->getRequest()->setActionName('index');
to
$TempAction= $this->getRequest()->setActionName('login');
Now No more 302 redirection.