[ic] Remove one item from a cart? Limit quantities?

Mike Heins interchange-users@icdevgroup.org
Tue Jan 28 15:22:00 2003


Quoting Jeff Dafoe (jeff@badtz-maru.com):
> > 1) I can't figure out how the snippet in the FAQ allows me to
> > remove one item from a cart; there's just no context for it.
> > Can anyone provide that?  I can delete the WHOLE cart, but
> > that doesn't make for a pleasant shopping experience when
> > you've picked multiple items and your mouse slips.
> 
>     Look at the Foundation cart component (templates/components/cart) for
> sample code.  It's done by setting the quantity of an item to zero.
> 
> > 2) On a possibly related note, is there a good way to tell
> > the cart in the "simple store" that it should NOT increment
> > quantities when an item is picked twice?  We're selling one-
> > offs, so once a sku is selected there just aren't any more
> > of it.  I have hardcoded the display so the quantity always
> > shows as "1" but would like the internals to support it
> > correctly.
> 
>     This code below came from someone on the list, I think it was Ed.  It
> goes at the top of the basket (templates/components/cart) and checkout
> (ord/checkout) pages.  Then set the inventory for your items to 1.
> 
> [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]
> 

In 4.9.x, you can do this directly:

    MaxQuantityField  inventory:quantity

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

How far can you open your mind before your brains fall out?