2

I would like to set session during login action and clear session during logout action.

By googling I understand the following code will help setting the session and clearing the session.

Mage::getSingleton('customer/session')->setMyValue($myValue);
Mage::getSingleton('customer/session')->unsMyValue();

But I don't know what are the files and where exactly I need to include these code to set session during login and clear session during logout.

Please advice.

3

Use event observer to set your custom session value (Refer this tutorial for Event observers)

For customer login

use

<frontend>
    <events>
        <customer_logout>
            <observers>
                <your_unqiue_event_name>
                    <class>Namespace_Module_Model_Observer</class>
                    <method>logout</method>
                    <type>singleton</type>
                </your_unqiue_event_name>
            </observers>
        </customer_logout>

        <customer_login>
            <observers>
                <your_unqiue_event_name1>
                    <class>Namespace_Module_Model_Observer</class>
                    <method>login</method>
                    <type>singleton</type>
                </your_unqiue_event_name1>
            </observers>
        </customer_login>
    </events>
</frontend>

Then set/unset your custom session value

in

public function login()
{
     ..... 
     Mage::getSingleton('customer/session')->setMyValue($myValue);
     .....
}

public function logout()
{
    .....
    Mage::getSingleton('customer/session')->unsMyValue();
    .....
}
3
  • Where do i keep this xml file – shakthydoss Jul 6 '15 at 8:07
  • @shakthydoss refer the tutorial link, you will get better understand of magento event observer – MeenakshiSundaram R Jul 6 '15 at 8:08
  • Is there any way to find admin logout users from magento using event observer? – Naveenbos Sep 10 '15 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.