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
2 Answers 2
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();
$customer->getEmail();
$customer->getFirstname();
$customer->getLastname();
$customer->getId();
endif;
-
Thanks Amit, I checked with your code, but still I am not getting the customer details in my custom module index controller.Phani Bob– Phani Bob2015年06月29日 19:10:34 +00:00Commented Jun 29, 2015 at 19:10
-
Are controllers work?2015年06月29日 19:12:17 +00:00Commented Jun 29, 2015 at 19:12
Try below code
if (Mage::getModel('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
echo '<pre>';
print_r($customer->getData());
} else {
echo 'Not Logged in';
}
Explore related questions
See similar questions with these tags.