I have overridden the AccountController of customer for a functionality which will redirect user to a specific page after checkout login.
For which I had to pass some parameter to the _loginPostRedirect() method as follows..
My override functions..
public function loginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
.......
.......
.......
.......
}
.......
.......
$this->_loginPostRedirect($login); //here I have passed the parameter
}
protected function _loginPostRedirect($login)
{
.....
.....
.....
if(isset($login['isMobCheckout'])){
$this->_redirectUrl($login['isMobCheckout']);
}
else{
$this->_redirectUrl($session->getBeforeAuthUrl(true));
}
}
So when I execute this the following error is coming..
Strict Notice: Declaration of Newcustom_Customer_AccountController::_loginPostRedirect() should be compatible with Mage_Customer_AccountController::_loginPostRedirect()
So I have passed the same variable in the core functions even if there is no use, And then it works fine.
But I did modify the core file which will be a problem while upgrading the system.
Could anyone please suggest whether it will be alright or is there any other methods present for doing the above functionality to avoid modify in core methods ?
2 Answers 2
public $parameters = null; // global declaration
public function loginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
$this->_parameters=$this->getRequest()->getPost('login'); //define
.......
.......
.......
.......
}
.......
.......
$this->_loginPostRedirect($login); //here I have passed the parameter
}
protected function _loginPostRedirect($login)
{
$login = $this->_parameters; // use here as you want
.....
.....
.....
if(isset($login['isMobCheckout'])){
$this->_redirectUrl($login['isMobCheckout']);
}
else{
$this->_redirectUrl($session->getBeforeAuthUrl(true));
}
}
-
It is working fine @Charlie. Thanks. How to acquire these type of tricks for developers ?Kishore Patra– Kishore Patra2016年04月29日 06:45:18 +00:00Commented Apr 29, 2016 at 6:45
-
everyone solve the problem differently so you need to check and look in to other code style. how they write it, what is their strategy to achieve solution...Charlie– Charlie2016年04月29日 08:28:00 +00:00Commented Apr 29, 2016 at 8:28
Hope this will Help You ...
In your app\code\local\Override\Accountcntrlr\controllers\Customer\Accountcntrlr.php
<?php
require_once "Mage/Customer/controllers/AccountController.php";
class Override_Accountcntrlr_Customer_AccountController extends Mage_Customer_AccountController{
public function loginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
}
}
In app\code\local\Override\Accountcntrlr\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Override_Accountcntrlr>
<version>0.1.0</version>
</Override_Accountcntrlr>
</modules>
<frontend>
<routers>
<accountcntrlr>
<use>standard</use>
<args>
<module>Override_Accountcntrlr</module>
<frontName>accountcntrlr</frontName>
</args>
</accountcntrlr>
</routers>
</frontend>
<global>
<rewrite>
<override_accountcntrlr_customer_accountcontroller>
<from><![CDATA[#^/customer/account/#]]></from> <!-- Mage_Customer_AccountController -->
<to>/accountcntrlr/customer_account/</to> <!-- Override_Accountcntrlr_Customer_AccountController -->
</override_accountcntrlr_customer_accountcontroller>
</rewrite>
<helpers>
<accountcntrlr>
<class>Override_Accountcntrlr_Helper</class>
</accountcntrlr>
</helpers>
</global>
<admin>
<routers>
<accountcntrlr>
<use>admin</use>
<args>
<module>Override_Accountcntrlr</module>
<frontName>admin_accountcntrlr</frontName>
</args>
</accountcntrlr>
</routers>
</admin>
</config>
In app\etc\modules\Override_Accountcntrlr.xml
<?xml version="1.0"?>
<config>
<modules>
<Override_Accountcntrlr>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Override_Accountcntrlr>
</modules>
</config>
loginPostAction()function and use them in_loginPostRedirect($login)function without passing as parameters$login = $this->getRequest()->getPost('login');It is only a value of a hidden field which is checked for the redirection. So could you help me how to set them as global variable ?