2

I Noticed that if a user has their computer clock off (wrong date or AM instead of PM etc.) and adds items to the cart and click checkout, he will get a message that he has no items in his cart, since there's a time mismatch which breaks the code.

So instead of the user getting frustrated and calling support (or abandons the cart completely), I'm wondering if there's some way to detect if the user's time / date is correct, and if not create an alert to fix his clock.

Any ideas? The site runs on php, so any script in php, javascript / ajax etc. would be awesome.

Thank you!

scrollup
  • 206
  • 4
  • 12
  • 1
    You should rather diagnose what's causing the cart to disappear when the user's clock is wrong. Maybe you should give your cookies a more generous expiration date, for instance? – Matti Virkkunen Dec 31 '12 at 15:22
  • 2
    Instead of trying to fix the client's clock, just get the time from the server. – Will C. Dec 31 '12 at 15:22
  • I'm not sure how the internals of magento works, and changing something in the core can create more chaos then just adding a small script (if that's all it takes)... – scrollup Dec 31 '12 at 15:57
  • Are you talking about cookies here? – Marty Wallace Dec 31 '12 at 23:34
  • Honestly I'm not exactly sure what method magento uses that takes the user's clock into account. Cookies do make sense though... – scrollup Jan 01 '13 at 04:46

2 Answers2

13

You would be better to change your code so that there is no reliance on the client side clock at all.

How do you deal with different timezones etc...?

Server side code should never rely on the client side environment to match.

Paddy
  • 33,309
  • 15
  • 79
  • 114
1

I would not recommend that you rely mainly on the client side for validating time/time-zones for your shopping carts. The client's time may be incorrectly set (even deliberately for malicious acts...the tricks never end.)

What you need to do is properly handle the scenario of the users with different time-zones.

Here is what you can do:

  • Use JavaScript to retrieve client's time/time-zone (see this question)
  • Make a post to the server to validate it.
  • Convert the time to the respective timezone. This can be used to either properly display to a time to the user or be stored in a cookie/session to keep track of the user information.
  • If a valid time was not provided, just use the server time.

It all depends on how you're currently dealing with the different time-zones...

Flimm
  • 136,138
  • 45
  • 251
  • 267
heyomi
  • 385
  • 5
  • 18
  • That's a good suggestion, since I don't want to change the internal functions of magento. I guess I can use that method to test the user's clock and if it doesn't match with the server, alert them that their clock is off. Also this way it'll prevent other errors the user might be having (for example if your clock is way off you'll get SSL certificate warnings all over..). – scrollup Dec 31 '12 at 18:08
  • Indeed. Error prevention and validation is key. – heyomi Jan 03 '13 at 00:47