[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] perl syntax of shopping cart items
>
> I have a perl block on my checkout page and it needs to get the sku
> codes of the items in the shopping cart. I can do a dump() and see them
> buried deep down in some data structures. I've tried stuff like
>
> my @out = '';
> my %stuff = '';
> my $pop = '';
> my @input = @{$Carts->{main}};
>
> foreach %kip (@input) {
> foreach $pop (%stuff) {
> push (@out, $pop);
> }
> }
>
> and I get closer but I don't know what I'm doing so the going is kind of
> slow. Does anyone know the perl syntax for getting at those code values?
>
Basically, to grab values from the cart, use this sort of loop:
my $cart = $Carts->{main};
foreach my $item (@$cart){
# $item->{code} is the sku
# $item->{quantity} is the qty
}
So, stripping down the above example, you can push all the SKU
values into one array using the following two lines of Perl code:
my @out;
push(@out,$_->{code}) for (@{$Carts->{main}});
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin@cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/