1

What i am trying to achieve is: Abandoned Customer Email Notification using 2 ways. 1). when customer logged out or closed his browser, 2). After X no. of days

ON Both ways cron will work.

For 2nd Way i have the solution.

But for the 1st way i am not getting how to check the customer is logged out or not, on the external php page or in module.

Kindly suggest, Please.

3 Answers 3

3

I found this answer on stackoverflow...

https://stackoverflow.com/questions/13723166/magento-can-not-detect-if-customer-is-logged-in-or-not

require_once 'app/Mage.php';


umask(0);

Mage::app('default');

Mage::getSingleton('core/session', array('name' => 'frontend'));

$sessionCustomer = Mage::getSingleton("customer/session");

if($sessionCustomer->isLoggedIn()) {
  echo "Logged";
} else {
   echo "Not Logged";
}

for more details check here Magento Customer login

2
  • This method will work for detecting if a user is logged in our out. However to trigger the sending of an email using this method would require the visitor of the site to visit this custom page. I added an alternative method below that operates via cron Jan 29, 2015 at 22:06
  • 1st Thanks for the reply CarComp, But i think you didn't get the question correctly, The above code check the customer logged in on same browser, What i want is, i need to perform some action when any user logout or closes his browser.
    – Ankur Jain
    Jan 30, 2015 at 5:55
1

The way that I have achieved this in the past is to rely on the Magento cron and run this every X interval.

The way to check if a customer is logged in or not is to look at the log_customer table within Magento. There are 2 columns login_at logout_at if there is a timestamp for logout_at then you know that the customer has logged out and it is safe to trigger some action.

Without looking at the code again I cant remember if there is a model you can use to get access to this data or if I had to rely on SQL to access the data.

However looking at this table should provide you with the information you require.

One consideration is that the log_* tables can be disabled so depending on the store you might not have access to this data.

2
  • Thanks! James Cowie. I already checked this table, but the thing is that if user do not click the logout and closes his browser then the logout_at field remain NULL, so i got stuck in this that how can we know that he logged out/ Closed his browser. Please suggest.
    – Ankur Jain
    Jan 30, 2015 at 6:02
  • There is no real way of detecting if a browser is closed . What you could do is in the SQL query get all customers that have a logged in over 2 hours, Chances are they are not on the site any more. There may be a way to do this via the users_online table to detect if they are still online. Jan 30, 2015 at 10:49
0

If the customer physically clicks on the logout button, then you could observe the following event: controller_action_predispatch_customer_account_logout

If the customer closes the browser window, you could add some javascript that detects this which can send an XHR request notifying Magento of the window being closed.

If the user closes the browser, you last bet would be to look at log tables.

The better way to check for abandoned carts is to check x days against stale quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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