
There are a lot of reasons you want to override customer login function of Magento, it could be because you want to implement captcha or new tracking or log customer data or many other reasons. Today going to cover this using observer which is always been preferable over overriding the whole class.
Let’s do the usual way step by step implementation
Step 1
Create a new module under your local folder i.e. app\code\local\Scommerce\Login
Step 2
Register your module in etc/modules directory by adding Scommerce_Login.xml file with the following content-:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Scommerce_Login>
<active>true</active>
<codePool>local</codePool>
</Scommerce_Login>
</modules>
</config>
Step 3
Create config.xml in the etc directory of your module i.e app\code\local\Scommerce\Login\etc
<?xml version="1.0"?>
<config>
<modules>
<Scommerce_Login>
<version>0.0.1</version>
</Scommerce_Login>
</modules>
<global>
<models>
<scommerce_login>
<class>Scommerce_Login_Model</class>
</scommerce_login>
</models>
</global>
<frontend>
<events>
<customer_login>
<observers>
<scommerce_customer_login><!--User Defined Unique Name-->
<class>scommerce_login/observer</class>
<method>checkLoginStatus</method>
</scommerce_customer_login>
</observers>
</customer_login>
</events>
</frontend>
</config>
Step 4
Create a observer class in the model directory of your code i.e. app\code\local\Scommerce\Login\Model
<?php
class Scommerce_Login_Model_Observer extends Mage_Core_Model_Abstract
{
public function checkLoginStatus(Varien_Event_Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$website = Mage::getModel("core/website")
->load($customer->getWebsiteId());
if ($website->getCode()=="base"){
//your custom code will go here
}
}
}
Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.



Thanks in support of sharing such a pleasant idea, paragraph is fastidious, thats why i have read it completely
It’s a shame you don’t have a donate button! I’d without a doubt donate to this excellent blog! I guess for now i’ll settle for bookmarking
and adding your RSS feed to my Google account. I look forward
to fresh updates and will talk about this site with my Facebook group.
Chat soon!
app/code/local/Scommerce/Login/Model on which name assign to file.
Observer.php
Thank you very much!.
Its working fine to me. I can trigger a function after successful login.
Thanks once again
Great Mahesh, we are glad it is working for you!!!!