[ic] Challenging Pricing Problem

Doug Alcorn interchange-users@icdevgroup.org
Tue Apr 15 19:26:01 2003


"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