From ff55ab1493e36478273e006a71f3ed053893c94c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 6 Sep 2009 20:23:12 -0700 Subject: [PATCH] For USPS priority service, add another container type. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Shop/ShipDriver/USPS.pm | 19 ++++--- lib/WebGUI/i18n/English/ShipDriver_USPS.pm | 6 +++ t/Shop/ShipDriver/USPS.t | 63 ++++++++++++++++++++-- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f555871b0..635e6d6db 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -16,6 +16,7 @@ - fixed #10876: EMS Schedule displaying wrong dates for ticket events - fixed #10915: StoryManager: Carousel clips content - fixed #10907: profiles viewable by everybody + - added custom box size to USPS driver, priority service 7.7.19 - fixed #10838: Forwarded forum post email to new CS adds reply to original thread diff --git a/lib/WebGUI/Shop/ShipDriver/USPS.pm b/lib/WebGUI/Shop/ShipDriver/USPS.pm index 2cc0f0eef..23e5faba3 100644 --- a/lib/WebGUI/Shop/ShipDriver/USPS.pm +++ b/lib/WebGUI/Shop/ShipDriver/USPS.pm @@ -53,6 +53,9 @@ 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; PACKAGE: for(my $packageIndex = 0; $packageIndex < scalar @packages; $packageIndex++) { my $package = $packages[$packageIndex]; next PACKAGE unless scalar @{ $package }; @@ -73,14 +76,17 @@ sub buildXML { my $destination = $package->[0]->getShippingAddress; my $destZipCode = $destination->get('code'); $packageData{ID} = $packageIndex; - $packageData{Service} = [ $self->get('shipType') ]; + $packageData{Service} = [ $service ]; $packageData{ZipOrigination} = [ $self->get('sourceZip') ]; $packageData{ZipDestination} = [ $destZipCode ]; $packageData{Pounds} = [ $pounds ]; $packageData{Ounces} = [ $ounces ]; - if ($self->get('shipType') eq 'PRIORITY') { + if ($shipType eq 'PRIORITY') { $packageData{Container} = [ 'FLAT RATE BOX' ]; } + elsif ($shipType eq 'PRIORITY VARIABLE') { + #$packageData{Container} = [ 'VARIABLE' ]; + } $packageData{Size} = [ 'REGULAR' ]; $packageData{Machinable} = [ 'true' ]; push @{ $xmlTop->{Package} }, \%packageData; @@ -218,10 +224,11 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session, 'ShipDriver_USPS'); tie my %shippingTypes, 'Tie::IxHash'; - ##Note, these keys are required XML keywords in the USPS XML API. - $shippingTypes{'PRIORITY'} = $i18n->get('priority'); - $shippingTypes{'EXPRESS' } = $i18n->get('express'); - $shippingTypes{'PARCEL' } = $i18n->get('parcel post'); + ##Note, these keys are used by buildXML + $shippingTypes{'PRIORITY VARIABLE'} = $i18n->get('priority variable'); + $shippingTypes{'PRIORITY'} = $i18n->get('priority'); + $shippingTypes{'EXPRESS' } = $i18n->get('express'); + $shippingTypes{'PARCEL' } = $i18n->get('parcel post'); tie my %fields, 'Tie::IxHash'; %fields = ( instructions => { diff --git a/lib/WebGUI/i18n/English/ShipDriver_USPS.pm b/lib/WebGUI/i18n/English/ShipDriver_USPS.pm index 21550a51a..3b9392784 100644 --- a/lib/WebGUI/i18n/English/ShipDriver_USPS.pm +++ b/lib/WebGUI/i18n/English/ShipDriver_USPS.pm @@ -76,6 +76,12 @@ our $I18N = { context => q|Label for a type of shipping from the USPS.|, }, + 'priority variable' => { + message => q|Priority, Custom box|, + lastUpdated => 1203569511, + context => q|Label for a type of shipping from the USPS.|, + }, + 'express' => { message => q|Express, Regular size|, lastUpdated => 1203569511, diff --git a/t/Shop/ShipDriver/USPS.t b/t/Shop/ShipDriver/USPS.t index 647be9510..ddb6087ff 100644 --- a/t/Shop/ShipDriver/USPS.t +++ b/t/Shop/ShipDriver/USPS.t @@ -93,6 +93,7 @@ my $nivBible = $bible->setCollateral('variantsJSON', 'variantId', 'new', ); $versionTag->commit; +WebGUI::Test->tagsToRollback($versionTag); SKIP: { @@ -699,6 +700,65 @@ SKIP: { } +$properties = $driver->get(); +$properties->{shipType} = 'PRIORITY VARIABLE'; +$driver->update($properties); + +$xml = $driver->buildXML($cart, @shippableUnits); +my $xmlData = XMLin($xml, + KeepRoot => 1, + ForceArray => ['Package'], +); +cmp_deeply( + $xmlData, + { + RateV3Request => { + USERID => $userId, + Package => [ + { + ID => 0, + ZipDestination => '53715', ZipOrigination => '97123', + Pounds => '1', Ounces => '8', + Size => 'REGULAR', Service => 'PRIORITY', + Machinable => 'true',# Container => 'VARIABLE', + }, + ], + } + }, + 'buildXML: PRIORITY, VARIABLE service, 1 item in cart' +); +like($xml, qr/RateV3Request USERID.+?Package ID=.+?Service.+?ZipOrigination.+?ZipDestination.+?Pounds.+?Ounces.+?Size.+?Machinable/, '... and tag order'); + +SKIP: { + + skip 'No userId for testing', 2 unless $hasRealUserId; + + my $response = $driver->_doXmlRequest($xml); + ok($response->is_success, '... _doXmlRequest to USPS successful'); + my $xmlData = XMLin($response->content, ForceArray => [qw/Package/],); + cmp_deeply( + $xmlData, + { + Package => [ + { + ID => 0, + ZipOrigination => ignore(), ZipDestination => ignore(), + Ounces => ignore(), Pounds => ignore(), + Size => ignore(), Zone => ignore(), + Postage => { + CLASSID => ignore(), + MailService => ignore(), + Rate => num(8,8), ##A number around 10... + } + }, + ], + }, + '... returned data from USPS in correct format. If this test fails, the driver may need to be updated' + ); + +} + + } #---------------------------------------------------------------------------- @@ -712,7 +772,4 @@ END { $addressBook->delete if $addressBook; $cart->delete; } - if (defined $versionTag) { - $versionTag->rollback; - } }