Balance is not checked

Ehud - May 5, 2008 - 08:46
Project:Ubercart Userpoints
Version:5.x-2.x-dev
Component:User interface
Category:bug report
Priority:critical
Assigned:bmagistro
Status:closed
Description

I am using points as a payment method to order products. Problem is that users are able to "buy" products even if they don't have the required amount of points. They submit their order and points are reduced from their balance to be less than zero...

I'm new to Drupal and Ubercart. I probably miss something here.

I am using Drupal 5.7 and the latest relevant versions of ubercart, userpoints and userpoints_ubercart.

Thanks very much for your help!

#1

bmagistro - May 5, 2008 - 13:20

I will have to look. I thought I had a check in there to see if they had enough. if the have <= 0 it shouldn't show an option, but I will look this week.

#2

Ehud - May 6, 2008 - 12:35

Thanks a lot!
That is really important. I went through a lot with the ubercart module and i wouldn't want to do it all again with another.
Thanks.

#3

korvus - May 7, 2008 - 17:48

What settings are you using? (especially the "Points used in payment" setting in the Ubercart section of admin/settings/userpoints)

How much are the products?

If you say that it costs 100 points / dollar, then sell a product for $0.25, it will think zero points are needed (not 25). If you set 0.5 points / dollar, it will think everything costs zero points (regardless of cost). The module is pretty quirky if you use it in a way it was not intended to be used.

Now, I'm pretty sure in both those cases it will try to subtract zero points, but if we know you have questionable settings somewhere (based on how the module works), that might give us a better idea of where to look.

#4

TR - May 7, 2008 - 18:02

When I tried this module a few weeks ago, I found I could make an order a negative $ amount if I used enough points, or I could spend more points than I had and end up with a negative point balance - I didn't see any limit checking in effect at all! I assigned $1 = 1 point, Points enabled as a discount method. I was applying points to the order as a discount, running on Ubercart RC4.

Also, you have a spelling error in the text displayed by the module - in several places, you spell "amount" wrong.

#5

bmagistro - May 7, 2008 - 19:54

Can you use the dev version? I have a check in uc_points_payment so that shouldn't be an issue. my guess is it was added after the release was made or something like that.

