0

This question already has an answer here:

I am trying to get customer last logged in (last visited) date in front end but it returns null . For some users it returns the date which also doesn't seems to be the correct date . this is what i am using to get last login date .

$collection = Mage::getModel('customer/customer')->getCollection();  
 foreach ($collection as $customer) { 
    $logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
    $lastVisited = $logCustomer->getLoginAt();
 }

Also on back end it shows Last Logged In: Never (Offline) for most of the users .

marked as duplicate by Fabian Schmengler, sv3n, Prince Patel, liyakat, Manthan Dave Aug 2 '17 at 8:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • and what is the $customer variable?? How do you get the customer?? – Asish Hira Apr 26 '16 at 8:14
  • $collection = Mage::getModel('customer/customer')->getCollection(); foreach ($collection as $customer) { } – Seefan Apr 26 '16 at 8:15
0

Use This code

$collection = Mage::getModel('customer/customer')->getCollection();  
 foreach ($collection as $customer) { 
    $logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
    $lastVisited = $logCustomer->getLoginAtTimestamp();
 }
  • getLoginAtTimestamp() and getLoginAt() returning same result . – Seefan Apr 26 '16 at 9:12
0

Last login date stores in table log_customer

select * from log_customer;

If Magento on back end shows Last Logged In: Never (Offline, it means that customer never logins before and log_customer has not data for this customer.

  • There are customers which completed orders and on backend it shows Logged In : Never . Also log_customer table contains data . – Seefan Apr 26 '16 at 9:10
0

If you have data in log_customers and your code is not returning correct result, could it be there is some module overwriting this default behavior?

0

For those how are facing the same problem, getting null from $logCustomer->getLoginAt() function, take a look at this link below:

Last Logged In, in Customers always shows 'Never (Offline)'

goto system -> configuration -> advanced -> system -> log and enable log.

  • 1
    Welcome to Magento SE and thanks for your contribution. Since the question boils down to the same problem as the one you linked, I flagged it as duplicate now. – Fabian Schmengler Aug 1 '17 at 20:39

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