[ic] Shipping calculation bug

Bruno Cantieni bruno at digi-land.com
Wed Aug 30 08:31:24 EDT 2006


 > -----Original Message-----
> From: interchange-users-bounces at icdevgroup.org 
> [mailto:interchange-users-bounces at icdevgroup.org] On Behalf 
> Of Bruno Cantieni
> Sent: August 28, 2006 6:50 PM
> To: interchange-users at icdevgroup.org
> Subject: [ic] Shipping calculation bug
> 
> Something looks buggy to me in the way additional shipping 
> calculations get
> handled.
> We have a shipmode that calls a usertag "padding" to 
> determine additional
> shipping charges and a usertag "drop_ship_internal_lookup" to 
> calculate the
> "raw" shipping charges.
> To make this work we have revisd Ship.pm to interpolate user 
> tags as e.g.:
> if (defined($o->{adder}) && $o->{adder} =~ /__\w+__|\[/);
> 
> The applicable lines in the shipping.asc would be as follows:
> 
> 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",'PriceDivide' =>
> "1",'ui_ship_type' => "weight",}
> upsg    UPS Ground      weight  0       999999  f 
> [drop_ship_internal_lookup
> mode=Ground]               {'PriceDivide' => "1",}
> 
> The problem we have is that while the 
> "drop_ship_internal_lookup" tag gets
> called and executes properly each and every time, the 
> "padding" tag gets
> called and executes at only arbitrary times, i.e. most of the time but
> sometimes not, leading to inacurate calculations.
> 
> I have looked all over the Ship.pm, Interpolate.pm and 
> Util.pm and I can not
> put my finger on why the tag would not get called properly 
> each and every
> time shipping needs to be calculated.
> I turned on ::logDebug() all over the place and got nothing 
> insightful so
> far.
> The padding tag looks essentially like this:
> 
> UserTag padding Order b zm m oz
> UserTag padding Routine <<EOR
> sub {
> 	my($b,$zm,$m,$oz) = @_;
> 	# $b  = 'base amount to charge' via b=2
> 	# $zm = 'zone map'              via zm='07928=4.5;33014=1.5'
> 	# $m  = '# of drop shipments'   via m=[scratch drop_ship]
> 	# $oz = 'origin zips'           via oz=[scratch origin_zips]
> 	::logDebug("Starting padding calcs:"); # Simply tells 
> me if/when the
> tag gets called :(
> 	return undef unless $zm;
> 	return undef unless $oz;
> 	$m ||= 1;
> 	my %pm =  split(/[=;]/, $zm);
> 	my $p = $b*$m;
> 	foreach my $k (keys %pm) {
> 		if ($oz =~ /$k/) {
> 			$p += $pm{$k};
> 		}
> 	}
> 	return $p;
> }
> EOR
> 
> If anybody has a clue as to why the "padding" tag does not 
> get called each
> time shipping needs to be calculated, I'd appreciate some feedback.
> Stumped,
> Bruno Cantieni
> 
Hi all,
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)?

Thanks,
Bruno Cantieni

###########################################
Digital Landscape - Cyboretum.com
Web Applications * Web Hosting * e-Commerce
http://www.digi-land.com
http://www.cyboretum.com
bruno at digi-land.com
Phone/Fax: 1+905.668.2255
Toll free: 1+877.668.2345
 




More information about the interchange-users mailing list