Hello,

I was reviewing the code a bit more and I discovered that the way the roles are retrieved, "$roles = $account->roles;", that it will get all the user's roles - even the ones which do not grant the user affiliate capabilities. If the user is granted to a role with a role_id that is greater than any affiliate role then it won't be able to retrieve the right commission information.

What I did was replace all of this code:

// Get the affiliate role (only the last one)
$roles = $account->roles;
krsort($roles);
$rids = array_keys($roles);
$rid = $rids[0];

With:

$rid = _uc_get_user_rid($account->roles);

And the function is:

// Will get the last role id for the user that is an affiliate role
function _uc_get_user_rid($user_roles) {
$roles = user_roles(FALSE, 'act as affiliate');
$roles = array_intersect_assoc($roles, $user_roles);
$rids = array_keys($roles);
$rid = $rids[0];
}

I placed this function right before the _uc_affiliate2_clicked($account) function

The reason why I created this as a function is because I am in the process of adding code that will reward an affiliate for purchases made by users he/she referred even if the cookie is long gone. This will serve two purposes, one where the user comes in with one computer, creates the account, and then makes a purchase with another computer. Or, more importantly for my purposes, can be used to grant an affiliate life time commissions for any client they referred. I will send you that code once I have it completed for your consideration.

Scott

Comments

bojanz’s picture

Status: Active » Fixed

Thanks, I've commited the changes.

Your function needs to be called _uc_affiliate2_get_user_rid, and needs to return $rid at the end.

Good to know someone is reviewing the code, only parts were written by me, so it's in dire need of a checkup.

Bojan

keptin-1’s picture

Bojan,

Oops! Thanks for pointing that out - I made the updates on my side.

No problem with checking it out - I really need this on my site and this is what the OpenSource idea is all about!

Scott

Status: Fixed » Closed (fixed)

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