[ic] how to calculate item-subtotal by the item price *and* packingunit

Kevin Walsh interchange-users@icdevgroup.org
Fri Aug 16 05:30:04 2002


> >>I've the item price and the quantity. If 1 quantity of an item is in the 
> >>basket, the item-subtotal has to dispay the price like
> >>
> >>1 quantity * item-prive * packing unit (from the field unit)
> >>
> >>For example a cake of soap cost 0.50 $. In the basket, it has to displays as
> >>
> >>sku  description    Qt.(Unit)  price   unit   item total
> >>1234 soap           1          0.50 $  72     36.00 $
> >>
> >>Can I use CommonAdjust to calculate the item total with
> >>
> >>price * quantity + field unit
> >>
> >>? My customer export his products table from his software and is not 
> >>able to set the price with 36.00$ instead of 0.50 $.
> >>
> > ...
> >
> > Just a thought, before you start creating a custom UserTag for use in
> > your CommonAdjust, which is the answer to your question, by the way.
> >
> Hmmm...I believe, it is easer to create an usertag, which call the carts 
> and change the values of [item-subtotal].
> 
> For example
> 
> ########
> # change the item-subtoal
> #
> #
> UserTag myitemsubtotal Interpolate 1
> UserTag myitemsubtotal Routine <<EOF
> sub {
> package Vend::Interpolate;
> my $cart;
> my $cart = $Vend::Items;
> my $code;
> my $price;
> my $unit;
> my $db = 'products';
> my $field = 'unit';
> my $qt;
> my $itemsubtotal;
> foreach my $item (@$cart){
>     $code = $item->{code};
>     $unit = Vend::Interpolate::tag_data($db, $field, $code);
>     $qt =  $item->{quantity} * $unit;
>     $price = $item->{price};
>     $itemsubtotal = $price * $qt;
>     $item->{subtotal} = $itemsubtotal;
>     }
> return '';
> }
> 
> and call it as [myitemsubtotal] at the top of the basket, checkout, 
> receipt, etc. pages.
> I'm unsure, if $item->{subtotal} is the right variable to set.
> 
> What do you think?
> 
That would not change the value returned by [item-subtotal],
although you could use [item-modifier subtotal] to read your new
'subtotal' hash key.

You could also modify your UserTag for use with the [assign] tag,
to override the value returned by [subtotal].  Your tag could do what
it does now, and then return a subtotal for assignment, or do the
assignment itself.

I still think the best way would be for you to create a UserTag
for use with CommonAdjust; It's just more 'supported' than any
other method you might think of.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/