Create a database table to track session activity, say sessions
. In it, put at least the fields session_id
and a DATETIME or TIME field called last_activity
.
If you don't have so already, also create a carts
table that holds the content of the cart (like product_id
and quantity
) and has a link to the session_id
. Then, there are 2 scenarios:
- The user finishes the order, just "wipe" the rows in the
carts
table belonging to their session.
- The user abandons the cart, call a cronjob that checks to see if the
last_activity
value is more then you want it to be (say, more then an hour ago). Make that script re-stock your supply with the quantity that was in the cart.
Note that you will need to update the last_activity
field in your bootstrap/loader (a mechanism that is triggered on every loaded page).