@@ -287,6 +287,8 @@ private function getGroup($groupId)
287
287
}
288
288
289
289
/**
290
+ * Returns timezone of the store to which customer assigned.
291
+ *
290
292
* @return string
291
293
*/
292
294
public function getStoreLastLoginDateTimezone ()
@@ -301,20 +303,31 @@ public function getStoreLastLoginDateTimezone()
301
303
/**
302
304
* Get customer's current status.
303
305
*
306
+ * Customer considered 'Offline' in the next cases:
307
+ *
308
+ * - customer has never been logged in;
309
+ * - customer clicked 'Log Out' link\button;
310
+ * - predefined interval has passed since customer's last activity.
311
+ *
312
+ * In all other cases customer considered 'Online'.
313
+ *
304
314
* @return \Magento\Framework\Phrase
305
315
*/
306
316
public function getCurrentStatus ()
307
317
{
318
+ // Customer has never been logged in.
308
319
if (!$ this ->getCustomerLog ()->getLastLoginAt ()) {
309
320
return __ ('Offline ' );
310
321
}
311
322
323
+ // Customer clicked 'Log Out' link\button.
312
324
if ($ this ->getCustomerLog ()->getLastLogoutAt () &&
313
325
strtotime ($ this ->getCustomerLog ()->getLastLogoutAt ()) > strtotime ($ this ->getCustomerLog ()->getLastLoginAt ())
314
326
) {
315
327
return __ ('Offline ' );
316
328
}
317
329
330
+ // Predefined interval has passed since customer's last activity.
318
331
$ interval = $ this ->getOnlineMinutesInterval ();
319
332
320
333
if ($ this ->getCustomerLog ()->getLastVisitAt () &&
@@ -333,28 +346,36 @@ public function getCurrentStatus()
333
346
*/
334
347
public function getLastLoginDate ()
335
348
{
336
- if ($ date = $ this ->getCustomerLog ()->getLastLoginAt ()) {
349
+ $ date = $ this ->getCustomerLog ()->getLastLoginAt ();
350
+
351
+ if ($ date ) {
337
352
return $ this ->formatDate ($ date , TimezoneInterface::FORMAT_TYPE_MEDIUM , true );
338
353
}
354
+
339
355
return __ ('Never ' );
340
356
}
341
357
342
358
/**
359
+ * Returns customer last login date in store's timezone.
360
+ *
343
361
* @return \Magento\Framework\Phrase|string
344
362
*/
345
363
public function getStoreLastLoginDate ()
346
364
{
347
- if ($ date = strtotime ($ this ->getCustomerLog ()->getLastLoginAt ())) {
365
+ $ date = strtotime ($ this ->getCustomerLog ()->getLastLoginAt ());
366
+
367
+ if ($ date ) {
348
368
$ date = $ this ->_localeDate ->scopeDate ($ this ->getCustomer ()->getStoreId (), $ date , true );
349
369
return $ this ->formatDate ($ date , TimezoneInterface::FORMAT_TYPE_MEDIUM , true );
350
370
}
371
+
351
372
return __ ('Never ' );
352
373
}
353
374
354
375
/**
355
- * Return online minutes interval .
376
+ * Returns interval that shows how long customer will be considered 'Online' .
356
377
*
357
- * @return int Minutes Interval
378
+ * @return int Interval in minutes
358
379
*/
359
380
protected function getOnlineMinutesInterval ()
360
381
{
0 commit comments