If this is your first visit, check our documentation. To post, register or login.

Fedex php error warning

Started by delia on 16 Dec 2020, 8:48 PM · Views: 16,794

Results 1 to 5 of 5
16 Dec 2020, 8:48 PM
#1
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Post #1 by delia

This happens on php 7.1. I contacted the firm who supports this module but they wanted me to pay for them to fix their dang bug.

[16-Dec-2020 20:39:04 UTC] PHP Warning: key() expects parameter 1 to be array, null given in /home/xxxxx/public_html/xxxxx.com/includes/modules/shipping/fedexwebservices.php on line 723

Line 723 is

 if(key($discount) <= $order->info['total']) {
                    $final_discount = $discount;
                    continue;
                  }

I commented out the entire section

    //find largest discount that applies
               ksort($discounts);
                while(count($discounts) > 0) {
                  $discount = array_pop($discounts);
                  if(key($discount) <= $order->info['total']) {
                    $final_discount = $discount;
                    continue;
                  }
                } 

But the error happens anyway.

Anyone else seen this? It's not an issue except that some services are just creating log file after log file. It does not seem to impact the functioning of the module but maybe it is and we don't realize it.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

16 Dec 2020, 11:02 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #2 by drbyte

Is that this module? https://www.zen-cart.com/downloads.php?do=file&id=1784

... cuz I don't see any code in its /includes/modules/shipping/fedexwebservices.php file that looks anything like what you posted, let alone around line 723, and nothing about discounts.

I don't understand why they're using a while-count-pop-key-continue loop instead of a simple foreach loop. But it's unclear what $discounts is supposed to contain (whether it's an array with custom keys, or just a set of one-dimensional values). Seeing how it is determined would be helpful. If it's a db query result or an api response result, then seeing actual data would be helpful, such as calling "die(print_r($discounts, true));" before the ksort line.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Dec 2020, 11:14 PM
#3
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Post #3 by delia

They no longer upload updates here. So yes, correct module. Not the recent version. I used to add updated versions like this here on zen cart but that brings questions directly to me I can’t answer. I’m thinking there’s more that needs fixing. They do not rely on in house coders by the way.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

17 Dec 2020, 12:27 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #4 by drbyte

I'm certain there's a much better way to write it, but there's not enough code provided here to investigate.
And yes I'd definitely call it a bug that they haven't accounted for.

You can put a bandage on it by changing like this:

if($discount !== null && key($discount) <= $order->info['total']) { 

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Dec 2020, 5:41 PM
#5
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Post #5 by delia

well either I did that wrong or it didn't work. So dang frustrating but still not major on this particular site as it's low traffic. I wonder how many high traffic sites are using this and not even realizing they have an issue. Responsible coding is all I ask of anyone.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo