[ic] Challenging Pricing Problem

Andy Melichar interchange-users@icdevgroup.org
Wed Apr 30 00:07:00 2003


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]




Thanks,
Andy Melichar
Rebel2 Studios



----------------------------------------------------
This mailbox protected from junk email by Matador
from MailFrontier, Inc. http://info.mailfrontier.com

-----Original Message-----
From: interchange-users-admin@icdevgroup.org
[mailto:interchange-users-admin@icdevgroup.org] On Behalf Of Doug Alcorn
Sent: Tuesday, April 15, 2003 6:25 PM
To: interchange-users@icdevgroup.org
Subject: Re: [ic] Challenging Pricing Problem

"Andy Melichar" <skip@skipmartin.com> writes:

> My customer has requested that I discount a product based off of the
> purchase of other products.
>
> I am clueless as to handle this type of discount. Has anyone done this
> before? Is there functionality already built into interchange that
would
> help me with this?

You're right.  This is a complex interaction, but not impossible.
What I would do is define a CommonAdjust that used a user tag.  The
UserTag accepts the sku and quantity.  You could do something that
said if sku is one of my special skus and quanity is one of my special
quanities then set discounted items.  The discounted items would be a
global list of items that received the specified discount.  At the end
of the UserTag, check if the sku is one of the discounted items and
apply the discount.  This is what you'd put in your catalog.cfg:

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 ("steak cut1", "steak cut2", "steak cut3",
    "etc") {
       if ($sku == $dependent_sku  && $quanity > 8) {
          $Scratch->{discounted_items} .= ", seasoning sku";
       }
    }

    my $discount = 1;
    for my $discounted_skus (split /, /, $Scratch->{discounted_items}) {
       if ($sku == $discounted_sku) {
          $discount = "some discount";
          last;
       }
    }

    sprintf ("%.2f", $Vend::Interpolate::item->{price} * $discount);
}
EOR

CommonAdjust [calc_price]

I haven't tested this.  In fact, I just typed it into this email
message.  You could obviously pull the list of "steak cutN" skus from
a special field in the database along with the discount amount and
minimum quantity; but, I'll leave that as an exercise for the reader.
-- 
 (__) Doug Alcorn - Unix/Linux/Web Developing
 oo / PGP 02B3 1E26 BCF2 9AAF 93F1  61D7 450C B264 3E63 D543
 |_/  mailto:doug@lathi.net http://www.lathi.net
      mailto:tarpit@lathi.net is a spam trap
_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users