DavidOmid - 2:49 pm on Sep 20, 2012 (gmt 0)
I've developed my own custom shopping cart system for a client.
The client can easily add products and choose the name, price, shipping costs and tax, description, sizes and quantities of each size available in stock.
This system is finished apart from one feature - the ability to automatically mark products as "Out of stock" when the available stock reaches 0.
For example, let's say 2 users are on the site and they both want to buy a red T-shirt. There's only one red T-shirt left, and one of the users adds it to their cart. I want it to then prevent any other users from adding a red T-shirt to their cart, until either of the following happen:
1. The online shop owner adds more stock to the site.
2. The user who put the last red T-shirt in their cart removes it from their cart or otherwise leave the store.
It's pretty easy to do all this, apart from when they leave the store (by closing their window, session ends etc).
How would I go about determining when their session has ended, and then determining which items were in their cart? I'm using PHP with a MySQL back-end.
I'd also be open to doing this in a completely different way. How do other shopping cart systems deal with this issue?