Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date ][Interchange by thread ]

RE: [ic] Can GlobalSub override item_price routine?



> 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.

UserTag user-price Order
UserTag user-price Interpolate 1
UserTag user-price Routine <<EOR
sub {
	my $username= $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=$Scratch->{priceband};
	}

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

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

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

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

	return $$ary[0][0];
}
EOR

Search for: Match: Format: Sort by: