[ic] modifying [item-quantity]

Mathias Picker mathiasp@venus.virtual-earth.de
Sun, 27 Aug 2000 12:41:49 +0200 (CEST)


On 26 Aug, Mike Heins wrote:
> Quoting Mathias Picker (mathiasp@venus.virtual-earth.de):
>> First, a big thanks to the developers for a nice piece of software!
>> 
>> But it's a complex one, so one question:
>> 
>> How do I modify [item-quantity] in an [item-list]
> 
> You cannot, directly.
> 
>> 
>> 
>> Since I have limited stock, I need to stop users from ordering more
>> items than I have.
> 
> There are a number of ways to do this. Here is one, placed at the top
> of the basket and checkout page:
> 
> [perl tables=inventory]
> 
> 	my $cart = $Carts->{main};
> 	my $item;
> 	foreach $item (@cart) {
> 	        my $on_hand = tag_data('inventory', 'quantity', $item->{code});
> 		next if $on_hand >= $item->{quantity};	<
> 		$item->{quantity} = $on_hand;
> 		$item->{q_message} = "Order quantity adjusted to fit stock.";
> 	}
> 
> [/perl]
> ...

Very nice, thats exactly what I need. Thanks a lot!

Although I had to use 

   	foreach $item (@{$Carts->{main}}) {

to have it enter the loop. Can't think of why.


-- 
                            virtual earth
 Mathias Picker
 Geschäftsführer      Gesellschaft für Wissens re/prä sentation mbH

                            Mathias.Picker@virtual-earth.de 
			    Fon +49 89  / 540 7425-1
                            Fax +49 89  / 540 7425-9