Have the USPS shipping driver accept ZIP+4, even if USPS doesn't.

This commit is contained in:
Colin Kuskie 2009-11-28 19:23:35 -08:00
parent ddf3fa108f
commit cc0cc0ba64
3 changed files with 58 additions and 4 deletions

View file

@ -1,5 +1,6 @@
7.8.7
- fixed #11278: Wrong test for Template::Toolkit in testEnvironment.pl
- fixed #11282: USPS Shipping Driver does not accept ZIP+4
7.8.6
- fixed #11250: i18n Asset_EMSSubmissionForm::delete created items label help

View file

@ -54,9 +54,12 @@ sub buildXML {
$xmlTop->{Package} = [];
##Do a request for each package.
my $packageIndex;
my $shipType = $self->get('shipType');
my $service = $shipType eq 'PRIORITY VARIABLE' ? 'PRIORITY'
: $shipType;
my $shipType = $self->get('shipType');
my $service = $shipType eq 'PRIORITY VARIABLE'
? 'PRIORITY'
: $shipType;
my $sourceZip = $self->get('sourceZip');
$sourceZip =~ s/^(\d{5}).*$/$1/;
PACKAGE: for(my $packageIndex = 0; $packageIndex < scalar @packages; $packageIndex++) {
my $package = $packages[$packageIndex];
next PACKAGE unless scalar @{ $package };
@ -79,6 +82,7 @@ sub buildXML {
}
my $destination = $package->[0]->getShippingAddress;
my $destZipCode = $destination->get('code');
$destZipCode =~ s/^(\d{5}).*$/$1/;
$packageData{ID} = $packageIndex;
$packageData{Service} = [ $service ];
$packageData{ZipOrigination} = [ $self->get('sourceZip') ];

View file

@ -25,7 +25,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::ShipDriver::USPS;
plan tests => 66;
plan tests => 69;
#----------------------------------------------------------------------------
# Init
@ -232,6 +232,13 @@ my $wucAddress = $addressBook->addAddress({
city => 'Madison', state => 'WI', code => '53703',
country => 'United States',
});
my $zip4Address = $addressBook->addAddress({
label => 'work-zip4',
organization => 'Plain Black Corporation',
address1 => '1360 Regent St. #145',
city => 'Madison', state => 'WI', code => '53715-1255',
country => 'United States',
});
$cart->update({shippingAddressId => $workAddress->getId});
cmp_deeply(
@ -826,6 +833,48 @@ SKIP: {
}
#######################################################################
#
# Test ZIP+4 format domestic code
#
#######################################################################
$cart->update({shippingAddressId => $zip4Address->getId});
my $xmlData = XMLin($driver->buildXML($cart, @shippableUnits),
KeepRoot => 1,
ForceArray => ['Package'],
);
cmp_deeply(
$xmlData,
{
RateV3Request => {
USERID => $userId,
Package => [
{
ID => 0,
ZipDestination => '53715', ZipOrigination => '97123',
Pounds => '1', Ounces => '8.0',
Size => 'REGULAR', Service => 'PRIORITY',
Machinable => 'true',# Container => 'VARIABLE',
},
],
}
},
'buildXML: removed plus4 part of zipcode'
);
SKIP: {
skip 'No userId for testing', 2 unless $hasRealUserId;
my $cost = eval { $driver->calculate($cart); };
my $e = Exception::Class->caught();
ok( ! ref $e, 'no exception thrown for zip+4 address');
cmp_deeply($cost, num(10,9.99), 'zip+4 address returns a valid cost');
}
$cart->update({shippingAddressId => $workAddress->getId});
#######################################################################
#
# Check for throwing an exception