I have a cart application with unique items with qty 1 - I need to deplete the stock qty when a user puts one in the basket to avoid someone else buying it. Problem is, that if they abandon the cart without buying I need to put the item back in stock.
Is there a way I can replenish the stock when the cart session expires? ie run a script to replace the stock.
You can use session_set_save_handler
to create a custom session-handling class.
When you do this, you can decide other actions that need to run either when the garbage collector is called or at session destroy. If you decide to work with the garbage collector, ensure that you also know the values for session.gc_divisor
and session.gc_probability
and also understand what they do (these set the probability that the garbage collector will run).
To avoid the need of cron jobs; keep it simple:
(time() + (60*20))
(This require that you update some sort of "last activity" in the database too)
Should be pretty straight forward.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With