Is it possible to have all the items removed from the shopping cart after a period of inactivity? Here's why I ask...
I think I've explained what Im trying to do in an earlier post on this forum, but in case I didn't and to recap, here it is again:
(For most of the products) the system I am setting up is for one-up items. Each item is unique (quantity 1) and can only be purchased once. So, to avoid people from purchasing two of the same item, here is the way I've got things going.
1. Somebody comes to the store. They find a product they want and click the "add to cart" link.
2. Before the item is added to the cart, an AJAX request is sent querying the database to check and make sure that the product is indeed still available.
3. If the product is indeed still available, another AJAX request is sent to the database, which puts a "lock" on the product, which will expire after a period (lets say 15 minutes) of inactivity based of the user's IP address. If the product is not available (it has either been sold or locked by a different user since the page initially loaded on our user's system) a message is displayed and the item is not added to the cart.
4. So, the user either completes the purchase and the status of the product is changed from "lock" to "sold", or 15 minutes go by, and the product's status changed back to "available".
But if the period of inactivity goes by, I would the cart to expire at the same time as the product's status switches back to unavailable.
I guess if that's not possible, I could just run a check everytime the cart opens that would check each item. If (after the period of inactivity) the item is still available (the status was reset and nobody else locked or purchased it) I would re-lock the item for the user, giving him a fresh new 15 minutes to buy it. If the item isn't available, I could show a message explaining they took too long and remove it from the cart. But, I would prefer to have the cart expire, it would be easier.
As a side note of something you might be interested in, I am using the data feed to get purchased items and change them from "lock" to "sold" in the database.