From cc7b28ecce28236bda50e255e04381457b1a6496 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 8 Jul 2009 21:11:15 -0700 Subject: [PATCH] Add customer classification field to the driver, i18n, tests. --- lib/WebGUI/Shop/ShipDriver/UPS.pm | 16 +++++++++++ lib/WebGUI/i18n/English/ShipDriver_UPS.pm | 30 ++++++++++++++++++-- t/Shop/ShipDriver/UPS.t | 34 ++++++++++++++--------- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/lib/WebGUI/Shop/ShipDriver/UPS.pm b/lib/WebGUI/Shop/ShipDriver/UPS.pm index 92661a9e7..e09abf308 100644 --- a/lib/WebGUI/Shop/ShipDriver/UPS.pm +++ b/lib/WebGUI/Shop/ShipDriver/UPS.pm @@ -88,6 +88,9 @@ sub buildXML { $xmlRate->{PickupType} = { Code => [ $self->get('pickupType') ], }; + $xmlRate->{CustomerClassification} = { + Code => [ $self->get('customerClassification') ], + }; $xmlRate->{Shipment} = { Shipper => { Address => [ { @@ -286,6 +289,12 @@ sub definition { $pickupTypes{'19'} = $i18n->get('pickup code 19'); $pickupTypes{'20'} = $i18n->get('pickup code 20'); + tie my %customerClassification, 'Tie::IxHash'; + ##Note, these keys are required XML keywords in the UPS XML API. + $customerClassification{'01'} = $i18n->get('customer classification 01'); + $customerClassification{'03'} = $i18n->get('customer classification 03'); + $customerClassification{'04'} = $i18n->get('customer classification 04'); + my $localizedCountries = Locales::Country->new('en'); ##Note, for future i18n change the locale tie my %localizedCountries, 'Tie::IxHash'; %localizedCountries = map { $_ => $_ } grep { !ref $_ } $localizedCountries->all_country_names(); @@ -351,6 +360,13 @@ sub definition { options => \%pickupTypes, defaultValue => '01', }, + customerClassification => { + fieldType => 'selectBox', + label => $i18n->get('customer classification'), + hoverHelp => $i18n->get('customer classification help'), + options => \%customerClassification, + defaultValue => '01', + }, ##Note, if a flat fee is added to this driver, then according to the license ##terms the website must display a note to the user (shop customer) that additional ##fees have been added. diff --git a/lib/WebGUI/i18n/English/ShipDriver_UPS.pm b/lib/WebGUI/i18n/English/ShipDriver_UPS.pm index 93c54c004..9d8be2024 100644 --- a/lib/WebGUI/i18n/English/ShipDriver_UPS.pm +++ b/lib/WebGUI/i18n/English/ShipDriver_UPS.pm @@ -92,6 +92,32 @@ our $I18N = { lastUpdated => 1242945844, }, + 'customer classification' => { + message => q|Customer Classification|, + lastUpdated => 1241214572, + context => q|What kind or type of customer are you?|, + }, + + 'customer classification help' => { + message => q|The kind or type of customer you are.|, + lastUpdated => 1247110533, + }, + + 'customer classification 01' => { + message => q|Wholesale|, + lastUpdated => 1247110533, + }, + + 'customer classification 03' => { + message => q|Occasional|, + lastUpdated => 1247110533, + }, + + 'customer classification 04' => { + message => q|Retail|, + lastUpdated => 1247110533, + }, + 'flatFee' => { message => q|Flat Fee|, lastUpdated => 1241214572, @@ -206,8 +232,8 @@ our $I18N = { }, 'ship type help' => { - message => q|Pick a type of shipping that will be used. The different types have different services available. Not all services are available in all types, or in all countries.|, - lastUpdated => 1242166045, + message => q|Pick a type of shipping that will be used. The different types have different services available. Not all services are available in all types, or in all countries. Changing the service will change the Ship Service options below.|, + lastUpdated => 1247111015, context => q|Label for a type of shipping from the UPS.|, }, diff --git a/t/Shop/ShipDriver/UPS.t b/t/Shop/ShipDriver/UPS.t index f57a52299..738f8d0c2 100644 --- a/t/Shop/ShipDriver/UPS.t +++ b/t/Shop/ShipDriver/UPS.t @@ -340,13 +340,14 @@ if (! $license) { } $properties = $driver->get(); -$properties->{userId} = $userId; -$properties->{password} = $password; -$properties->{licenseNo} = $license; -$properties->{sourceZip} = '97123'; -$properties->{sourceCountry} = 'United States'; -$properties->{shipService} = '03'; -$properties->{pickupType} = '01'; +$properties->{userId} = $userId; +$properties->{password} = $password; +$properties->{licenseNo} = $license; +$properties->{sourceZip} = '97123'; +$properties->{sourceCountry} = 'United States'; +$properties->{shipService} = '03'; +$properties->{pickupType} = '01'; +$properties->{customerClassification} = '04'; $driver->update($properties); $driver->testMode(1); @@ -378,6 +379,8 @@ cmp_deeply( '... correct access request data structure for 1 package' ); +diag $xmlR; + my $xmlRate = XMLin($xmlR, KeepRoot => 1, ); @@ -386,9 +389,10 @@ cmp_deeply( $xmlRate, { RatingServiceSelectionRequest => { 'xml:lang' => 'en-US', - PickupType => { Code => '01', }, - Request => { RequestAction => 'Rate', }, - Shipment => { + PickupType => { Code => '01', }, + CustomerClassification => { Code => '04', }, + Request => { RequestAction => 'Rate', }, + Shipment => { Shipper => { Address => { PostalCode => 97123, CountryCode => 'us', }, }, @@ -430,6 +434,8 @@ $xml = $driver->buildXML($cart, @shippableUnits); ($xmlA, $xmlR) = split /\n(?=<\?xml)/, $xml; +diag $xmlR; + $xmlRate = XMLin( $xmlR, KeepRoot => 1, ForceArray => ['Package'], @@ -439,9 +445,10 @@ cmp_deeply( $xmlRate, { RatingServiceSelectionRequest => { 'xml:lang' => 'en-US', - PickupType => { Code => '01', }, - Request => { RequestAction => 'Rate', }, - Shipment => { + PickupType => { Code => '01', }, + CustomerClassification => { Code => '04', }, + Request => { RequestAction => 'Rate', }, + Shipment => { Shipper => { Address => { PostalCode => 97123, CountryCode => 'us', }, }, @@ -474,6 +481,7 @@ SKIP: { my $xmlData = XMLin($response->content, ForceArray => [qw/RatedPackage/],); ok($xmlData->{Response}->{ResponseStatusCode}, '... responseCode is successful'); ok($xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue}, '... total charges returned'); + diag $xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue}; }