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 offset notice when deleting an order #208

Closed daphilli224 closed 2 years ago

daphilli224 commented 2 years ago

I'm receiving an undefined offset notice: PHP Notice: Undefined offset: 3 in /admin/includes/classes/observers/EditOrdersAdminObserver.php on line 69 when deleting an order using the button row. If the design intent is to display an edit order button next to the delete and cancel buttons in the cancel order confirmation area, the problem is that the $p2 array contains a 'form' key in addition to 0, 1, and 2. Therefore $index_to_update is calculated as 3, which does not exist. I fixed the problem by testing $p2 for a 'form' key using array_key_exists and if true, setting $index_to_update to count($p2) - 2. I did not chase down whether 'form' should be in $p2 or not, and it could be there from something I did elsewhere. I attached a screen shot before the fix. After the fix, the button appears in the same row as the delete and cancel buttons.

Note that this code is also executed to display the edit order button at the bottom of the order details area. No error is encountered then, and the 'form' key is not present in $p2.

But I question whether the edit order button should be in this area at all. I agree it should be at the end of the order details area as well as at the top.

Edit Orders version 4.6.0 File: EditOrdersAdminObserver.php Notifier: NOTIFY_ADMIN_ORDERS_MENU_BUTTONS_END php version 7.3.29 zc version: 1.5.7c Screen Shot 2022-01-06 at 10 37 33 AM Edit Orders v4.0 Support Thread, post #1718 from 9/18/21

proseLA commented 2 years ago

i have verified said PHP notice. i think the easiest thing to do would be to adjust the code as such:

    case 'NOTIFY_ADMIN_ORDERS_MENU_BUTTONS_END':
        $action = $_REQUEST['action'] ?? 'noAction';
                if (is_object($p1) && count($p2) > 0 && ($action !== 'delete')) {
                    $index_to_update = count($p2) - 1;
                    $p2[$index_to_update]['text'] = $this->addEditOrderButton($p1->orders_id, $p2[$index_to_update]['text']);
                }
                break;

note this will only work on php versions > 7.

lat9 commented 2 years ago

@daphilli224, thanks for the report, and @proseLA, thanks for the code adjustment. I'll be doing that so that PHP 5.6 will still be supported.