[ic] Changing pricing based on any field

Mike Heins interchange-users@lists.akopia.com
Fri Jun 15 09:36:01 2001


Quoting Nathan Wiger (nate@nateware.com):
> I've used UserTags to solve several different problems, but I guess I'm
> confused how this could be used to tie into something as fundamental as
> pricing? Perhaps UserTags are more powerful than I understand and can
> override anything?

In this case, it is because the current item is available as the
variable $item, the current subtotal is available as $s, and the
current pricing quantity is available as $q.

So you can have a sub like:

UserTag my-adjust Routine <<EOS
sub {
	my $code = $item->{code};

	# Could read this from a DB
	my @look_at = qw/color size/;

	my $adjust = 0;
	foreach my $opt (@look_at) {
	     my $opt_val = $item->{$opt}
		or next;
	     my $field_name = $opt . "_price";
	     my $price_data = tag_data('pricing', $field_name, $code)
		or next;

	     # Works with XL=2, S=-1, L=.50 or the like
	     my %price_hash = split /\s*[=,]\s*/, $price_data;
	     next if $price_hash{$opt_val} == 0;
	     $adjust += $price_hash{$opt_val};
	}
	return $adjust;
}
EOF

So there should be no trouble adding "[my-adjust]" as an atom to
CommonAdjust and doing your routines. (This particular one won't work
with percentages, but you could easily return a "10%" number from a
routine.)

> 
> In order for this to work AFAIK, any UserTag would have to be able to plug
> into the main pricing routines so that any arbitrary fields could make
> changes to the price, correct? Is this a matter of adding a UserTag,
> twiddling some hash values inside it, and adding an extra call in the
> checkout stuff?

Nope. Your UserTag needs to return an atom like -10 or 25 or -8%, which
will adjust the price as a part of CommonAdjust.

-- 
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH  45013
phone +1.513.523.7621      <mheins@redhat.com>

This answer sponsored by the Society to End Lazy Windows Top-Quoting Style.