From fe63bccea97310b0cc9105df9ee795f5e1a1a112 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 10 Aug 2009 13:33:40 -0700 Subject: [PATCH] Clip lowside weight at 0.1 lbs. Otherwise UPS will gripe at you. --- lib/WebGUI/Shop/ShipDriver/UPS.pm | 4 ++- t/Shop/ShipDriver/UPS.t | 41 +++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/WebGUI/Shop/ShipDriver/UPS.pm b/lib/WebGUI/Shop/ShipDriver/UPS.pm index 0a40501cc..c58e2ef4f 100644 --- a/lib/WebGUI/Shop/ShipDriver/UPS.pm +++ b/lib/WebGUI/Shop/ShipDriver/UPS.pm @@ -129,12 +129,14 @@ sub buildXML { $weight += $skuWeight; } next PACKAGE unless $weight; + $weight = sprintf "%.1f", $weight; + $weight = '0.1' if $weight == 0; my $options = { PackagingType => [ { Code => [ '02' ], } ], PackageWeight => [ { - Weight => [ sprintf "%.1f", $weight ], ##Required formatting from spec + Weight => [ $weight ], ##Required formatting from spec } ], }; push @{ $packHash }, $options; diff --git a/t/Shop/ShipDriver/UPS.t b/t/Shop/ShipDriver/UPS.t index 9c1a8fdbd..40c2a4d9b 100644 --- a/t/Shop/ShipDriver/UPS.t +++ b/t/Shop/ShipDriver/UPS.t @@ -35,7 +35,7 @@ $session->user({user => $user}); #---------------------------------------------------------------------------- # Tests -my $tests = 40; +my $tests = 41; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -93,6 +93,20 @@ my $nivBible = $bible->setCollateral('variantsJSON', 'variantId', 'new', } ); +my $feather = $home->addChild({ + className => 'WebGUI::Asset::Sku::Product', + isShippingRequired => 1, title => 'Feathers', + shipsSeparately => 0, +}); + +my $blueFeather = $feather->setCollateral('variantsJSON', 'variantId', 'new', + { + shortdesc => 'blue feather', price => 1.00, + varSku => 'blue', weight => 0.001, + quantity => 999999, + } +); + $versionTag->commit; WebGUI::Test->tagsToRollback($versionTag); @@ -385,8 +399,6 @@ my $xmlRate = XMLin($xmlR, KeepRoot => 1, ); -diag Dumper $xmlRate; - cmp_deeply( $xmlRate, { RatingServiceSelectionRequest => { @@ -463,6 +475,8 @@ $xmlRate = XMLin( $xmlR, ForceArray => ['Package'], ); +diag Dumper $xmlRate; + cmp_deeply( $xmlRate, { RatingServiceSelectionRequest => { @@ -475,13 +489,13 @@ cmp_deeply( Address => { PostalCode => 97123, CountryCode => 'us', }, }, ShipTo => { - Address => { PostalCode => 53715, CountryCode => 'us', }, + Address => { PostalCode => 53715, CountryCode => 'us', ResidentialAddressIndicator => {}, }, }, Service => { Code => '03', }, Package => bag( { PackagingType => { Code => '02', }, - PackageWeight => { Weight => '1.5', }, + PackageWeight => { Weight => '3.0', }, }, { PackagingType => { Code => '02', }, @@ -509,6 +523,23 @@ SKIP: { ok($driver->getEditForm(), 'getEditForm'); +$cart->empty; +$feather->addToCart($feather->getCollateral('variantsJSON', 'variantId', $blueFeather)); +$xml = $driver->buildXML($cart, $driver->_getShippableUnits($cart)); +($xmlA, $xmlR) = split /\n(?=<\?xml)/, $xml; + +$xmlRate = XMLin( $xmlR, + KeepRoot => 1, + ForceArray => ['Package'], +); + +is ( + $xmlRate->{RatingServiceSelectionRequest}->{Shipment}->{Package}->[0]->{PackageWeight}->{Weight}, + '0.1', + 'Weight is clipped at 0.1 pounds.' +); + +$cart->empty; } #----------------------------------------------------------------------------