cubecart / v6

CubeCart Version 6
https://cubecart.com
72 stars 59 forks source link

Divide by Zero #3506

Closed bhsmither closed 5 months ago

bhsmither commented 5 months ago

In statistics.index.inc.php, near line 281, there is this part of the statement:

100*($result['customer_expenditure']/$divider[0]['total_sales']

When there are orders (status=3) having been made, but all of those orders have in the total column a decimal value of 0.00 (as when all of the products "sold" are free, consider that the database returns total_sales as the string "0.00", which is not false-like.

This particular string will auto-convert to the integer zero in the equation (problem!), but not in the test expression. This particular string is not empty() either.

Suggest a new line after line 273:

$divider = (float)$divider[0]['total_sales'];

Then line 281:

$result['percent'] = $divider ? number_format(100*($result['customer_expenditure']/$divider), 2) : 0;
abrookbanks commented 5 months ago

Very helpful thank you!