Results 1 to 10 of 447

Threaded View

  1. #21
    Join Date
    Apr 2019
    Posts
    350
    Plugin Contributions
    0

    Default Re: USPS Shipping Module [Support Thread]

    Quote Originally Posted by swguy View Post
    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']);
                } 
            }
    Last edited by njcyx; 20 Apr 2022 at 09:32 PM.

 

 

Similar Threads

  1. Optional Shipping Insurance Module [Support Thread]
    By jettrue in forum Addon Shipping Modules
    Replies: 415
    Last Post: 6 Jul 2026, 02:45 PM
  2. MultiSite Module Support Thread
    By Gerome in forum All Other Contributions/Addons
    Replies: 2246
    Last Post: 29 Dec 2025, 10:13 AM
  3. Replies: 29
    Last Post: 24 Sep 2014, 09:59 PM
  4. Replies: 335
    Last Post: 1 Aug 2013, 08:54 PM
  5. PC Configurator Module [Support Thread]
    By lebrand2006 in forum All Other Contributions/Addons
    Replies: 254
    Last Post: 22 Aug 2012, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg