[ic] Change the price on the fly, without CommonAdjust

Ed LaFrance interchange-users@lists.akopia.com
Wed Jun 27 17:01:01 2001


At 10:02 AM 06/27/2001 -0700, you wrote:
>Hello list,
>
>I've been reading the documentation for CommonAdjust that was posted by Mike
>here:
>
>http://developer2.akopia.com/archive/interchange-users/2001/msg03850.html
>
>It appears that CommonAdjust is based off of values in the pricing table and
>fields in the product database.  However for the project that I'm working on
>does not seem to fit this mold.  I'll first explain the situation.
>
>The code I have now generates a case order form based on records both in the
>products table and support tables I have designed for the case modifiers.
>Each part of the case can be customized with a different anodized color.  If
>the user selects a color already in the list they are not charged extra for
>these colors.  However if they select 'Custom Color' they are charged $15.00
>for each additional color.  If they select Custom Color for 10 parts and the
>custom color they would like is the same for all 10 parts then they are only
>charged $15.00 (since the anodizing is done in a batch) not $150.00.  Each
>part is a modifier to the case (the case is one product sku) and each part
>also has a modifier for the color.
>
>I already have the code that determines the price of the case and what I
>would like to do is set the price of the case for that particular item in
>the cart.  All of the mailing lists items I looked through (516) talked
>about using CommonAdjust but in those case it was only one level of
>modifiers (size, color, etc..) and in this case it is two levels (a modifier
>of a modifier).  Is it possible to use perl to change the price for a
>certain cart item after it is added to the cart?  Is it possible to change
>the price before it's added to the cart?  If I change the price of the item
>will the other subtotal and total fields work properly?
>
>Thanks for your help!
>Ron Phipps

Ron -

Commonadjust is still the best entry point into the pricing scheme, in my 
opinion.  Something which is mentioned briefly in the docs, but not well 
illustrated, that that IC tags can be part of the CommonAdjust string, 
which opens the door to employing UserTags to figure pricing.  This is 
probably the most effective way of doing complex pricing, since you can 
evaluate just about any mixture of database and session data to arrive at a 
final price.  Mike Heins posted a very nice example a couple weeks ago - it 
didn't pop up in a search of the mail archives, but I kept a copy - here it 
is, out of context unfortunately, because I don't have the whole thread:


In this case, it is because the current item is available as the
variable $item, the current subtotal is available as $s, and the
current pricing quantity is available as $q.

So you can have a sub like:

UserTag my-adjust Routine <<EOS
sub {
         my $code = $item->{code};

         # Could read this from a DB
         my @look_at = qw/color size/;

         my $adjust = 0;
         foreach my $opt (@look_at) {
              my $opt_val = $item->{$opt}
                 or next;
              my $field_name = $opt . "_price";
              my $price_data = tag_data('pricing', $field_name, $code)
                 or next;

              # Works with XL=2, S=-1, L=.50 or the like
              my %price_hash = split /\s*[=,]\s*/, $price_data;
              next if $price_hash{$opt_val} == 0;
              $adjust += $price_hash{$opt_val};
         }
         return $adjust;
}
EOF

So there should be no trouble adding "[my-adjust]" as an atom to
CommonAdjust and doing your routines. (This particular one won't work
with percentages, but you could easily return a "10%" number from a
routine.)

 >
 > In order for this to work AFAIK, any UserTag would have to be able to plug
 > into the main pricing routines so that any arbitrary fields could make
 > changes to the price, correct? Is this a matter of adding a UserTag,
 > twiddling some hash values inside it, and adding an extra call in the
 > checkout stuff?

Nope. Your UserTag needs to return an atom like -10 or 25 or -8%, which
will adjust the price as a part of CommonAdjust.

-- 
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH  45013
phone +1.513.523.7621      <mheins@redhat.com>

This answer sponsored by the Society to End Lazy Windows Top-Quoting Style.
_______________________________________________
Interchange-users mailing list
Interchange-users@lists.akopia.com
http://lists.akopia.com/mailman/listinfo/interchange-users





===============================================================
New Media E.M.S.               Software Solutions for Business
463 Main St., Suite D          eCommerce | Consulting | Hosting
Placerville, CA  95667         edl@newmediaems.com
(530) 622-9421                 http://www.newmediaems.com
(866) 519-4680 Toll-Free       (530) 622-9426 Fax
===============================================================