I am developing custom module which needs to use customer data from session. Here I am having some problem with session. I am unable to get any customer data in my custom module from session even if the user logged in.

I logged below code in my index controller.

Mage::getSingleton('core/session', array('name' => 'frontend'));
        $customer_id = Mage::getSingleton('customer/session')->getCustomer()->getId();
        Mage::log("Index - customer id check: " . $customer_id);

A failure to get customer Id.

After that added customer_login event and tried to log the same in the observer method. Here it worked.

But, still not working in the index controller.

Please help


You need to check customer is loggedin or not.

Without customer loggin,you cannot get customer data from session:

if (Mage::getSingleton('customer/session')->isLoggedIn()):
    $customer = Mage::getSingleton('customer/session')->getCustomer();
| improve this answer | |
  • Thanks Amit, I checked with your code, but still I am not getting the customer details in my custom module index controller. – Phani Bob Jun 29 '15 at 19:10
  • Are controllers work? – Amit Bera Jun 29 '15 at 19:12

Try below code

    if (Mage::getModel('customer/session')->isLoggedIn()) {
        $customer = Mage::getSingleton('customer/session')->getCustomer();
        echo '<pre>';
    } else {
        echo 'Not Logged in';
| improve this answer | |

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.