[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Re: CommonAdjust calculated price
Mike Heins [mike@perusion.com] wrote:
> Quoting Daniel A. Shockley (danielashockley@yahoo.com):
> >
> > PriceField 0
> > CommonAdjust "& $Tag->insc_price($item->{code}, $item->{quantity},
> > $item->{inscription})"
> >
> > UserTag insc_price Interpolate
> > UserTag insc_price Order code quantity inscription
> > UserTag insc_price Routine <<EOR
> > sub {
> > my ($sku, $quantity, $inscription) = @_;
> >
> > my $price = $Tag->data( {
> > table => 'products',
> > field => 'price',
> > key => $sku,
> > });
> >
> > return $quantity*($price+ $quantity*1.50*length($inscription));
> > }
> > EOR
> >
> > If I put [insc_price code="[item-sku]" quantity="[item-quantity]"
> > inscription="[item-modifier inscription]"] in an HTML page, it
> > displays the proper amount in that tag, but it doesn't seem to get
> > through to CommonAdjust.
> >
> > Any evidence of why in the code I posted?
> >
> I don't know if $item is in scope in that code, quite frankly. But
> it would be in the usertag, so just do:
>
> CommonAdjust [insc-price]
>
> UserTag insc_price Interpolate
> UserTag insc_price Order code quantity inscription
> UserTag insc_price Routine <<EOR
> sub {
> my ($sku, $quantity, $inscription) = @_;
>
> $sku ||= $item->{code};
> $quantity ||= $item->{quantity};
> $inscription ||= $item->{inscription};
>
> my $price = $Tag->data( {
> table => 'products',
> field => 'price',
> key => $sku,
> });
>
> return $quantity*($price + $quantity * 1.50 * length($inscription));
> }
> EOR
>
As a side note, you may want to strip any leading/trailing whitespace
before calling "length($inscription)" to calculate the price.
You should also think about making the "1.50" value configurable,
perhaps using a Variable in catalog.cfg or your variable table.
It could be difficult to remember where that price is set if you
wanted to change it in the future. I assume the 1.50 price is fixed,
regardless of the item being inscribed.
One last point - remove that "Interpolate" setting - you don't need it.
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin@cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/