Skip to content

Commit

Permalink
#39: Correct single-service international quotes
Browse files Browse the repository at this point in the history
Also includes some simplification in the special-services' determination.
  • Loading branch information
lat9 committed Jul 6, 2023
1 parent 2d986a4 commit d3f889d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
60 changes: 35 additions & 25 deletions includes/modules/shipping/usps.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,26 @@ public function quote($method = '')
}

if ($this->is_us_shipment === true) {
if (!isset($uspsQuote['Package']) || !is_array($uspsQuote['Package'])) {
$PackageSize = 0;
} else {
$PackageSize = count($uspsQuote['Package']);
// if object has no legitimate children, turn it into a firstborn:
if (isset($uspsQuote['Package']['ZipDestination']) && !isset($uspsQuote['Package'][0]['Postage'])) {
$uspsQuote['Package'][] = $uspsQuote['Package'];
$PackageSize = 1;
}
// if object has no legitimate children, turn it into a firstborn:
if (isset($uspsQuote['Package']['ZipDestination']) && !isset($uspsQuote['Package'][0]['Postage'])) {
$uspsQuote['Package'] = [
$uspsQuote['Package'],
];
}
$PackageSize = count($uspsQuote['Package']);
$domestic_service_varname = (MODULE_SHIPPING_USPS_RATE_TYPE === 'Online') ? 'AvailableOnline' : 'Available';
} else {
// -----
// Some countries, notably Aruba, have only one service available, turn this into
// a single-element array.
//
if (isset($uspsQuote['Package']['Service']['SvcDescription']) && !isset($uspsQuote['Package']['Service'][0])) {
$uspsQuote['Package']['Service'] = [
$uspsQuote['Package']['Service']
];
}
$PackageSize = count($uspsQuote['Package']['Service']);
$intl_service_varname = (MODULE_SHIPPING_USPS_RATE_TYPE === 'Online') ? 'OnlineAvailable' : 'Available';
}

for ($i = 0; $i < $PackageSize; $i++) {
Expand All @@ -582,27 +590,29 @@ public function quote($method = '')
}

foreach ($Package['SpecialServices']['SpecialService'] as $key => $val) {
$service_name = $val['ServiceName'];

// translate friendly names for Insurance Restricted Delivery 177, 178, 179, since USPS rebranded to remove all sense of explanations
if ($val['ServiceName'] === 'Insurance Restricted Delivery') {
if ($service_name === 'Insurance Restricted Delivery') {
if ($val['ServiceID'] === '178') {
$val['ServiceName'] = 'Insurance Restricted Delivery (Priority Mail Express)';
$service_name = 'Insurance Restricted Delivery (Priority Mail Express)';
} elseif ($val['ServiceID'] === '179') {
$val['ServiceName'] = 'Insurance Restricted Delivery (Priority Mail)';
$service_name = 'Insurance Restricted Delivery (Priority Mail)';
}
}
// translate friendly names for insurance 100, 101, 125, since USPS rebranded to remove all sense of explanations
if ($val['ServiceName'] === 'Insurance') {
if ($service_name === 'Insurance') {
if ($val['ServiceID'] === '125') {
$val['ServiceName'] = 'Priority Mail Insurance';
$service_name = 'Priority Mail Insurance';
} elseif ($val['ServiceID'] === '101') {
$val['ServiceName'] = 'Priority Mail Express Insurance';
$service_name = 'Priority Mail Express Insurance';
}
}

$val['ServiceName'] = $this->clean_usps_marks($val['ServiceName']);

if (!empty($dExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE === 'Online' && !empty($val['AvailableOnline']) && strtoupper($val['AvailableOnline']) === 'TRUE') || (MODULE_SHIPPING_USPS_RATE_TYPE === 'Retail' && !empty($val['Available']) && strtoupper($val['Available']) === 'TRUE'))) {
$val['ServiceAdmin'] = $this->clean_usps_marks($dExtras[$val['ServiceName']]);
$service_name = $this->clean_usps_marks($service_name);
if (!empty($dExtras[$service_name]) && !empty($val[$domestic_service_varname]) && strtoupper($val[$domestic_service_varname]) === 'TRUE') {
$val['ServiceAdmin'] = $this->clean_usps_marks($dExtras[$service_name]);
$val['ServiceName'] = $service_name;
$Services[] = $val;
}
}
Expand All @@ -622,9 +632,10 @@ public function quote($method = '')
}

foreach ($Package['ExtraServices']['ExtraService'] as $key => $val) {
$val['ServiceName'] = $this->clean_usps_marks($val['ServiceName']);
if (isset($iExtras[$val['ServiceName']]) && !empty($iExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE === 'Online' && strtoupper($val['OnlineAvailable']) === 'TRUE') || (MODULE_SHIPPING_USPS_RATE_TYPE === 'Retail' && strtoupper($val['Available']) === 'TRUE'))) {
$val['ServiceAdmin'] = $this->clean_usps_marks($iExtras[$val['ServiceName']]);
$service_name = $this->clean_usps_marks($val['ServiceName']);
if (!empty($iExtras[$service_name]) && strtoupper($val[$intl_service_varname]) === 'TRUE') {
$val['ServiceAdmin'] = $this->clean_usps_marks($iExtras[$service_name]);
$val['ServiceName'] = $service_name;
$Services[] = $val;
}
}
Expand Down Expand Up @@ -1262,7 +1273,6 @@ protected function _getQuote()
if (is_numeric($requested_type) || preg_match('#(GXG|International)#i' , $requested_type)) {
continue;
}
$FirstClassMailType = '';
$Container = 'VARIABLE';
if ($requested_type === 'Media Mail Parcel') {
$service = 'MEDIA';
Expand Down Expand Up @@ -1738,7 +1748,7 @@ protected function parseDomesticLegacyAPITransitTimeResults($transresp)
$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
}
break;
case (stripos($service, 'USPS Retail Ground') !== false):
case (stripos($service, 'USPS Ground Advantage') !== false):
$time = $val['Days'];
if ($time === '' || $time === 'No Data') {
$time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
Expand Down Expand Up @@ -1784,7 +1794,7 @@ protected function parseDomesticTransitTimeResults($Package, $service)
case (stripos($service, 'Priority Mail') !== false):
$time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
break;
case (stripos($service, 'USPS Ground AdvantageTM') !== false):
case (stripos($service, 'USPS Ground Advantage') !== false):
$time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
break;
default:
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ To install or update this code ...
- Remove K11f changes that attempted (keyword) to remove the regional boxes from the configuration.
- Installations prior to K11g will need to "Remove" and then re "Install" the shipping module.
- 'Clean up' various code sections.
- Correct PHP Warnings when a country (like Aruba) has only one international service available.

2023-02-14 by lat9 2023-02-14 Version K11h
- quotes must be public, not protected. Cheapest shipping (when it's USPS) isn't highlighted.
Expand Down

0 comments on commit d3f889d

Please sign in to comment.