Yes, its possible.
OPTION 1: Using event observer, add below code in your config.xml
:
<events>
<customer_login>
<observers>
<redirection>
<class>redirection/observer_customer</class>
<method>customerLogin</method>
</redirection>
</observers>
</customer_login>
</events>
And in your customerLogin()
of Namespace_Extension_Model_Observer_Customer
class you need to check if current cart has any item then redirect to shopping cart page like -
public function customerLogin(Varien_Event_Observer $observer)
{
if (Mage::getModel('checkout/cart')->getQuote()->getItemsCount()){
$_session = Mage::getSingleton('customer/session');
$_session->setBeforeAuthUrl(Mage::helper('checkout/cart')->getCartUrl());
}
}
OPTION 2: Another option is to override Mage_Customer
controller.
In your module config.xml
file add below code:
<frontend>
<routers>
<customer>
<args>
<modules>
<moduleidentifier_customer before="Mage_Customer">YourModule_Customer</moduleidentifier_customer>
</modules>
</args>
</customer>
</routers>
</frontend>
After that you have to create account controller inside your module controllers
directory and placed below code in your controller class:
class Yourmodule_Customer_AccountController extends Mage_Customer_AccountController
{
/**
* Overriding defaults redirect URL
* Define target URL and redirect customer after logging in
*/
protected function _loginPostRedirect()
{
$session = $this->_getSession();
if($session->isLoggedIn() && Mage::getModel('checkout/cart')->getQuote()->getItemsCount()){
$_session->setBeforeAuthUrl(Mage::helper('checkout/cart')->getCartUrl());
}
else{
if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) {
// Set default URL to redirect customer to
$session->setBeforeAuthUrl($this->_getHelper('customer')->getAccountUrl());
// Redirect customer to the last page visited after logging in
if ($session->isLoggedIn()) {
if (!Mage::getStoreConfigFlag(
Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
)) {
$referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
if ($referer) {
// Rebuild referer URL to handle the case when SID was changed
$referer = $this->_getModel('core/url')
->getRebuiltUrl( $this->_getHelper('core')->urlDecodeAndEscape($referer));
if ($this->_isUrlInternal($referer)) {
$session->setBeforeAuthUrl($referer);
}
}
} else if ($session->getAfterAuthUrl()) {
$session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
}
} else {
$session->setBeforeAuthUrl( $this->_getHelper('customer')->getLoginUrl());
}
} else if ($session->getBeforeAuthUrl() == $this->_getHelper('customer')->getLogoutUrl()) {
$session->setBeforeAuthUrl( $this->_getHelper('customer')->getDashboardUrl());
} else {
if (!$session->getAfterAuthUrl()) {
$session->setAfterAuthUrl($session->getBeforeAuthUrl());
}
if ($session->isLoggedIn()) {
$session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
}
}
}
$this->_redirectUrl($session->getBeforeAuthUrl(true));
}
}
Note: Compare your Mage_Customer_AccountController
class
_loginPostRedirect()
method with above mentioned
_loginPostRedirect()
method for difference. Change module
,
method
, configuration node
, etc. according to your module.
Let me know if you have any issue regarding approach.