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

Ron Phipps interchange-users@interchange.redhat.com
Fri Apr 19 11:43:00 2002


> From: interchange-users-admin@interchange.redhat.com
[mailto:interchange-
> users-admin@interchange.redhat.com] On Behalf Of Stefan Hornburg
(Racke)
> 
> "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;
> 

Thanks Racke for another efficient and clean example.  As you can
probably tell I'm far from a Perl expert and I'm still learning the
ropes of using Perl's hashes and arrays.  In fact I had only touched
perl back in a college class for 1 quarter until I found Minivend.
Hopefully this time next year I'll have my bearings on Perl :)

Thanks a lot!
-Ron