[ic] Set mv_price upon addition to cart

Dan B db@cyclonehq.dnsalias.net
Sat, 31 Mar 2001 21:02:57 -0800

On my results page, when a user clicks "add to cart", I would like to set 
$Carts->{main}->[$line]{mv_price} for that lineitem.

I'm trying to do it with mv_click code, but the item doesn't seem to be 
added to the cart until after mv_click (i.e. after refresh).  My mv_click 
happens to do [munge_quantity], so that's where I'm working in...

So I thought I would try to do
[set munge_quantity]

But that didn't take either.

However, I *can* modify mv_price if I loop through the entire cart.  But 
why do that when I just want to set the price once when the user adds it to 
his cart?

I've been pouring over docs and the mailing list for the past 14 hours, and 
at this point I would appreciate any tips or directional suggestions.  Thanks!


Here's a snippet:

[set munge_quantity]
         $Scratch->{did_order} = 1;
         @q = split /\0/, $CGI->{mv_order_quantity};
         for (@q) {
                 next unless length $_;
                 $_ = "=$_";
         @parms = grep /^mv_oi\d+/ && $CGI->{$_}, keys %{$CGI};

         # If we have parms, means an individual buy. If we don't
         # we want to strip empty items
         unless (@parms) {
                 @i = split "\0", $CGI->{mv_order_item};
                 for(my $i = 0; $i < @i; $i++) {
                         next if length($q[$i]);
                         $i[$i] = '';
                 @i = grep length($_), @i;
                 @q = grep length($_), @q;
                 $CGI_array->{mv_order_quantity} = \@q;
                 $CGI->{mv_order_quantity} = join "\0", @q;
                 $CGI_array->{mv_order_item} = \@i;
                 $CGI->{mv_order_item} = join "\0", @i;
         my $item = $parms[0];
         $item =~ /(\d+)/ or return;
         my $idx = $1;
         $CGI->{mv_order_item} = $CGI->{$item};
         $CGI->{mv_order_quantity} = "$q[$idx]";

# munge_quantity done, now modify price
# (this works, but doesn't access the last lineitem)
         my $cart = $Carts->{main};
         my $price = 99.99;

         for( my $i = 0; $i < @$cart; $i++) {
                 $cart->[$i]{mv_price} = $price;
         [bounce href="[history-scan exclude=nothing]"]

Dan Browning, Cyclone Computer Systems, danb@cyclonecomputers.com