Magento Customer Session – Destroy Customer Sessions Programmatically

customerevent-observersession

Even if I'm logged out of the site, I see my information in Online customers section in Magento admin if I'm not closing the window which seems to be normal Magento flow.

How can I destroy my session completely so that when I'm logged out, website will track me as a guest user?

I've tried firing customer_logout event and cleaning frontend cache using Mage::app()->cleanCache(); but it doesn't seem to be built for this purpose.

Here is observer function

public function flushCache(Varien_Event_Observer $observer)
    {
        $customer = $observer->getEvent()->getCustomer();
        Mage::app()->cleanCache();
        Mage::getSingleton('customer/session')->unsetAll();
    }

Best Answer

Whenever the logout() function of Mage_Customer_Model_Session called then

Magento is assign the customer as guest using $this->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);

For this reason at magento,you can see *the customer as guest *. also as per as system, after fire of customer_logout event magento is set customer as guest.So if you tried to make change then that may be not reflect

protected function _logout()
{
    $this->setId(null);
    $this->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
    $this->getCookie()->delete($this->getSessionName());
    return $this;
}

If you want to remove those assign then just rewrite Mage_Customer_Model_Session

and remove the code:

$this->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);

rewrite class:

<?php
class  [ModuleNameSpace]_[ModuleName]_Model_Session extends Mage_Customer_Model_Session{

 protected function _logout()
    {
        $this->setId(null);
        $this->getCookie()->delete($this->getSessionName());
        return $this;
    }

}

This may be help you.