Using customised Magento ver., how I display/export customer list with last login date?

I am looking for last login date and never logged in.


Try this:

$collection = Mage::getModel('customer/customer')->getCollection();
foreach($collectin as $customer){
   $logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
   $lastVisited = $logCustomer->getLoginAtTimestamp();
   echo $lastVisited = $customer->getFirstname(). " => ".date('Y-m-d H:i:s', $lastVisited). "<br>";

This should give you what you are looking for.


To show this result in admin area, I would create a simple admin extension: learn here.

And put above code in controller for quick view, however I want you to understand how MVC works in magento and show desired result in magento way.

  • Sorry I am a novice in this, where do I insert this code? Thanks for your help. – ajains Feb 8 '16 at 5:16
  • It depends. Where do you want to display the result? – Adarsh Khatri Feb 8 '16 at 5:16
  • in the default customer list or in an export with customer listing and the last login and/or no of logins – ajains Feb 8 '16 at 5:20

if you have access to phpMyAdmin, you can run the following query for looking at customers in last login order:

SELECT * FROM `customer_entity`
LEFT JOIN `log_customer` on customer_entity.entity_id = log_customer.customer_id
ORDER BY log_customer.login_at DESC

or if you want a list of those who never logged in:

SELECT * FROM `customer_entity`
LEFT JOIN `log_customer` on customer_entity.entity_id = log_customer.customer_id
WHERE log_customer.login_at IS NULL

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.