Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] Perl loop



******    message to minivend-users from Murray Gibbins <Murray@scotweb.ltd.uk>     ******

Mike Heins wrote:
> 
> ******    message to minivend-users from Mike Heins <mikeh@minivend.com>     ******

I wrote this to get around the problem of not being able to dymamically tell
perl what tables it can use.

[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 sttribute
                # 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]


I think I was feverish when I did it though ;-)


-- 
  ____
  \__/    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


Search for: Match: Format: Sort by: