[ic] Prevent from ordering more than is in stock

Michael Goldfarb interchange-users@icdevgroup.org
Mon Oct 14 15:17:00 2002


>Hello,
>
>I have prevented out of stock orders (foundation demo) by conditionally

>displaying the quantity box / having an 'Add to cart' button clickable
in >the 
>various pages (results.html, flypage.html, and the components such as
>random, 
>etc.), by use of a [if-item-data inventory quantity > 0] tag. I also
got >rid 
>of the 'Out Of Stock' and 'N' hyperlinks in flypage.html and
results.html 
>respectively.
>
>Is this sufficient to prevent people from ordering items that are out
of 
>stock?
>
>
>Also, the main reason for posting this; how can I prevent people from 
>ordering more items than are in stock?
>
>A search of the archives revealed this:
>
>
>>  [item-calc]
>>  my $q = q{[item-data inventory quantity]};
>>  my $s = q{[item-quantity]};
>>  if($q < $s) {
>>  return <<EOF;
>>  <font size=1 face="arial, verdana, helvetica" color="#ff0000">
>>  Sorry, only $q available.
>>  <br></font></TD><TD ALIGN=CENTER>
>>  <INPUT onChange="this.form.submit()" TYPE=text
NAME="[quantity-name]"
>>  VALUE=$q SIZE=3>
>>  EOF
>>  }
>>  else {
>>  return <<EOF;
>>  </TD><TD ALIGN=CENTER>
>>  <INPUT onChange="this.form.submit()" TYPE=text
NAME="[quantity-name]"
>>  VALUE="[item-quantity]" SIZE=3>
>>  EOF
>>  }
>>  [/item-calc]
>>  </TD>
>
>
>This would go in checkout.html, in the cart section, but the problem
here >is 
>that if someone arrives at the checkout page with more items than are
in 
>stock, or changes the quantity on the checkout page to more than is in
>stock, 
>the incorrect price is displayed.
>
>The solution is very simple - all I have to do is set the item quantity
to 
>the inventory value for that item within the above 'if' statement, but
HOW >do 
>I do this, either in ITL or Perl?
>
>Thanks in advance.

How about a SQL query?

[query sql="select quantity from inventory where sku = '[item-code]'"
list=1]
[sql-pos 0]
[/query]

In this example, "[sql-pos 0]" should pull the number in the inventory
for the given sku.

HTH