using 2.3.0.2 and in my error log i'm getting an error:
PHP Warning: Division by zero in /system/storage/modification/catalog/controller/product/category.php on line 380
When I go to line 380 in the above file, I have this:
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
Can someone tell me what it's looking at that's causing the error? so far none of the other division by zero threads appear to be the same from what i've found.
thanks!
Hi,
Seems you have installed some module where is this formula. this formula is bad. Because division by zero is not allowed (in red).
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
Seems you have installed some module where is this formula. this formula is bad. Because division by zero is not allowed (in red).
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
As above, it's a badly written extension. Disable them one by one until you find which one is the cause and then ask for support from the developer.kestas wrote: ↑Wed Oct 25, 2017 2:18 pmSeems you have installed some module where is this formula. this formula is bad. Because division by zero is not allowed (in red).
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Guru Member
I fixed this for a client today, and just to note, this code is actually in OpenCart 2.3.0.2, so the code itself is not from a mod. It may be being *triggered* by a mod, but the OpenCart code has the actual syntax error in it.
Also, the syntax error is not the 0 in that line of code, but this part:
$product_total / $limit
It occurs when $limit is 0, which is probably what the mod is triggering, since OpenCart doesn't ever load a page with a $limit of 0 (as far as I know). It could also be a bot that is scraping the site and getting the $limit wrong, or leaving it blank.
To fix it, you can make this edit:
The same issue will occur for any other paginated page with a $limit of 0, so you can make the same edit in the other files in /catalog/controller/product/ if you see the error come from any of those files.
Also, the syntax error is not the 0 in that line of code, but this part:
$product_total / $limit
It occurs when $limit is 0, which is probably what the mod is triggering, since OpenCart doesn't ever load a page with a $limit of 0 (as far as I know). It could also be a bot that is scraping the site and getting the $limit wrong, or leaving it blank.
To fix it, you can make this edit:
Code: Select all
IN:
/catalog/controller/product/category.php
REPLACE ALL INSTANCES OF:
if (isset($this->request->get['limit'])) {
WITH:
if (!empty($this->request->get['limit'])) {
The same issue will occur for any other paginated page with a $limit of 0, so you can make the same edit in the other files in /catalog/controller/product/ if you see the error come from any of those files.
Thank you for this fix Johnathan, I was getting this error from a bot scraping the site. Your code has fixed this for when as you say when the bot has the value set to 0 or blank. However if the value is something like "0:0" or "a0", the error persists, is there a better solution that can deal with any value?
Try changing the edit to this:
Code: Select all
IN:
/catalog/controller/product/category.php
REPLACE ALL INSTANCES OF:
if (isset($this->request->get['limit'])) {
WITH:
if (!empty((int)$this->request->get['limit'])) {
Thanks for this suggestion Johnathan. The results are that it does stop any errors when the limit is set to any text value, however it will generate an error every time you view a category without any limit specified in the URL, such as the default view, and it does this for the first 5 instances of the replaced code. Meaning just viewing a category will generate 5 error logs, each with the error message "PHP Notice: Undefined index: limit in ...catalog/controller/product/category.php on line...".
As it only generated it for the first 5 occurrences and not the 6th/final occurrence, I replaced only the 6th/final instance with the '(int)' version, and the others as the previous '!empty' non-int version, but this performed as the original solution with the division by zero error still there for text values.
As it only generated it for the first 5 occurrences and not the 6th/final occurrence, I replaced only the 6th/final instance with the '(int)' version, and the others as the previous '!empty' non-int version, but this performed as the original solution with the division by zero error still there for text values.
Ah, it must not like being cast to an int before it's checked whether the parameter is set. Try this edit instead:
Code: Select all
IN:
/catalog/controller/product/category.php
REPLACE ALL INSTANCES OF:
if (isset($this->request->get['limit'])) {
WITH:
if (!empty($this->request->get['limit']) && (int)$this->request->get['limit'] > 0) {
$this->request->get['limit'] = (int)$this->request->get['limit'];
Who is online
Users browsing this forum: No registered users and 421 guests