|Product stock system - how would I go about doing this?|
| 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?
| 5:30 pm on Sep 20, 2012 (gmt 0)|
Instead of dumping a cart when the user closes the browser or the session ends, it's a much better user experience to allow the cart to be saved. Several sites I frequent maintain the items in my cart for many days or even weeks. Other sites allow users to save their carts for even longer. I believe Dell expires saved carts after 30 days or so.
My suggestion would be to save the cart info to your DB and use a cookie or session variable to identify the cart in your DB (instead of saving everything in the cart in a cookie or session variable). Have an automatic processes to clean up your Carts table and return items to active inventory if the cart has been inactive for whatever period of time you decide to use.
You may want to use different time frames for different items. For example, if you have thousands of pieces of one item in stock, you could use a longer window than for something with only 1 or 2 pieces left in stock.
Of course, you should notify your users of the time frame for cart/item expiration. For the low inventory items, something like "This item is in high demand, so will be returned to inventory automatically in 2 hours if you do not complete your checkout by then."
| 7:52 pm on Sep 20, 2012 (gmt 0)|
Oh, okay thanks. That's a much better idea! Not sure why I didn't think of that before!
Thanks again, much appreciated!
| 3:52 pm on Sep 24, 2012 (gmt 0)|
I wouldn't do that at all - so someone who has every intention of buying and checking out there and then is prevented from doing so by a tyre kicker who just wanted to scope out your delivery costs.
Leave any reduction of inventory until they checkout their order.
| 4:05 pm on Sep 24, 2012 (gmt 0)|
Okay thanks, you make a really good point!
Much appreciated, I'll take that into account.
| 4:12 pm on Sep 24, 2012 (gmt 0)|
I mean maybe you could lock the inventory if they begin your checkout process or something, or maybe if they get to the payment details stage as they are getting closer to committing to the purchase, but still there is scope for them to bail out.