[ic] Can GlobalSub override item_price routine?

Jonathan Clark jonc@webmaint.com
Mon, 5 Feb 2001 20:27:48 -0000


This is a multi-part message in MIME format.

------=_NextPart_000_0004_01C08FB2.1AB0A9F0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

> Is it possible to override the item_price routine in MV?
> (I would rather do that than hack the IC code)
>
> Can anyone give me a simple example of always returning a
> price of $1.23?
>
> Thanks.

The simple answer is yes you can override it.

You do this by specifying a custom usertag and then altering the default
CommonAdjust setting.

I use:

CommonAdjust   [user-price] ;products:price

Which means return user-price if it exists, otherwise return the price from
the products file.

To return $1.23 you define a usertag:

UserTag user-price Routine <<EOR
sub {
return 1.23
}

and put it in catalog.cfg. then restart your ic server.

I use a custom tag to return pricing based upon a customer price, or price
band price (see attached usertags) The second tag is used to allow
formatting changes if the customer has been given a special price. (probably
not the best perl, but it works.)


good luck!

Jonathan
Webmaint.


------=_NextPart_000_0004_01C08FB2.1AB0A9F0
Content-Type: text/plain;
	name="user-price.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="user-price.txt"

UserTag user-price Order
UserTag user-price Interpolate 1
UserTag user-price Routine <<EOR
sub {
	my $username=3D $Session->{username} || 'nouser';
	if ($username eq 'nouser') {
#		::logError("user not logged in for price");
		return undef;}

# get the user's price break (A,B,C)...
	my $band;
	if ($Scratch->{priceband} ne '0'){
		$band=3D$Scratch->{priceband};
	}

	my $code =3D $Vend::Interpolate::item->{code};
	my $qty =3D $Vend::Interpolate::item->{quantity};
	my @qtybreaks =3D (1,5,10,20);
	my $level;
	my $field;

# decide which price break to use...
	foreach $level ( @qtybreaks ) {
		last if ($qty < $level);
		$field =3D "q$level";
	}

	my $opt =3D { sql =3D> "select $field from custpricing where =
sku=3D'$code' and username=3D'$username'",
			};
	my $db =3D $Vend::Database{custpricing} ;
	my $ary=3D $db->query($opt, '[sql-code]');
	if(! ref $ary) {
		::logError("Could not make custom price item query for item=3D$code, =
user=3D$username, quantity=3D$qty, field=3D$field");
		return undef;
=09
	}

	# if there is no user pricing check for band...
	if ((!$$ary[0][0]) && $band){
		my $opt =3D { sql =3D> "select $field from custpricing where =
sku=3D'$code' and username=3D'$band'",
			};
		$ary=3D $db->query($opt, '[sql-code]');
		if(! ref $ary) {
			return undef;
			::logError("Could not make custom price item query for item=3D$code, =
user=3D$username, quantity=3D$qty, field=3D$field");
		}
	}

	return $$ary[0][0];
}
EOR
------=_NextPart_000_0004_01C08FB2.1AB0A9F0--