[ic] Re: CommonAdjust calculated price

Mike Heins interchange-users@icdevgroup.org
Sat Nov 9 00:58:00 2002


Quoting Daniel A. Shockley (danielashockley@yahoo.com):
> >  > I can see how to have CommonAdjust lookup a static price for an Option,
> >>  but the price is based on the LENGTH of what was typed in, not on an
> >>  option chosen from a Select popup. I can calculate the additional price
> >>  using perl, of course, but how do I get CommonAdjust to see that price?
> >
> >CommonAdjust [calc_price]
> >
> >where [calc-price] is a UserTag which calculates the price for
> >a given item and its quantity, both found in Vend::Interpolate::item.
> >
> >Search the archives for a sample implementation of calc_price.
> >
> >Bye
> >      Racke
> 
> Well, I've worked at this for a while, and I'm getting stuck.
> 
> I've got this in my catalog.cfg - I had the same problem with 
> [insc_price] in CommonAdjust, as Racke advised:
> 
> 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

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Being against torture ought to be sort of a bipartisan thing.
-- Karl Lehenbauer