I receive this error on the Ubercart Payment settings page. I am using Drupal 5.5, PostgreSQL, and Ubercart Beta 5.

warning: Division by zero in /usr/local/apache2/htdocs/drupal/modules/userpoints_ubercart/uc_points_payment.inc on line 13.

Comments

bmagistro’s picture

either the ammount of points that the user has is 0 or the points used in payment is 0 which is more likely the problem. i know there should probably be a if check there to prevent this but i do not have the time i would like to spend on this module at this time. can you check both of those first for me? I will try and get that if statement added in and a new release packaged this weekend but no guarantees. someone else has added a patch for some other items with referrals and better paypal integration that i want too look at this weekend too.....

WISEOZ’s picture

The Ubercart Payment Settings screen isn't specific to any given user, so I'll answer your questions with that in mind. I have 34 users on my test site and some definitely have zero points. My points used in payment under Userpoint Settings -> Ubercart Options is set to .10.

bmagistro’s picture

what would happen there is if one of your zero point users hit it 0/.1, I thought there was a check to block it if they had 0 points? so are you saying that you want $10 = 1 point? because .1 is 1/10 of a point not $.10 use 1 if you want one point to be one dollar, 10 if you want 10 points to be 1 dollar.

can you try the dev version? as i think some of this might have been fixed in there, but im not sure anymore

WISEOZ’s picture

Good catch! I had intended on 10 points equally a $1. I changed it to 10 and I no longer receive the error!

korvus’s picture

There are a few places in the code where numbers like that are casted to integers (I was setting it up so referrers would get 1 point for every $10 that someone they referred spent, but my 0.1 points/dollar got casted to an integer 0, always awarding 0 points). In this case, it's the (int) here:

$maxdisc = round($curUserPoints / (int)variable_get(USERPOINTS_UC_SPEND, 1));

I am not sure if there are cases where people would want to have 1 point be more than 1 dollar, but it might make sense to avoid casts that make those assumptions. Of course, right now the divide by zero error stops people from making the mistake WiSeOz did...

bmagistro’s picture

i did that because i didn't think people would be using partial points like that but seeing as how that could be a possibility I think it might be worth taking that out and allowing decimals to be used.

wotstheguts’s picture

Hi, I also get this error:

warning: Division by zero in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\modules\userpoints_ubercart\uc_points_payment.inc on line 13.

My settings are as follows:

Points awarded for buying (multiplied by price): 1
Smallest purchase for which points are awarded: 8
Points used in payment (for every dollar): 0
Enable Points as a discount method: No

If I change "Points used in payment" to a non-zero value, the problem disappears. However, I don't want to give users the option of paying with points!

Your help would be appreciated.

Thanks,
Peter.

bmagistro’s picture

leave that at one and edit the settings payment settings and just don't allow points, or is that part not showing up/working?

wotstheguts’s picture

Thanks, that works, though the code should probably still check for a zero value to avoid the uglies.

bmagistro’s picture

there are still a lot of things I want it to do. I am getting them done as time permits....

bmagistro’s picture

Status: Active » Fixed

Marking as fixed as it works currently. There is still room for improvement I am sure....

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.