login observer

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. appcodelocalScommerceLogin

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>

Step 3

Create config.xml in the etc directory of your module i.e appcodelocalScommerceLoginetc

<?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>

Step 4

Create a observer class in the model directory of your code i.e. appcodelocalScommerceLoginModel

<?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.

Similar Posts