When a user logged in,automatically is redirected to the Dashboard page, but i want to stay on the same page from where he logged in successfully.
For this a created 2 observers but none of them working. I tried to print_r something at the begining at each function, but without success
My config xml looks like this:
<global>
<helpers>
<in2itive_customerredirect>
<class>In2itive_CustomerRedirect_Helper</class>
</in2itive_customerredirect>
</helpers>
<models>
<in2itive_customerredirect>
<class>In2itive_CustomerRedirect_Model</class>
</in2itive_customerredirect>
</models>
</global>
<frontend>
<events>
<customer_login>
<observers>
<in2itive_customerredirect_customer_login>
<class>In2itive_CustomerRedirect_Model_Observers_Customer_Redirect</class>
<method>customerLoginRedirect</method>
</in2itive_customerredirect_customer_login>
</observers>
</customer_login>
<controller_action_predispatch>
<observers>
<in2itive_customerredirect_controller_action_predispatch>
<class>In2itive_CustomerRedirect_Model_Observers_Customer_Lastpage</class>
<method>getLastVisitedPage</method>
</in2itive_customerredirect_action_predispatch>
</observers>
</controller_action_predispatch>
</events>
</frontend>
and my observers are located in app\code\local\In2itive\CustomerRedirect\Model\Observers\Customer\Lastpage.php and it looks like this :
/**
* @param $observer
*
* @return $this
*/
public function getLastVisitedPage($observer)
{ echo 1; exit();
$this->_beforeLogin($observer);
return $this;
}
/**
* Get the lastest url visited by a user, in a session, if it is not logged in
* @param Varien_Event_Observer $observer
* @return void
*/
public function _beforeLogin(Varien_Event_Observer $observer)
{ print_R(1); die();
$url = Mage::app()->getRequest()->getServer('HTTP_REFERER');
if ((strpos($url, Mage::app()->getStore()->getBaseUrl()) !== 0)
&& (strpos($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) !== 0)
) {
$url = Mage::app()->getStore()->getBaseUrl();
}
$session = Mage::getSingleton("core/session", array("name" => "frontend"));
if (strpos($url, 'customer/account') === false && strpos($url, 'skin') === false) {
$session->setData("lastUrl", $url);
}
}
and the second one located on the same location looks like this:
class In2itive_CustomerRedirect_Model_Observers_Customer_Redirect extends Mage_Core_Model_Abstract
{
/**
* @param $observer
*
* @return $this
*/
public function redirectCustomer($observer){
print('sadasd'); die();
$url = 'http://www.google.ro';
// $url can be : Mage::getUrl('some/path'); or Mage::getUrl('', array('_direct'=>'some-cms-page.html'));
Mage::app()->getResponse()->setRedirect($url);
return $this;
}
public function customerLoginRedirect($observer)
{ print_r("dsadasd"); die();
$this->_redirectUser($observer);
return $this;
}
/**
* Getting the latest url from session and the redirects the user after the login process to the latest url visited
* @param Varien_Event_Observer $observer
* @return void
*/
public function _redirectUser(Varien_Event_Observer $observer)
{
$sessionUrl = Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton('customer/session');
$lastUrl = $sessionUrl->getData("lastUrl");
$lastUrl = str_replace("/onepage/","",$lastUrl);
print_R($lastUrl); die();
$session->setAfterAuthUrl($lastUrl);
}
}
What i am doing wrong? why my observer is not accessed?