if ($curUserPoints < $pointsNeeded) {

thank you for pointing my spelling mistakes out. just goes to show why i shouldn't write more code after school and work and everything else..... I will get those fixed in the latest dev later today

#6

Ehud - May 11, 2008 - 11:50

I tried the dev version. it behaves the same way.. I tried various configurations. none of them worked for me. Some how the $orderTotal variable gets the value 0, so the condition above is true only if the total amount of points is less than zero.

regarding the setting that I'm using, it should be 1 points / dollar. and users should be able to order prices from the points that they manage to collect using the site (using only points as a payment method). But i don't mind using different configuration if it works(i already tried several, with no success). Is there any setting i can use?

Sorry for the delayed response, caused by local holidays...

Thanks again for your kind support.

#7

Ehud - May 19, 2008 - 08:28

Is there anything I can add in order to help with a solution?
Please update if there is a plan to work on this issue in the near future.

Thank you.

#8

Ehud - May 20, 2008 - 07:01

I managed to fix it eventually. Probably not the best way to do it, but it does the work.
Add the following code in uc_cart\uc_cart.module file after line 1317 within the uc_cart_checkout() function:

$subtotal = 0;
$items = uc_cart_get_contents();
if (is_array($items) && count($items) > 0) {
$points_per_dollar = variable_get(USERPOINTS_UC_SPEND,1);
foreach ($items as $item) {
$data = module_invoke($item->module, 'cart_display', $item);
if (!empty($data)) {
$subtotal += $data['#total'] * $points_per_dollar;
}
}
}
$current_userpoints = userpoints_get_current_points($user->uid);
if ($current_userpoints < $subtotal) {
drupal_set_message(t('Not enuogh points for this order. You need ' . $subtotal . ' and you have only ' . $current_userpoints), 'error');
drupal_goto('cart');
}

It takes in account the points per dollar variable that you define in the Ubercart Userpoints Options.

#9

bmagistro - May 20, 2008 - 16:45

that is not the best way to do it. I have not had time to get this resolved, but will try and work on it this week time permitting. Be sure you do not upgrade ubercart as you will break the points system like that since your fix is not in the points module.

#10

Ehud - May 21, 2008 - 14:15

ok. I will remember that.
I hope you have time to work on a better solution.
thanks.

#11

bmagistro - May 22, 2008 - 18:23

I am looking at my code and hope to have a published fix for this but I have this in there and it should be doing the check here:

if ($curUserPoints < $pointsNeeded && $curUserId != 0) {
drupal_set_message('You do not have enough points to complete this purchase. You have ' . $curUserPoints . ' but you need ' . $pointsNeeded . '. Please select another payment method.', 'error');
return FALSE;

I am going to do some testing tonight and see how it goes. Once the script updates the dev version, if you have a sandbox you can try this out on that would be great. It now uses workflow for the points at the end of an order. I still need to do some writeups on that.

#12

Ehud - May 29, 2008 - 07:56

Maybe we have different configurations and this is why this check doesn't work for me. But there is nothing special with mine. I use no payment method besides the points
Please notify when you finish up and i will check it on my environment.
Thanks a lot!

#13

Ehud - June 11, 2008 - 20:00

Hi, any news? Did you manage to get to it?
Regards.

#14

bmagistro - June 11, 2008 - 23:38

at this time i cannot find the problem. can you download and install the latest dev version???

#15

Ehud - June 13, 2008 - 11:16

I checked it already. I think I will use my fix, and remember to handle it carefully on upgrades. Thanks anyhow.

#16

bmagistro - June 13, 2008 - 11:53
Status:active» postponed (maintainer needs more info)

I am going to mark this as needs more info for now since as far as I can tell you are the only experiencing this problem. I will ask someone else who is testing / running this to see if he can reproduce your problem.

#17

torgosPizza - June 13, 2008 - 16:05

Can confirm that this issue exists in the recent dev version:

User testuser lost 400 Userpoints! Total now is -293 points.

I'll see if I can work on a patch.

#18

torgosPizza - June 13, 2008 - 17:05

It looks like, per your hunch, using the (int) cast is making the negative integer into a positive.

Replacing it with usage of the intval() function seems to fix the issue.

You do not have enough points to complete this purchase. You have 100 but you need 399. Please select another payment method.

<?php
  $curUserPoints
= intval(userpoints_get_current_points($uid = $curUserId, $tid = NULL));
 
$pointExchange = intval(variable_get(USERPOINTS_UC_SPEND, 1));
?>

I would probably do this throughout the module...

#19

torgosPizza - June 13, 2008 - 17:23

Disregard this post. :)

#20

torgosPizza - June 13, 2008 - 18:30

ehudov, I would implement the fix as I've posted above. Hacking core ubercart files is messy and not good practice. The fix is simple, remove the (int) cast (and replace with intval()) for the function as bmagistro mentioned above. That way you won't have to worry about Ubercart upgrades with core, and plus, it's not really much of a change :) Much more preferable than your code, which invokes cart_display and makes some other unnecessary operations.

Let me know if you have any issues after this change.

#21

bmagistro - June 13, 2008 - 18:35

torogosPizza:
Thanks for testing that and getting back to me so quickly. I will get this applied throughout the module tonight and committed to the cvs. This was my first drupal module, so I'm sure there are things I could do better... I know some of my php skills could be better as well.

ehudov:
If you could start rolling back your changes I should have the dev updated by 6 or 7 tonight est.

I will post again once I have the changes completed. Thanks guys

#22

bmagistro - June 13, 2008 - 19:49
Version:5.x-1.7» 5.x-1.x-dev
Status:postponed (maintainer needs more info)» fixed

I am marking this as fixed unless someone comes back and reports that it is still not working...

#23

Ehud - June 26, 2008 - 06:23

Hello,

I'm very sorry for the delay in my response. Unfortunately, I only noticed the updates an hour ago..
there are so many other issues... I figure you too have...

Thank you all for your effort here.

I'm also sorry to report that the change from int to intval didn't help... I did the changes and noticed that the condition noticed that $curUserPoints is less than $pointsNeeded, but doesn't send the message. I will continue to investigate and let you know if I find anything.

Again, I'm sorry for coming back so late on this! Do you know if there is a way to get mail alerts whenever an issue is updated? (i didn't find this option in my account).

Best regards,
Ehud.

#24

Ehud - June 26, 2008 - 07:58

Hello again,

I debugged it and found that $orderTotal variable is zero. It seems that at the point where this code is running there is no order record in uc_orders table, so the used query (select order_total from {uc_orders} where order_id = ...) returns empty result.
By the time the last checkout review page appears the order is it its place but it still isn't there in between, when the important condition is being run.
I found only uc_cart_products table that holds the current product selections. but we need the cart_id in order to get the info from it.
I looked in the ubercart uc_cart module for a function that gets the cart_id. no luck..

Maybe we need to hook to some other event, i really have no experience in that Drupal part..
I will try to look for other directions..

I hope i'm not wrong here. any ideas or comments will be helpful

Thanks & regards.

#25

torgosPizza - June 26, 2008 - 18:02
Status:fixed» postponed (maintainer needs more info)

