[ic] Prevent from ordering more than is in stock

Mike Heins interchange-users@icdevgroup.org
Tue Oct 15 11:50:01 2002


Quoting Interchange user (interchange.mail@virgin.net):
> >     It should probably go in the ord/checkout file also, although I don't
> > have it there because I don't have that much concurrency.  For sites with
> > really high item concurrency at checkout there should probably be something
> > in the etc/profiles.order also.  For sites with mega ultra crazy order
> > volume and small stock quantities it might even be necessary to go beyond
> > that, one might have to start doing some sort of encapsulation using a
> > database transaction or a nasty semaphone to check the stock level and
> > decrement it or kick the order back all in one autonomous, serialized
> > operation.  But, man, if I ever get to that transaction volume I'll be able
> > to pay someone else to do that while I sit on the beach and drink
> > margaritas.  Until that point I will be using this:
> >
> > [comment]dont let users add more to cart than we have in stock[/comment]
> > [perl tables=inventory]
> >   my $item;
> >   foreach $item (@{$Carts->{main}}) {
> >     my $on_hand = tag_data('inventory', 'quantity', $item->{code});
> >     next if $on_hand >= $item->{quantity};
> >     if ($on_hand<=0) {
> >       $item->{quantity} = 0;
> >       $item->{q_message} = "Item is currently out of stock.";
> >     } else {
> >       $item->{quantity} = $on_hand;
> >       $item->{q_message} = "Limited item stock, order quantity adjusted.";
> >     }
> >   }
> > [/perl]
> >
> >
> >
> > Jeff
> 
> 
> Thanks Jeff, that's just the type of thing I was looking for. I've put that 
> at the top of ord/checkout.html, as I figure it should be parsed before 
> anything else, but it doesn't seem to be having any effect on the quantities 
> (I've restarted Interchange). Any ideas?
> 

As part of my continuing series plugging IC 4.9, there is now a feature
that does this:

    MaxQuantityField  inventory:quantity

You can set a field which will intrinsically limit the order quantity to
the amount in inventory. If the user orders 9 while 9 are in stock, then
there is an intervening order for 5, the number on order will automatically
be adjusted to 4 on the next cart refresh.

(The observant will notice that there are of some possible problems with
contention there, as it would be possible to have an order adjusted
between time of loading the checkout page and time of actual order
placement. There is some exception handling possible with this, but it
isn't documented yet. This type of thing is a very advanced function though,
and probably anyone using it should be capable of perusing the source.)

There is also

    MinQuantityField  inventory:min_order

which enforces a minimum order quantity automatically. Both of these set
warnings via $Tag->warning() when an adjustment takes place.

-- 
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