VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: Greystoke on April 27, 2017, 16:03:31 PM

Title: Error: PHP Warning: Division by zero
Post by: Greystoke on April 27, 2017, 16:03:31 PM
Hi,

Upgraded to Joomla 3.7.0
PHP 5.6
VirtueMart 3.2.1

I am see this error since I upgraded Joomla to 3.7.0:

PHP Warning:  Division by zero in /components/com_virtuemart/sublayouts/categories.php on line 33
PHP Warning:  Division by zero in /components/com_virtuemart/sublayouts/categories.php on line 57
Title: Re: Error: PHP Warning: Division by zero
Post by: jenkinhill on April 27, 2017, 17:30:01 PM
Probably another J3.7 issue. Was there a warning with J3.6.5?  If the front end still looks OK then you can suppress the php warning with php.ini settings or possibly by setting  Error Reporting
to none in Joomla global config/server - I have not checked if warning suppression still works after a Joomla update.
Title: Re: Error: PHP Warning: Division by zero
Post by: Greystoke on April 27, 2017, 17:38:25 PM
Hi,

The error was in the error log.

When I upgrade PHP to 7.0 virtuemart no longer works at all.

I get this error on all pages:

(http://i65.tinypic.com/2s8039j.jpg)
Title: Re: Error: PHP Warning: Division by zero
Post by: Jörgen on April 27, 2017, 17:58:00 PM
Are You using a custom template ? Because others are using Joomla 3.7.0 without this issue. Not saying that VM doesn´t have issues with 3.7.0, but probably not this for most other users.

regards

Jörgen @ Kreativ Fotografi
Title: Re: Error: PHP Warning: Division by zero
Post by: Greystoke on April 27, 2017, 18:14:25 PM
I changed the Template to the Joomla default:

Beez3 - Default

Error:
(http://i64.tinypic.com/2vio9bc.jpg)

I removed the lines that where giving errors and virtuemart works with PHP 7.0
PHP Warning:  Division by zero in /components/com_virtuemart/sublayouts/categories.php on line 33
PHP Warning:  Division by zero in /components/com_virtuemart/sublayouts/categories.php on line 57  (REMOVED LINES 57-61 AS IT WAS AN IF STATEMENT)
Title: Re: Error: PHP Warning: Division by zero
Post by: Jörgen on April 27, 2017, 18:20:07 PM
Please show the code for the lines that are faulting. You may have some settings in number of columns maybe that is giving trouble.

This should be easy to fix in the template file :)

regards

Jörgen @ Kreativ Fotografi
Title: Re: Error: PHP Warning: Division by zero
Post by: jenkinhill on April 27, 2017, 18:40:37 PM
Both those calculation lines include the number of set categories per row.

I have a J3.7 VM3.2.1 running just fine on PHP7.0.18 using Beez and VM default templates. With full debug turned on there is no division by zero reported.
Title: Re: Error: PHP Warning: Division by zero
Post by: Greystoke on April 27, 2017, 22:16:52 PM
It looks like it is just this link that is the problem.

index.php?option=com_virtuemart&view=category&virtuemart_category_id=0&virtuemart_manufacturer_id=0&Itemid=557

It is the Menu link to the Shop, created using the Menu Item Type : Category Layout.

Select a Category is set to: Top Level Category.
Select a Manufacturer is set to: "Please Select". ( I am not using Manufacturers, so none to select )

Title: Re: Error: PHP Warning: Division by zero
Post by: Jörgen on April 28, 2017, 09:44:53 AM
Just curious. Do You have categories per row set to 0 somewhere  in Virtuemart under configuration templates?

This would explain the issue. The following code would be nice to include in sublayouts/categories.php

after line 39
$categories_per_row = VmConfig::get ( 'categories_per_row', 3 );

insert a test for categories == 0
// JH 2017-04-28 Prevents division by 0
if ($categories_per_row == 0) {
  $categories_per_row = 3:}



regards

Jörgen @ Kreativ Fotografi
Title: Re: Error: PHP Warning: Division by zero
Post by: Greystoke on April 29, 2017, 16:08:49 PM
I have Default number of categories in a row set to 3

Is there anywhere else this could be set.
Title: Re: Error: PHP Warning: Division by zero
Post by: jenkinhill on April 29, 2017, 16:19:31 PM
Cats per row can be set in three places: 
the Joomla menu link to VM category view on the Virtuemart Category View Settings tab
in VM Configuration/Templates
and for each category on the Virtuemart category view settings
Title: Re: Error: PHP Warning: Division by zero
Post by: Milbo on May 03, 2017, 07:44:44 AM
or just

if(empty($categories_per_row)) $categories_per_row = 3;