We’re writing a small shopping cart for a customer (selling clothing) with a very low stock. That is for each size he’ll less than 10 items available. My worry is how to keep the available stock up to date. Or another word when should I consider an item as not available ? When the customer put the item in his shopping cart ? What about if the customer doesn’t actually buy the item ? How long after he started the buy I should make the item available again ?
You could make the item unavaliable as soon as it’s added to a shopping cart. Then if the shopper hasn’t completed the payment by a certain time (you decide a reasonable time) make all the items in the cart available again. That’s the way it would work in most real “bricks and mortar” stores.
I know your guy is dealing with a limited stock, but to me that also assumes a smaller traffic volume.
If someone adds an item to the cart, it seems to me, you’d have to -1 from available stock. HOWEVER, if that is the last item (or the second to last leaving only one left), then worry about webdev’s suggestion of the time out feature.
That’s probably a reasonable assumption but imo a risky one to base your code logic on.
What if say you have 4 items left and 6 people add them to their cart within a few minutes of each other and then all proceed to make their payments. You are then committed to finding an extra 2 items from somewhere or refunding/crediting 2 customers and doing at least potential harm to your business and reputation to deliver ordered goods.
It’s up to the op to weigh up the risks/consequences, so this is just some food for thought.
I’ll agree with that … unless it ends up being TRUE
The guy would have to look at his traffic and order volumes … and possibly have different rules based on how “hot” an item is.