lat9 / edit_orders

Edit Orders: Updates for continued operation on Zen Cart v1.5.8 and later
GNU General Public License v2.0
5 stars 9 forks source link

Undefined array key PHP Warning when an order's tax value is 0. #221

Closed lat9 closed 4 months ago

lat9 commented 1 year ago

As reported on the Zen Cart forum's support thread by Dave224: I'm getting an undefined array key 'tax_rate' error when editing orders with no tax. The myDEBUG log is:

[08-Jun-2023 19:03:00 America/New_York] Request URI: /admin/index.php?cmd=edit_orders&oID=5704&action=update_order, IP address: ::1
#1 zen_get_tax_rate_from_desc() called at [/path/includes/modules/order_total/ot_quantity_discount.php:369]
#2 ot_quantity_discount->calculate_deductions() called at [/path/includes/modules/order_total/ot_quantity_discount.php:158]
#3 ot_quantity_discount->process() called at [/path/includes/classes/order_total.php:65]
#4 order_total->process() called at [/path/admin/includes/functions/extra_functions/edit_orders_functions.php:1435]
#5 eo_update_database_order_totals() called at [/path/admin/includes/modules/edit_orders/eo_update_order_action_processing.php:456]
#6 require(/path/admin/includes/modules/edit_orders/eo_update_order_action_processing.php) called at [/path/admin/edit_orders.php:84]
#7 require(/path/admin/edit_orders.php) called at [/path/admin/index.php:11]
--> PHP Warning: Undefined array key "tax_rate" in /path/admin/includes/functions/extra_functions/edit_orders_functions.php on line 217.

No errors occur if tax>0. I've found that edit orders changes the tax_groups array in the order class from '0.0000'=>'1' to 'Tax'=>'0.0'. Then when function zen_get_tax_rate_from_desc queries the tax_rate table, it can't find 'Tax' and the undefined array key warning occurs. 'Tax' is the value of TEXT_UNKNOWN_TAX_RATE in admin.

An obvious fix is to test whether the query finds a valid tax rate in zen_get_tax_rate_from_desc, but I'm not sure that's the best solution. Any suggested fixes would be appreciated.

zc1.5.7c, edit orders 4.6.2, php 8.0.2. Line numbers in the log may differ slightly from out-of-the-box code due to troubleshooting code. Testing done on development system.

lat9 commented 8 months ago

While not a correction, I'll note that v4.7.0 of EO will no longer include that zen_get_tax_rate_from_desc function as it's now available for use in the admin.

Having (now) traced that log back, it appears that that function is the victim, having been passed invalid data from

zen_get_tax_rate_from_desc() called at [/path/includes/modules/order_total/ot_quantity_discount.php:369]