[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Perl Cart Maniuplation
Quoting Erik Fantasia (epfantasia@hotmail.com):
> I'm at the moment doing various things on the basket page with some perl,
> such as:
>
> my $cart = $Carts->{main};
> my $count = 0;
>
> foreach $item (@cart) {
>
> ...
>
> }
>
> Now one of the things I would like to do is allow customers to forward order
> items not currently in stock by including a separate line in the basket with
> the quantity to be ordered. I've worked out that an identical line can be
> added in the loop with:
>
> splice (@{$Carts->{main}},$count,1,$item); # NB: $count++ precedes
>
> However, then when i try to adjust any of the properties of this new nested
> hash, ie:
>
> $Carts->{main}[$count]{mv_ip} = $count;
>
> The new hash remains unchanged from the original $items hashref!
>
> Any clues?
>
This is just perl. You have copied the reference -- the data hasn't
changed.
You would have to do something like:
my $cart = $Carts->{main};
my @clone;
foreach my $item (@$carts) {
my $onhand = $Tag->data('inventory', 'quantity', $item->{code});
push @clone, { %$item }
if $onhand - $item->{quantity} < 1;
}
foreach my $new (@clone) {
push @$cart, $new;
$new->{mv_ip} = $#$carts;
}
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.513.523.7621 <mike@perusion.com>
For a successful technology, reality must take precedence over public
relations, for Nature cannot be fooled. -- Dick Feynman