[ic] Prevent from ordering more than is in stock

Mike Heins interchange-users@icdevgroup.org
Tue Oct 15 19:34:01 2002


Quoting Jim Balcom (jim@idk-enterprises.com):
> On Tue, 15 Oct 2002, Mike Heins wrote:
> 
> MH>>As part of my continuing series plugging IC 4.9, there is now a feature
> MH>>that does this:
> MH>>
> MH>>    MaxQuantityField  inventory:quantity
> MH>>
> MH>>You can set a field which will intrinsically limit the order quantity to
> MH>>the amount in inventory. If the user orders 9 while 9 are in stock, then
> MH>>there is an intervening order for 5, the number on order will automatically
> MH>>be adjusted to 4 on the next cart refresh.
> MH>>
> MH>>(The observant will notice that there are of some possible problems with
> MH>>contention there, as it would be possible to have an order adjusted
> MH>>between time of loading the checkout page and time of actual order
> MH>>placement. There is some exception handling possible with this, but it
> MH>>isn't documented yet. This type of thing is a very advanced function though,
> MH>>and probably anyone using it should be capable of perusing the source.)
> MH>>
> 
> When is it counting the inventory, and when is it being deducted?
> 
> Customer A orders 10 gadgets and puts them in his cart. (There are only 15
> in stock). Does it deduct them then, or does it deduct them when he
> submits his order? Or, after the CC# approval and the receipt sent to him?
> 
> Customer B orders 10 gadgets and puts them in his cart at the same time as
> Customer A. They both hit 'submit' within seconds of each other. The first
> one submitted has a declined card, so at that precise moment there are 15 in
> stock for customer B. Does customer B only get 5?
> 
> Depending on when they are deducted, if they get deducted when they are put
> in the cart, will they get plussed when they are removed from the cart? And,
> if customer B has been told that he can only have 5, does he get his desired
> quantity restored when customer A takes them out of his cart?

WIth a transaction-capable database, the answer is in that there is no
bar to putting them in your cart except current inventory. Once your
order starts, you get as many as are available at that time. The next
person gets none if that is all that are available. 

At no time can you ever be in a negative-inventory situation, because
the total-cost calculation is done within the transaction boundary. An
attempt to set an inventory number to negative would, presuming your
database supports it, cause a fault that would cause the order to
fail.

The trick is the event handler that triggers when you

	1) cross the boundary where you will place the order if 
           your credit card validates

	2) have an event that lowers the quantity you would
           receive.

Right now, if you had 9 in your cart and someone else had 12, and
they ordered first, you would get 2 and would only be charged for
that number.

I am not too disposed to go far into theoreticals here, but that
is how it is by default right now. Any further fine-tuning would
be something I would have to study, and I probably won't do that
unless someone has a need pressing enough to pay me to study it. 8-)

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Nature, to be commanded, must be obeyed. -- Francis Bacon