Upgrading error and cleaning up sloppy programming
Posted: Sun Sep 26, 2021 7:11 am
Hi everyone,
I am in the process of upgrading my site and in the process I am trying to clean up some sloppy programming a third party programmer did for me (before I realised that there were preferred programmers on this site that could have done the job for me)...
I added some code to the file includes\system\versioned\1.0.7.8\checkout.php back in the upgrade to version 1.0.7.10 (I think) and now as I upgrade to 1.0.7.13 it is causing me grief....
Can someone have a look at it and maybe give me an idea of where the problem would generate from and maybe tell me how I would fix it up so that it is not messing with the core code.
the code I have added (originally written by my programmer) is here;
The code is there to allow me to count stock movements on some items in my store and not others...
the error I am getting is;
I tried to workout where the call to this function was coming from but cannot locate it so I am not sure where to go from here.
I am in the process of upgrading my site and in the process I am trying to clean up some sloppy programming a third party programmer did for me (before I realised that there were preferred programmers on this site that could have done the job for me)...
I added some code to the file includes\system\versioned\1.0.7.8\checkout.php back in the upgrade to version 1.0.7.10 (I think) and now as I upgrade to 1.0.7.13 it is causing me grief....
Can someone have a look at it and maybe give me an idea of where the problem would generate from and maybe tell me how I would fix it up so that it is not messing with the core code.
the code I have added (originally written by my programmer) is here;
Code: Select all
public static function reset_cart() {
// Added by programmer
foreach ($GLOBALS['order']->products as $product) { //This is the line generating the error
$stock_query = tep_db_query("SELECT products_quantity, products_count_stock FROM products WHERE products_id = '" . tep_get_prid($product['id']) . "'");
if ($stock_values = tep_db_fetch_array($stock_query)) {
if ($stock_values['products_count_stock'] == 1)
{
// do not decrement quantities if products_attributes_filename exists
$stock_left = $stock_values['products_quantity'] - $product['qty'];
tep_db_query("UPDATE products SET products_quantity = " . (int)$stock_left . " WHERE products_id = '" . tep_get_prid($product['id']) . "'");
}
}
}// End Added by programmer
$_SESSION['cart']->reset(true);
}the error I am getting is;
Code: Select all
PHP Notice: Undefined index: order in .../includes/system/versioned/1.0.7.8/checkout.php on line 194
PHP Notice: Trying to get property 'products' of non-object in ..../includes/system/versioned/1.0.7.8/checkout.php on line 194
PHP Warning: Invalid argument supplied for foreach() in .../includes/system/versioned/1.0.7.8/checkout.php on line 194