[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Shopping Cart MV 4.04
****** message to minivend-users from Murray Gibbins <murray@scotweb.ltd.uk> ******
Humberto T Reyes wrote:
> Murray,
>
> Thank you for letting me know it is as simple as pie--care to provide more
> info? I want to run a query for a group of items and place them in the
> shopping cart.
>
Here is something simular to what you want, please feel free to adapt to your
needs...
[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){
# the numbers that are attached to the
# cart name.
# These numbers will relate to the
# 'mv_ip' numbers
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};
$Carts->{$cart}[$num]{'quantity'} = $quantity;
if($quantity == 0){
# ok so we are going to have to run over the cart and remove the
# product associated with the zero quantity
# remove the product.
splice @{$Carts->{$cart}},$num,1 ;
}
}
}
# 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 hte products from the arts that have
# a zero quantity we may have upset the
# ordering of the cart information.
foreach my $cart (@carts){
my $count = 0;
foreach $prod (@{$Carts->{$cart}}){
$prod{mv_ip} = $count ;
$count++ ;
}
}
return ;
[/perl]
or ....
[loop args="[scratch cart-loop]" prefix=what_the_hell]
[set what_the_hell-code][what_the_hell-code][/set]
[perl tables="[what_the_hell-code]_thekeys [what_the_hell-code]_fields [what_the
_hell-code]"]
# This code deals withthe problem of
# minvend giving the atributes of products
# incremental numericla "form-name" values
# This stops two products in two different
# carts having independant product atributes.
# To solve this the new form-names have the
# name of the cart prepended to it.
# This code then deals with the
# parseing of this new form-name.
# It takes the values and puts them
# into the correct carts and products
my $cart = $Scratch->{'what_the_hell-code'};
# now we need the mv_ip number
my $product_db_ref = $Db{$cart} ;
foreach $product_hash_ref (@{$Carts->{$cart}}){
my $db_cart_thekeys = $Db{$cart."_thekeys"};
# we have the cart, so ..
# now we now that if we have the choice
# a choice must be there.
# This means that the procudt db must
# have an entry for this field into
# ohter wise we don't give a choice.
my $product_db_ref = $Db{$cart} ;
foreach $key (split(/\s/,($db_cart_thekeys->field("fields","keys")))){
my $cart_field = $cart."_fields" ;
my $db_cart_field = $Db{$cart_field};
if($db_cart_field->field($key,"basket")){
# ok if we are here then we have an posible atribute
# of the product.
if($db_cart_field->field($key,"choice")){
# if we are here then we know that this attribute
# is one that can be posibly set for the product
# we have the cart, so ..
if( (defined $product_db_ref->test_column($key)) && (defined $pr
oduct_db_ref->field($product_hash_ref->{code},$key)) && $product_db_ref->field($
product_hash_ref->{code},$key) ){
my $mv_ip = $product_hash_ref->{mv_ip} ;
my $cgi_thing = $cart."_".$key.$mv_ip ;
my $cgi_val = $CGI->{$cart."_".$key.$mv_ip} ;
if((defined $cgi_val) && ($cgi_val)){
$product_hash_ref->{$key} = $cgi_val;
}
}
}
}
select(undef,undef,undef,0.0001);
}
}
return ;
[/perl]
[/loop]
Simple manipulation of the internal minivend db's which are stored as
Data::Dumped hash and nested array statements. :-P
--
____
\__/ 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
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list