Strange, I didn't have this issue but I'll be happy to look into it. I'm on vacation at the moment, but when I get some spare coding time I will see if I can't get this to work. (First I'll need to reproduce it, hopefully I can to start.)

#26

Ehud - June 27, 2008 - 05:45

Thanks a lot! Please let me know if I can help in any way.

#27

bmagistro - July 3, 2008 - 23:14

did you setup the points rule in workflow-ng? In the latest release it uses that to simplify things like paypal integration.

#28

torgosPizza - July 4, 2008 - 02:25

Just wanted to say that someone on UC pointed to an error (which I don't have in my "working" version):

Fatal error: Call to undefined function intvar() in /Applications/MAMP/htdocs/mysite/sites/all/modules/userpoints_ubercart/uc_points_payment.inc on line 13

#29

bmagistro - July 4, 2008 - 02:57

I did see that. Version 1.9 should be coming out shortly. It will just be a update to ensure that intvar is no longer in a active release. I thought I had gotten that taken care of the first time it came up...i guess not. Thanks

#30

bmagistro - July 6, 2008 - 01:26
Assigned to:Ehud» bmagistro
Status:postponed (maintainer needs more info)» active

well...not really what i wanted but i can confirm that this is happening on one of my test sites. I found it while working on a mod for another user. I hope to have it fixed later today or tomorrow. I will keep you guys posted

#31

bmagistro - July 6, 2008 - 03:09
Status:active» fixed

The fix was surprisingly simple if it works. It has been added to the dev version. I am also very surprised the thing worked at all...but at line 147 there should have been a "break;" and one at 154. I have since added those and the check appears to be firing correctly every time. I eagerly await your feedback guys (if it doesn't work at least wait a few hours (or days) and let me think it does for a little while...:-p)

#32

Ehud - July 6, 2008 - 14:11

Thanks a lot for your effort! I will do as you please and wait a few hours to tell you if it works...(-:

Regards,
Ehud

#33

Ehud - July 6, 2008 - 19:10

Hello,

I am glad to say that it works. Thanks again for all of this job you did!

Best regards,
Ehud

#34

Anonymous (not verified) - July 23, 2008 - 10:56
Status:fixed» closed

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

#35

kristyb2008 - September 9, 2008 - 03:55
Status:closed» active

Hi Ben,

The balance is now being checked for Payment Method of UserPoints - But it's not being checked when using the Userpoints Discounts. What is the patch for this??

#36

bmagistro - September 9, 2008 - 13:13

I will try and look at this this week but no guarantees....i thought i had a check in there around line 190? does that not work?

#37

kristyb2008 - September 9, 2008 - 20:08

The problem isn't to do with whether or not the discount form displays if they have points, its to do with if the points entered in the field are greater than what they have available. There is no check. Therefore if they have 800 points and they wish to discount their cart by 900 points it lets them. Instead it should advise you can only enter a max of 800 points. Select an additional payment method to pay for the balance.

#38

bmagistro - September 9, 2008 - 20:10

I do understand what you are saying and I thought I had a check in there at one point for that. As I said earlier I will try and look at it this week.

#39

bmagistro - September 9, 2008 - 22:03

I have attached what I think will work. I have not tested this yet. It replaces the discount.module file. You need to rename this file. It looks like I lost the check for this....I will try and go find the original one but if this one works I like what it looks like....(I think)

AttachmentSize
uc_userpoints_discount.txt 8.71 KB

#40

kristyb2008 - September 10, 2008 - 16:43

Hey. I just tried the new module and it doesn't work. Users can still discount their purchase with more points then they have available.

#41

torgosPizza - September 12, 2008 - 22:17

Sounds odd, I'll take a look at this later today to, see if I can find anything.

#42

nathanjo - October 17, 2008 - 10:44
Version:5.x-1.x-dev» 5.x-2.2

Weird stuff! Still can discount items and purchase using points payment method even i don't have any points. Funny things, after purchase will still deduct your 0 points. :)

#43

gillesfouillet - November 12, 2008 - 14:47

hello everyone,

is someone still working on this 'Major' weird issue?

#44

Tanfoglio69 - November 12, 2008 - 23:36

I'm also in need of a solution for this...I hope someone can help?

Thanks in advance!

#45

bmagistro - November 16, 2008 - 19:50

I have found the bug causing this to happen with payments only so far. I hope to have that portion fixed later today.

#46

bmagistro - November 16, 2008 - 20:27
Version:5.x-2.2» 5.x-2.x-dev
Status:active» fixed

I am marking this as fixed until someone can confirm this does not work. It is my understanding that this bug report is ONLY for payment issues not for discount issues relating to balances. Once the packaging script runs and updates the development snapshot download and install it.

#47

Tanfoglio69 - November 17, 2008 - 08:46

Hi, thanks for your reply, the payment method does work for me now. I hope you can also fix the discounts, because that's the one I need the most...

If I can do anything to help, just tell me!

Thanks in advance

#48

bmagistro - November 17, 2008 - 17:44

I am tracking that issue here
http://drupal.org/node/282679

#49

System Message - December 1, 2008 - 17:51
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.