
Originally Posted by
swguy
I will periodically see
--> PHP Warning: count(): Parameter must be an array or an object that implements Countable in /SITE/includes/modules/shipping/usps.php on line 492. // line 487 in an unmodified file
where that line is
$PackageSize = count($uspsQuote['Package']['Service']);
This is the else branch of $this->is_us_shipment.
Is it possible this branch needs the same check as the other branch, where we check count($uspsQuote['Package']); (line 480).
I noticed the same issues and I spent some time try to fix it. Here is what I found:
How to trigger this warning:
1) When you tried to ship this order to a country that USPS cannot ship (like Russia), this warning will be generated (because USPS cannot ship to that country).
2) If your shopping cart is expensive (like over 10k) or maybe very heavy, and your shipping cart has more than one items, if you want to ship it to non-US country (like France), this warning will be generated. It seems USPS doesn't have a way to ship this order so zen cart cannot get a quote from USPS.
Here is my fix. I tested and it seems good. I'm not a professional developer, so if you have a better way to improve, please let me know. My USPS module version is 2020-09-24 lat9 Version K11. I checked the latest version, the code in this section is the same.
Here is the original code near line 487:
Code:
if ($this->is_us_shipment) {
$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;
}
} else {
$PackageSize = count($uspsQuote['Package']['Service']);
}
Here is my code:
Code:
if ($this->is_us_shipment) {
$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;
}
} else {
// $PackageSize = count($uspsQuote['Package']['Service']);
if ($uspsQuote['Package']['Service']) {
$PackageSize = count($uspsQuote['Package']['Service']);
}
}
Bookmarks