[ic] Shipping from multiple origins/zones
Bruno Cantieni
bruno at digi-land.com
Thu Jul 20 08:15:24 EDT 2006
Based on a collection of posts and code snippets of a similar nature, I have
cooked up a usertag to handle drop shipping from multiple origins as
follows:
(FYI, we are running on IC 5.2.0.)
# Drop ship items from various locations to a single address
# Uses UPS www lookup
UserTag drop_ship Order mode zip
UserTag drop_ship Routine <<EOR
sub {
my($mode,$zip) = @_;
my $country;
$zip = $::Values->{$::Variable->{UPS_POSTCODE_FIELD}} if !$zip;
$country = $::Values->{$::Variable->{UPS_COUNTRY_FIELD}} if
!$country;
my $total = 0;
my %origins;
for (@$Items) { # Combine origins to minimize ups-queries
$origins{$_->{origin}} += ($_->{weight}*$_->{quantity});
}
for (keys %origins) {
$total += $Tag->ups_query( {
mode => $mode,
zip => $zip,
country => $country,
weight => $origins{$_},
origin => $_
} );
}
return $total;
}
EOR
The tag is then called as per e.g.:
..
upsg UPS Ground weight 0 999999 f [drop_ship mode=GNDCOM]
{'PriceDivide' => "1",}
..
While this works 9 out of 10 times, we do get bum results occasionally and
as far as I' can tell, this is probably due to connection failures or
connection time-outs to the UPS website.
I am now trying to switch this code to use internal lookup tables instead.
I have every single zone chart installed and where necessary symlinked them
to account for UPS combining some zones (e.g. for 018-99 you'd actually use
017.csv).
I have now cooked up the following:
# Drop ship items from various locations to a single address
# Uses UPS internal lookup tables with fall back to www lookup
UserTag drop_ship_internal_lookup Order mode zip
UserTag drop_ship_internal_lookup Routine <<EOR
sub {
my($mode,$zip) = @_;
my ($weight,$zone,$country);
my $OK = 1;
$zip = $::Values->{$::Variable->{UPS_POSTCODE_FIELD}} if !$zip;
$country = $::Values->{$::Variable->{UPS_COUNTRY_FIELD}} if
!$country;
my $total = 0;
my %origins;
for (@$Items) { # Combine origins to minimize ups-queries
$origins{$_->{origin}} += ($_->{weight}*$_->{quantity});
}
for (keys %origins) {
$weight = $origins{$_};
$zone = substr $_, 0, 3;
$total += Vend::Ship::tag_ups($mode, $zip, $weight ,$zone);
# Fallback to www lookup if internal lookup fails
if ($total < 1){
$OK=0;
}
}
# Fallback to www lookup if internal lookup fails
if (!$OK){
$total = $Tag->drop_ship_www_lookup($mode,$zip); # tag
drop_ship_www_lookup is identiacal to tag drop_ship above
}
return $total;
}
EOR
This fails miserably with e.g.:
Shipping '018' lookup called, no zone defined
Shipping '079' lookup called, no zone defined
Looking at the code in Ship.pm which is the cause of this:
unless (ref $Vend::Cfg->{Shipping_zone}{$code}) {
logError("Shipping '%s' lookup called, no zone defined",
$code);
return undef;
}
I can see why it wouldn't get past this, the question is how can I get this
to actually work?
Am I just barking up the wrong tree here (i.e. there's a better way and I
don't see it).
Any suggestions appreciated.
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