[interchange-cvs] interchange - ton modified lib/Vend/Ship.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Fri Feb 3 11:36:46 EST 2006


User:      ton
Date:      2006-02-03 16:36:46 GMT
Modified:  lib/Vend Ship.pm
Log:
	Added UPS support for countries ouside the US.

	In order to use this functionality one only needs
	to add the following two lines to a UPS shipping
	method in shipping.asc.

	zone_file	products/ship/zone_NL_international.txt
	country_prefix	1

	The zone file 'zone_NLinternational.txt' is TAB delimited and
	should contain entries like:

	low	high	ExpressPlus	Express	ExpressSaver	Standard	Expedited

	"Destination: Belgium (BE). 4-digit code"
	BE:0000	BE:9999	2	2	2	2	-

	"Destination: France (FR). 5-digit code"
	FR:2000	FR:2999	3	3	3	4	-
	FR:3000	FR:7999	3	4	4	5	-
	FR:8000	FR:8999	3	3	3	4	-
	FR:9000	FR:9999	3	4	4	5	-
	FR:1000	FR:1099	3	3	3	4	-

	The values in the postcode range should be prepended with the
	country code. Prepend FR: to postcodes for country France.

	There is no change to the rate tables.

Revision  Changes    Path
2.16      +28 -4     interchange/lib/Vend/Ship.pm


rev 2.16, prev_rev 2.15
Index: Ship.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Ship.pm,v
retrieving revision 2.15
retrieving revision 2.16
diff -u -r2.15 -r2.16
--- Ship.pm	3 Feb 2006 15:34:32 -0000	2.15
+++ Ship.pm	3 Feb 2006 16:36:45 -0000	2.16
@@ -1,6 +1,6 @@
 # Vend::Ship - Interchange shipping code
 # 
-# $Id: Ship.pm,v 2.15 2006/02/03 15:34:32 mheins Exp $
+# $Id: Ship.pm,v 2.16 2006/02/03 16:36:45 ton Exp $
 #
 # Copyright (C) 2002-2005 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -370,13 +370,15 @@
 				next;
 			}
 			my (@zone) = grep /\S/, split /[\r\n]+/, $ref->{zone_data};
-			shift @zone while @zone and $zone[0] !~ /^(Postal|Dest.*Z)/;
+			shift @zone while @zone and $zone[0] !~ /^(Postal|Dest.*Z|low)/;
 			if($zone[0] =~ /^Postal/) {
 				$zone[0] =~ s/,,/,/;
 				for(@zone[1 .. $#zone]) {
 					s/,/-/;
 				}
 			}
+			@zone = grep /\S/, @zone;
+			@zone = grep /^[^"]/, @zone;
 			if($zone[0] !~ /\t/) {
 				my $len = $ref->{str_length} || 3;
 				@zone = grep /\S/, @zone;
@@ -1120,7 +1122,21 @@
 
 	my $rawzip = $zip;
 
-	$zip = substr($zip, 0, ($zref->{str_length} || 3));
+	my $country;
+	if($opt->{country_prefix}) {
+		$country = $::Values->{country} || '';
+		$country = uc $country;
+		$country =~ s/\W+//g;
+		$country =~ m{^\w\w$} 
+			or do {
+				logDebug('Country code not present with country_prefix');
+				return undef;
+			};
+		$zip = $country . ":" . $zip;
+	}
+	else {
+		$zip = substr($zip, 0, ($zref->{str_length} || 3));
+	}
 
 	@fieldnames = split /\t/, $zdata->[0];
 	for($i = 2; $i < @fieldnames; $i++) {
@@ -1130,8 +1146,7 @@
 	}
 
 	unless (defined $point) {
-		logError("Zone '%s' lookup failed, type '%s' not found", $code, $type)
-			unless $zref->{quiet};
+		logError("Zone '$code' lookup failed, type '$type' not found");
 		return undef;
 	}
 
@@ -1146,8 +1161,17 @@
 	}
 
 #::logDebug("tag_ups looking in zone data.");
+	my $zip_trimmed;
 	for(@{$zdata}[1..$#{$zdata}]) {
 		@data = split /\t/, $_;
+
+                unless($zip_trimmed) {
+			if ( $data[0] =~ m{^(([A-Z][A-Z]):)?(\w+)} and $2 eq $country ) {
+				$zip = substr($zip, 0, length($1.$3));
+				$zip_trimmed++;
+			}
+		}		
+
 		next unless ($zip ge $data[0] and $zip le $data[1]);
 		$zone = $data[$point];
 		$eas_zone = $data[$eas_point] if defined $eas_point;








More information about the interchange-cvs mailing list