I’m writing a website where users can order products, but the catch is that the products should automatically checkout (executes PHP script including MySQL queries) after 5 minutes even if the users logout/close the browser, etc. Has anyone had a problem similar to this. How should I go about coding this?
Share
Since this is a recurring automated task, you will need to set up a cron or other task scheduler. Crudely, this is how it would work:
When user adds product to shopping cart, it goes into database with a flag indicating that its not checked out along with timestamp of addition to db/shopping cart.
If the product is checkout by the user explicitly from the browser, this flag is updated to reflect the same.
The cron wakes up every one or two mins and checks this table for timestamps of items added to shopping cart without checkout flag updated and added more than 5 mins before.
It checks out such products and updates flag.
Please note that you will still need to further tweak this flow to handle situations like what happens if the user is manually checking out while your cron is doing the same etc etc
But on a nutshell I think this is how I would proceed to tackle the issue