Gossamer Forum
Home : Products : Gossamer Links : Discussions :

question about a new subroutine

Quote Reply
question about a new subroutine
Hi,
I created a subroutine to return different 'prices' for every link and I wanted to ask if this might become a processor problem or if someone has another idea to handle this. Would be nice if you could take a look at the code.
Any comments are appreciated.


sub price {
my ($sth,$dbh);
my (@ary);
my $customer = $_[1] || "standard"; # the individual status of each customer bronze,silver,gold
my $customer_factor = undef; # the factor of the customer dependant on the status
my $price = $_[2]; # the price from the database
my $price_discount = $_[3] || 1; # the class depenadant on the product
my $price_currency = $_[4] || "EUR_net"; # the currency factor e.g. 1.95583 for EURO
# the basic customer gets the regular price from the database
if ( $customer eq 'standard') { $customer_factor = 1; }
# if the customer is not standard we try to find his status in the prices database
# and return the customer_factor if we do not find anything we handle him like standard
else {
$dbh = DBI->connect ($SHOP{dsn}, $SHOP{user_name}, $SHOP{password}, { RaiseError => 1 });
$sth = $dbh->prepare (qq{SELECT * FROM shop_Prices WHERE Customer LIKE '$customer'} );
$sth->execute ();
while (@ary = $sth->fetchrow_array ()) { $customer_factor = $ary[$price_discount]; }
$sth->finish ();
$dbh->disconnect ();
unless ($customer_factor) { $customer_factor = 1 };
}
my $return_price = undef;
# now we can calculate the price and return the result
if ($price_currency eq "DM_net") {$return_price = sprintf ("%0.2f",$customer_factor * $price * 1.95583);}
elsif ($price_currency eq "EUR_net") {$return_price = sprintf ("%0.2f",$customer_factor * $price);}
elsif ($price_currency eq "DM_gros") {$return_price = sprintf ("%0.2f",1.95583 * sprintf ("%0.2f",$customer_factor * 1.16 * $price));}
elsif ($price_currency eq "EUR_gros") {$return_price = sprintf ("%0.2f",$customer_factor * 1.16 * $price);}
return "$return_price";
}


The routine is called with:
<%Shop::price("$Class","$Price","$Discount","DM_gros")%>

Cheers
Niko


http://www.master-productions.com
Subject Author Views Date
Thread question about a new subroutine el noe 1190 Jul 2, 2001, 11:52 PM
Thread Re: question about a new subroutine
Stealth 1131 Jul 3, 2001, 7:28 AM
Post Re: question about a new subroutine
el noe 1126 Jul 3, 2001, 7:43 AM