问题
I am using OpenCart 1.4.9 and I have been dealing with Undefined index Errors in product.php recently, I suspect it happens every time the user is creating/input a new product on the dashboard.
How to fix these errors because it makes the server resource overload, my site resource usage peaked at 91% sometimes 100% on the cPanel?
Here is the model file.
Here is the controller file.
Here are the errors I am getting:
PHP Notice: Undefined index: model in /home/xxx/public_html/admin/controller/catalog/product.php on line 651
PHP Notice: Undefined index: sku in /home/xxx/public_html/admin/controller/catalog/product.php on line 659
PHP Notice: Undefined index: location in /home/xxx/public_html/admin/controller/catalog/product.php on line 667
PHP Notice: Undefined index: keyword in /home/xxx/public_html/admin/controller/catalog/product.php on line 687
PHP Notice: Undefined index: image in /home/xxx/public_html/admin/controller/catalog/product.php on line 703
PHP Notice: Undefined index: image in /home/xxx/public_html/admin/controller/catalog/product.php on line 710
PHP Notice: Undefined index: manufacturer_id in /home/xxx/public_html/admin/controller/catalog/product.php on line 723
PHP Notice: Undefined index: shipping in /home/xxx/public_html/admin/controller/catalog/product.php on line 731
PHP Notice: Undefined index: date_available in /home/xxx/public_html/admin/controller/catalog/product.php on line 739
PHP Notice: Undefined index: quantity in /home/xxx/public_html/admin/controller/catalog/product.php on line 747
PHP Notice: Undefined index: minimum in /home/xxx/public_html/admin/controller/catalog/product.php on line 755
PHP Notice: Undefined index: subtract in /home/xxx/public_html/admin/controller/catalog/product.php on line 763
PHP Notice: Undefined index: sort_order in /home/xxx/public_html/admin/controller/catalog/product.php on line 771
PHP Notice: Undefined index: stock_status_id in /home/xxx/public_html/admin/controller/catalog/product.php on line 783
PHP Notice: Undefined index: price in /home/xxx/public_html/admin/controller/catalog/product.php on line 791
PHP Notice: Undefined index: cost in /home/xxx/public_html/admin/controller/catalog/product.php on line 799
PHP Notice: Undefined index: status in /home/xxx/public_html/admin/controller/catalog/product.php on line 807
PHP Notice: Undefined index: tax_class_id in /home/xxx/public_html/admin/controller/catalog/product.php on line 819
PHP Notice: Undefined index: weight in /home/xxx/public_html/admin/controller/catalog/product.php on line 827
PHP Notice: Undefined index: weight_class_id in /home/xxx/public_html/admin/controller/catalog/product.php on line 841
PHP Notice: Undefined index: length in /home/xxx/public_html/admin/controller/catalog/product.php on line 851
PHP Notice: Undefined index: width in /home/xxx/public_html/admin/controller/catalog/product.php on line 859
PHP Notice: Undefined index: height in /home/xxx/public_html/admin/controller/catalog/product.php on line 867
PHP Notice: Undefined index: length_class_id in /home/xxx/public_html/admin/controller/catalog/product.php on line 881
回答1:
The following are some possibilities:
The fields (listed in your errors) don't exist in your database.
There might be some problem with your product_form.tpl template file.
Check whether the values are getting inserted correctly to the product tables while adding a product.
Comparing the admin product files with a fresh unedited OpenCart 1.4.9 admin product files will help you to find out the issue.
回答2:
These simply occur when $product_info['variable mentioned in error is not specified']
, a simple, and complete fix is to edit the query like below:
elseif (isset($product_info)) {
$this->data['location'] = $product_info['location'];
}
Into:
elseif (isset($product_info['location'])) {
$this->data['location'] = $product_info['location'];
}
And do so for each of the cases, furthermore you can do this for all $product_info[]
data to avoid future errors like that.
回答3:
In case of when just some of the indexes undefined, the reason for it may be very simple: if the properties are not set in the admin panel (like in my case for Length, Weight and in stock).
来源:https://stackoverflow.com/questions/21519019/opencart-undefined-index-errors-in-product