[ic] UserTag to return correct price for a given quantity using new pricing table

Stefan Hornburg Racke interchange-users@interchange.redhat.com
Fri Apr 19 07:57:01 2002


"Ron Phipps" <rphipps@reliant-solutions.com> writes:


[...]

> 
> The tag:
> 
> UserTag lookup-qty-pricing Order table
> UserTag lookup-qty-pricing Routine <<EOR
> sub {
> 		my ($price_db) = @_;
> 		my $code = $item->{code};
> 		my $qty = $item->{quantity};
> 		
> 		my $db = Vend::Data::database_exists_ref($price_db);
> 		my $dbh = $db->[$Vend::Table::DBI::DBI];
> 		my $sql = "SELECT price FROM " . $price_db . " WHERE
> sku='" . $code . "' AND quantity <= " . $qty . " ORDER BY quantity
> DESC";
> 		my $sth = $dbh->prepare($sql);
> 		$sth->execute();
> 		
> 		if ($sth) {
>          		my $sql_results = $sth->fetchrow_hashref();
>          		my $price = $$sql_results{price};
>          		
>          		if ($price eq '') {
>          			return 0;
>          		} else {
>          			return $price;
>          		}
> 		}
> 		else {
>          		return 0;
> 		}
> }
> EOR

That's way too much code for such a easy task.

$set = $Db{pricing}->query($sql);
if (@$set) {
   $price = $set->[0]->[0];
   return $price if $price ne '';
}

return 0;


Ciao
        Racke

-- 
Think of it !

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