[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
Re: [ic] Is this a known issue/bug? Problems removing items from cart.
Steven Morrison wrote:
>
> Hello group,
>
> I am having some problems with my templates. It seems I cannot remove items
> from my cart if there is more than one item there. If I attempt to remove
> an item except for the first one (quantity0) it does not do so. If I
> attempt to remove the first item, I am left with two errors, one right after
> the other:
>
ok relax I have done a lot of stuff manipulating the Cart while constructing
malls. Here is a complete example of code that among other things remove item
from the cart.
[perl]
# ok lets get the carts we are going to run over
my $carts = $CGI->{'carts'};
my @carts;
if($carts =~ /_/g){
@carts = split("_",$carts);
}
else{
push @carts,$carts;
}
foreach my $cart (@carts){
if(! exists $Carts->{$cart}){
next;
}
#log
#$Tag->log({file=>"/tmp/kil.log"}, "Cart = ".$cart);
my @remove_numbers ;
# the numbers that are attached to the
# cart name.
# it is likely that the numbers will be
# letters so we don't get confused
# with the quanities.
# These numbers will relate to the
# 'mv_ip' numbers
# i.e. cameronsquare.a_qw_s
#
my $numbers = $CGI->{$cart.".numbers"};
my @numbers = split("_",$numbers);
$numbers-- ;
foreach my $num (0 .. $numbers){
# defines the quanitiy of
# product.
my $quan_name = $cart.".quantity".$num;
my $quantity = $CGI->{$quan_name};
#$Tag->log({file=>"/tmp/kil.log"}, "$quan_name = ".$quantity);
#if(!$quantity){
#$Tag->log({file=>"/tmp/kil.log"}, "Oh, zerio quantity");
#}
if(($quantity) && (exists $Carts->{$cart})){
#$Tag->log({file=>"/tmp/kil.log"}, "Cart ref =
".$Carts->{$cart}[$num]);
$Carts->{$cart}[$num]{'quantity'} = $quantity;
#$Tag->log({file=>"/tmp/kil.log"}, "Cart ref2 =
".$Carts->{$cart}[$num]);
#next;
}
if(!$quantity){
# add this number to the list
# we will remve it later
push @remove_numbers,$num;
}
}
# now lets remove some of the products
foreach my $rm (@remove_numbers){
splice @{$Carts->{$cart}},$rm,1;
$CGI->{$cart.".numbers"} -= 1;
}
my $item_num = @{$Carts->{$cart}} ;
# if the cart has no items them remove the cart
if(! $item_num){
delete $Carts->{$cart};
# now we have to adjust the cart-loop and cart-dash scratch variables
my @new_carts;
foreach my $cart_loop (split(/\s/,$Scratch->{"cart-loop"})){
if($cart_loop ne $cart){
push @new_carts,$cart_loop;
}
}
my ($new_string,$dash_carts) ;
if (scalar(@new_carts) > 1){
$new_string = join(" ",@new_carts);
$dash_carts = join("_",@new_carts);
}
else{
$new_string = shift @new_carts ;
$dash_carts = $new_string ;
}
$Tag->set("cart-loop", $new_string);
$Tag->set("cart-dash", $dash_carts);
# now deal with mv_muzz_routes
my @new_routes;
foreach my $cart_loop (split(/\s/,$Scratch->{"mv_muzz_routes"})){
if($cart_loop ne $cart){
push @new_routes,$cart_loop;
}
}
$Tag->set("mv_muzz_routes", join(" ",@new_routes));
}
#$Tag->log({file=>"/tmp/kil.log"}, "Cart items = ".$item_num);
}
# ok now we have loop throught all the carts
# we want to ajust the values of mv_ip
# in each of the carts. The reason being.
# in removing the products from the arts that have
# a zero quantity we may have upset the
# ordering of the cart information.
foreach my $cart (@carts){
if(! exists $Carts->{$cart}){
next;
}
my $count = 0;
foreach $prod (@{$Carts->{$cart}}){
$prod{mv_ip} = $count ;
$count++ ;
}
}
return ;
[/perl]
it has worked for me from 4.0.4 to 4.6.1
--
____
\__/ Murray Gibbins murray@scotweb.ltd.uk
/ \ Programmer
_ \__/ _ ================================================
\\ || // Scotweb Limited, info@scotweb.ltd.uk
\\||// 13a Albert Terrace, http://www.scotweb.ltd.uk
\||/ Edinburgh EH10 5EA Tel: +44 (0) 131 270 82 33
|| Scotland. Europe. Fax: +44 (0) 7020 93 49 04