[ic] shipping.asc and formulas (adder or at_least field)
Kevin Walsh
kevin at cursor.biz
Fri Oct 28 15:28:07 EDT 2005
Randy Just [randyjust at justcomp.com] wrote:
> I am trying to use formulas in fields such as at_least or adder and seem
> to be striking out. In the code below I am
> attempting to change the minimum shipping charge for the user based on
> the value of the merchandise they
> are ordering.
>
> That being if the item total is $8.99 or less, then the minimum shipping
> charge will be $4.99. Over $8.99 and it goes to $5.49.
>
> at_least [calc interpolate=1]$tmp1=([item-list][item_field
> price]*[item_quantity]+[/item-list]0);if($tmp1>8.99){$tmp2=5.49}else{$tmp2=4.99};return
> $tmp2;[/calc]
>
> I have entered the info above into shipping.asc and while the system
> doesn't error out, it seems to be "ignoring" the calculation.
>
> Alternatively, if I can add a formula to the adder field to add $1.00 if
> the merchandise total is above $8.99, that would
> be OK too.
>
I don't believe that the "min_cost" field interpolates ICML tags at
all, at the moment. There may be a good reason for this, or perhaps
I'm just reading the code wrong.
Assuming I'm correct, the following patch should add the capability.
I say "should" because I haven't tested it at all. :-)
----------------------------------------------------------------------
--- Ship.pm 9 Jun 2005 18:43:58 -0000 2.13
+++ Ship.pm 28 Oct 2005 19:18:03 -0000
@@ -694,6 +694,10 @@
$o = get_option_hash($row->[OPT], $o)
if $row->[OPT];
+
+ $o->{at_least} = interpolate_html($o->{at_least})
+ if (defined($o->{at_least}) && $o->{at_least} =~ /__\w+__|\[/);
+
# unless field begins with 'x' or 'f', straight cost is returned
# - otherwise the quantity is multiplied by the cost or a formula
# is applied
----------------------------------------------------------------------
If the above works, and is deemed acceptable, then the same code could
also be applied to the "adder" value.
By the way, there's no reason to use "interpolate=1" in your [calc]
tag. [calc] interpolates by default. [calcn] is the one that doesn't.
Also, if you're going to use Perl then you might as well loop through
the @$Items array instead of calling the [item-list] tag.
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin at cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
More information about the interchange-users
mailing list