How to bind an action after customer login success using Magento?
On the Mage_Customer_Model_Session
model's method setCustomerAsLoggedIn()
an event customer_login
is being dispatched. I guess you need to hook in on that event. You could do this as follows.
Add the event to your module's config.xml
file (app/code/local/Lpf/ModuleCookie/etc/config.xml):
<?xml version="1.0"?>
<config>
<modules>
<Lpf_ModuleCookie>
<version>0.1</version>
</Lpf_ModuleCookie>
</modules>
<global>
<models>
<lpf_modulecookie>
<class>Lpf_ModuleCookie_Model</class>
</lpf_modulecookie>
</models>
</global>
<frontend>
<events>
<customer_login>
<observers>
<lpf_modulecookie_customer_login>
<type>model</type>
<class>lpf_modulecookie/observer</class>
<method>customerLogin</method>
</lpf_modulecookie_customer_login>
</observers>
</customer_login>
</events>
</frontend>
</config>
Now create a model Lpf_ModuleCookie_Model_Observer
(app/code/local/Lpf/ModuleCookie/Model/Observer.php). Add a customerLogin()
method to the class:
class Lpf_ModuleCookie_Model_Observer
{
/**
* Run couple of 'php' codes after customer logs in
*
* @param Varien_Event_Observer $observer
*/
public function customerLogin($observer)
{
Mage::log(__METHOD__ . '() Hello!'); // Remove afterwards. Check your var/log/system.log to see if came to this point
$customer = $observer->getCustomer();
// "run couple of 'php' codes"
}
}