News:

Support the VirtueMart project and become a member

Main Menu

PHP7 - Category View 0 Modulo by zero

Started by xtech86, December 28, 2016, 12:30:33 PM

Previous topic - Next topic

xtech86

Hello,

I'm struggling to narrow down this bug in VM3.0.18. When viewing a category view we get:

0 Modulo by zero

Stack trace shows as:

1   JApplicationCms->execute()   /Applications/MAMP/htdocs/site/index.php:49
2   JApplicationSite->doExecute()   /Applications/MAMP/htdocs/site/libraries/cms/application/cms.php:261
3   JApplicationSite->dispatch()   /Applications/MAMP/htdocs/site/libraries/cms/application/site.php:230
4   JComponentHelper::renderComponent()   /Applications/MAMP/htdocs/site/libraries/cms/application/site.php:191
5   JComponentHelper::executeComponent()   /Applications/MAMP/htdocs/site/libraries/cms/component/helper.php:380
6   require_once()   /Applications/MAMP/htdocs/site/libraries/cms/component/helper.php:405
7   JControllerLegacy->execute()   /Applications/MAMP/htdocs/site/components/com_virtuemart/virtuemart.php:125
8   VirtueMartControllerCategory->display()   /Applications/MAMP/htdocs/site/libraries/legacy/controller/legacy.php:702
9   VirtuemartViewCategory->display()   /Applications/MAMP/htdocs/site/components/com_virtuemart/controllers/category.php:54
10   VirtueMartModelProduct->sortSearchListQuery()   /Applications/MAMP/htdocs/site/components/com_virtuemart/views/category/view.html.php:196
11   VmModel->exeSortSearchListQuery()   /Applications/MAMP/htdocs/site/administrator/components/com_virtuemart/models/product.php:702
12   VirtueMartModelProduct->setPaginationLimits()   /Applications/MAMP/htdocs/site/administrator/components/com_virtuemart/helpers/vmmodel.php:820

I've gone through setPaginationLimit() with the debugger and all works well, it returns two array values of 10, 10. Although you do set limit as an int on line 728 then then on line 731 and 733 you just get and do not convert back to an int, but this is technically ok as the later requests/sets store as an int anyhow.

If I remove the $this->SetPaginationLimits for the 3 calls in the vmmodel.php the site loads again.

Any one got any suggestions? I'm quite stumped. Since the error to me looks to be a Division by Zero from the Modulo by Zero report. But the only possible for that is on line 748 $limitStart = ceil((float)$limitStart/(float)$limit) * $limit;

Both of which return numbered and none 0 values.

Suggestions??


xtech86

I have found the problem, it was caused by allowing the products per row to be set to 0 in the Category configuration of VM. If you increase this to a value greater than 0 it works since a calculation can be completed.

But VM should be adding a check on line 809 of /administrator/components/com_virtuemart/models/product.php when doing a calculation with the following code:


$rest = $suglimit % $category->products_per_row;


The calculation shouldn't be done if either products_per_row value = 0, either that or on update you check the categories do now have a value of 0 in the products_per_row and you increase it to say 1 or more so the problem cannot occur.

Many thanks
Tony

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/