[ic] Shipping calculation bug

Mike Heins mike at perusion.com
Wed Aug 30 11:29:19 EDT 2006


Quoting Bruno Cantieni (bruno at digi-land.com):
> After spending a couple of more days codewalking (5.2.0) Ship.pm,
> Interpolate.pm, Util.pm, Parse.pm and Parser.pm, I'm following up with
> something that puzzles me and I'm hoping someone will be able to enlighten
> me.
> 
> Line 556 of Ship.pm:
> @lines = grep $_->[0] =~ /^$mode/, @{$Vend::Cfg->{Shipping_line}};
> 
> If I ::logDebug("Shipping_line: " .
> uneval(\@{$Vend::Cfg->{Shipping_line}}));
> I expect to get something like this for my upsg method with my padding tag
> in it:
> Vend::Ship:debug: Shipping_line: [
>   [
>     'upsg',
>     'UPS Ground',
>     'weight',
>     '0',
>     '0',
>     'e Nothing to ship!',
>     '',
>     {
>       'adder' => '[padding b=\'0\' zm=\'07928=4.5;33014=1.5\' m=\'[scratch
> drop_ship]\' oz=\'[scratch origin_zips]\' interpolate=\'1\']',
>       'ups' => '0',
>       'ui_ship_type' => 'weight',
>       'PriceDivide' => '1'
>     }
>   ],
>   [
>     'upsg',
>     'UPS Ground',
>     'weight',
>     '0',
>     '999999',
>     'f [drop_ship_internal_lookup mode=Ground]',
>     '',
>     {
>       'PriceDivide' => '1'
>     }
>   ],
> etc.....
> 
> Often, however, I actually get:
> Vend::Ship:debug: Shipping_line: [
>   [
>     'upsg',
>     'UPS Ground',
>     'weight',
>     '0',
>     0,
>     'e Nothing to ship!',
>     '',
>     {
>       'adder' => '1.5',
>       'ups' => '0',
>       'ui_ship_type' => 'weight',
>       'PriceDivide' => '1'
>     }
>   ],
>   [
>     'upsg',
>     'UPS Ground',
>     'weight',
>     0,
>     999999,
>     'f [drop_ship_internal_lookup mode=Ground]',
>     '',
>     {
>       'adder' => '1.5',
>       'ups' => '0',
>       'ui_ship_type' => 'weight',
>       'PriceDivide' => '1'
>     }
>   ],
> etc.....
> As you can see, I get an interpolated value for 'adder' instead of the "raw"
> padding tag.
> This is intermittent and inconsistent.
> Having an already interpolated and possibly stale value in 'adder' means
> 'adder' does not get re-interpolated (e.g. on reselecting a different
> shipping method on checkout) and I end up with faulty shipping costs!
> I can not figure out how this even makes it into the hash.
> As far as I can tell, $Vend::Cfg->{Shipping_line} only ever gets built on
> restarts or reconfigs, so how or where does 'adder' end up with an
> interpolated value (the 'f [drop_ship...' never does)?

Try this patch to Util.pm:

Index: Util.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Util.pm,v
retrieving revision 2.95
diff -u -r2.95 Util.pm
--- Util.pm	16 Aug 2006 13:34:09 -0000	2.95
+++ Util.pm	30 Aug 2006 15:28:44 -0000
@@ -892,13 +892,14 @@
 sub get_option_hash {
 	my $string = shift;
 	my $merge = shift;
-	if (ref $string) {
-		return $string unless ref $merge;
+	if (ref $string eq 'HASH') {
+		my $ref = %$string;
+		return $ref unless ref $merge;
 		for(keys %{$merge}) {
-			$string->{$_} = $merge->{$_}
-				unless defined $string->{$_};
+			$ref->{$_} = $merge->{$_}
+				unless defined $ref->{$_};
 		}
-		return $string;
+		return $ref;
 	}
 	return {} unless $string and $string =~ /\S/;
 	$string =~ s/^\s+//;

I believe the value of the option is getting modified in place,
and that this should solve that.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

Being against torture ought to be sort of a bipartisan thing.
-- Karl Lehenbauer


More information about the interchange-users mailing list