[ic] Many to many price schema

Stefan Hornburg Racke interchange-users@lists.akopia.com
Fri May 11 10:37:00 2001


"Renato Enea" <renea@enter.it> writes:

> Hi again...i modified your routine according to my database structure:
> 
> UserTag calc_price Order code quantity
> UserTag calc_price Routine <<EOF
> sub {
>     my ($code, $quantity);
> 
> if ($Vend::Interpolate::item) {
> $code = $Vend::Interpolate::item->{code};
> $quantity = $Vend::Interpolate::item->{quantity};
> } else {
> ($code, $quantity) = @_;
>     }
> 
> # sanity check
> if ($code !~ /^\d+$/ || $quantity !~ /^\d+$/) {
> Log ("Wrong input for calc_price: CODE $code QUANTITY $quantity");
>         return;
>     }
>  my $db = Vend::Data::database_exists_ref('products');
>  my $keys = $db->query ("select price from prezzi where sku='$code' and nome
> = '$Vend::Session->{username}' and min<='$quantity' and max>='$quantity'");
> my $price;
> 
> if (@$keys) {
> # fallback price
> $price = $keys->[0]->[0];
> # check for appropriate price
> #for (my $i = 0; $i < @$keys; $i++) {
> #if ($quantity > $keys->[$i]->[1]) {
> #$price = $keys->[$i]->[0];
> #}
> #}
> }
> else {
>  my $keys = $db->query ("select price from prezzi where sku='$code' and nome
> is null and min<='$quantity' and max>='$quantity'");
>  $price = $keys->[0]->[0];
> }
> 
> 
> }
> EOF
> 
> CommonAdjust [calc_price]
> 
> and using the tag:
> 
> [calc_price code="405153283" quantity="1"]
> 
> works well...
> 
> the problem is now that the tag [item-price] does not show the correct prize
> and ordering the product the basket does not show the correct price.
> How can i do to show always the prize calculated by the routine ??

Hmm, maybe this works only with IC 4.7.x. Check if you get the correct
code and quantity into calc_price and look for the SQL statements
in your database logs.

Maybe you need [perl tables="prezzi"][/perl] on top of your basket
page.

Bye
        Racke

-- 
Master of Swiss Web 2001: http://www.zweifel.ch/

For projects and other business stuff please refer to COBOLT NetServices
(URL: http://www.cobolt.net; Email: info@cobolt.net; Phone: 0041-1-3884400)