[ic] Challenging Pricing Problem

Stefan Hornburg interchange-users@icdevgroup.org
Wed Apr 30 04:30:01 2003


On Tue, 29 Apr 2003 23:08:03 -0500
"Andy Melichar" <skip@skipmartin.com> wrote:

> Doug,
> 
> I never got around to thanking you for this code. I am just now in the
> process of attempting to implement it. After adding it to my catalog.cfg
> file and making some changes (there were some variables that were not
> consistent and causing an error when I restarted interchange) I am
> running into a slight problem - as long as the line
> 	CommonAdjust [calc_price]
> Is in the catalog, all of the prices in my catalog show up as $0.00
> If I comment out the commentadjust line (thus not running the routine)
> all of my prices go back to normal.
> 
> Any ideas? I have been troubleshooting this for over an hour, and
> honestly I just don't know what I'm doing. 
> 
> Here is the modified code:
> 
> #=======================================================================
> ===#
> #Adjust Prices for Steak Salt
> #=======================================================================
> ===#
> 
> UserTag calc_price Order sku quantity
> UserTag calc_price Routine <<EOR
> sub {
>     my ($sku, $quantity);
>     if ($Vend::Interpolate::item) {
>        $sku = $Vend::Interpolate::item->{code};
>        $quantity = $Vend::Interpolate::item->{quantity};
>     } else {
>        ($sku, $quantity) = @_;
>     }
> 
>     for my $dependent_sku ("FL-4757", "NY-4761") {
>        if ($sku == $dependent_sku  && $quantity > 0) {
>           $Scratch->{discounted_items} .= ", SS-4772";
>        }
>     }
> 
>     my $discount = 1;
>     for my $discounted_sku (split /, /, $Scratch->{discounted_items}) {
>        if ($sku == $discounted_sku) {
>           $discount = "0.89979959919839679358717434869739";
>           last;
>        }
>     }
> 
>     sprintf ("%.2f", $Vend::Interpolate::item->{price} * $discount); 
> }
> EOR
> 
> CommonAdjust    [calc_price]

I think the problem is that $Vend::Interpolate::item->{price} isn't set
at this point. You need a lookup from the database where the price
is stored, e.g.

$Tag->perl({tables => 'products'});
$Tag->field('price', $sku);

Ciao
         Racke