Closed (fixed)
Project:
User Referral
Version:
7.x-1.x-dev
Component:
Code: other
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
8 May 2012 at 09:09 UTC
Updated:
13 Sep 2016 at 04:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
coleman.sean.c commentedHere's the patch. The rules action returns a list of uids, just to protect against edge cases where there are 0 or many referrals. Is there a hard limit of at most one referral? Could simplify the code a bit, and return a user object if that were the case...
Comment #2
IWasBornToWin commentedI just tried to apply the patch but it wouldn't apply. I did it manually. The last added line of the patch has a ";" which would add two semicolon's at the end of the line. Not sure if that would make a difference or not.
After manually changing everything, the new rules action worked. I did get this notice afterward. Notice: Undefined offset: 1 in DatabaseStatementBase->fetchAllKeyed() (line 2180 of /home4/growtogi/public_html/includes/database/database.inc).
I've created a user field, referred_by, and I assign it the uid of the referring user after a new user account is saved. I did notice the variable of the fetched referring uid offered me [referring-uids:0],[referring-uids:1],[referring-uids:2],etc. I'm not sure there should be more than one uid fetched (iud instead of uids). I didn't even know it was possible to have more than one referring uid when referring a new user.
I see your note above about "many referrals" just didn't realize that was even possible. To eliminate a possible 0 I created aded condition - user was referred by another user.
This patch helps out big time - thank you.
Comment #3
RKS commentedIs there any way to fetch this for anon users? I need it to track the referrer for each user making a purchase and not just registered users.
Comment #4
vadim.eremeev commentedThanks for patch, I've a bit modified it to follow way since there is no possibility to have more than one referring user.
Added follow code which creates new action and return only one referring user ID:
So with this patch we can create a rule which award referring user with points after his referral did success purchase in ecommerce store. Exported rule looks like:
Comment #5
dariogcode commentedI just applied the patch #1 and it works, but as @vadim.eremeev mentioned there is possible only one referer. An about the last patch I think there isn't neccesary to do db_query_range
It is sufficient with
fetchField only return the first result and also it is supposed to not get more than one row with that query.
Comment #6
vadim.eremeev commented@tilon thanks for comments. Yep, I think we can just use db_query().
Also I've added another custom condition which checks if user did first order on web-site. Seems commerce not provide us with such a condition. I've created custom module for that with follow code in custom_referral.rules.inc file (other files just standart):
So my final rule which award referring user after his referral did first purchase on web-site looks like:
Comment #7
dariogcode commentedNice, I'm doing something similar but with Payment module, but I pay referral with userpoints for each referer purchase ;). I think you should make a final patch for "Fetch referring User" and this should be added to the last version, this is esentially.
Comment #8
hockey2112 commentedI applied the patch in #1, but I get this error message when adding the new action to the rule: "Unknown action fetch_referral." Any idea how to fix that issue?
Comment #9
sachin00700 commentedHello vadim.eremeev,
Your code is working for me but in my case i want that only points credit on referred user if the first purchase done from the referral user not in every purchase would you help me out for this i am not getting that.
Thanks in advance wait for you quick response
Sachin
Comment #10
sumit-k commentedHi,
You can try commerce first time customer discount module.It has one rule condition user first order.
Comment #11
hejazee commentedThis issue is fixed in the git repository. Please checkout the latest version
(or nightly built version)
Comment #12
hejazee commented