Question

What are the best (or perhaps most commonly used) approaches for coordinating actual stock quantities with that shown or offered for sale with a shopping cart?

Thanks in advance, Matt

Was it helpful?

Solution

Well, you have several problems.

At a basic level, its "easy". Simply use classic transactional processing techniques to maintain the stock numbers and the order entry lines against the stock. If you have 10 available, and someone orders 1, then commit the line item with a qty of 1 at the same time you increment the "committed" qty on the inventory item. When you ship the item, remove one from In Stock, and one from Committed. In Stock - Committed = Available.

So:

          In Stock   Committed    Available
 Before:     10          0           10
Ordered:     10          1            9
Shipped:      9          0            9

The down side is that involves a bunch of locking, which can affect concurrency. Depending on your traffic this may or may not be an issue. Then you're work with on the fly counting of ordered items against stock, and you end up with race conditions. But it's really just a fact of life in business.

But, either way, regardless of how you commit the entry in to your database, it doesn't mean that the item will actually ship.

The In Stock number could simply be wrong. It could have been miskeyed, stock may be damaged, "employee shrinkage", etc. All sorts of things can go wrong. So, any commitment you make to a customer that you'll actually SHIP what you've promised has to have that little * next to it as a disclaimer.

Then you get in to the whole back ordering, cancellation and fulfillment issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top