So I'm going to go back and test this in the previous version I had relatively working, but what I'm running into is:
If I create a new user account through an affiliate link, the affiliate chain seems to receive their affiliate percentages just fine
If I create a new user and then set their affiliate via the affiliate administration, the affiliate, and any parent affiliates, fail to receive any compensation
Am I misusing this functionality? or is this something that should work and does not?
I suppose I should add that I'm trying to get this running on PostgreSQL and have a handful of patches to that end (mostly INSERT INTO SET queries replaced with INSERT INTO VALUES queries and db_affected_rows() replaced with !empty($result), along with a few postgres functions (mysql unix timestamp porting)
EDIT: Working on tracing this down... it seems like the problem is that affiliate_aid is being saved to the data field in the user entry and loaded back from there when it is needed, rather than being derived on user_load?
If this is intended, then the admin functions don't update affiliate_aid properly, but I'm inclined to think it's not?
EDIT (again): I think I finally got this worked out... after getting rid of the stored values in user data, ms_affiliates_load_affiliate calls a user_access('act as affiliate') check, but in the context of ms_affiliates_ms_order_payment the current user is Anonymous, so affiliate_aid is null if not present in the user data... changing the access check to user_access('act as affiliate', $account) fixes this...
(so would making ms_affiliates_ms_order_payment call ms_affiliates_load_affiliate directly, rather than using $account->affiliate_aid, but this seemed tidier, no clue on better practices though?)
I wonder if this is even the right place for the user_access call? a user doesn't necessarily need to be able to be an affiliate to have an affiliate... shouldn't user_access be checked when walking the affiliate chain, for each parent account, not for the child account?
ie. either in load_affiliates first get $account->affiliate_aid and then check user_access('act as affiliate', user_load($account->affiliate_aid)) and unset it upon failure (fairly clever way to get the right access calls happening? will result in more overhead though?), or check it in ms_order_payment for each affiliate account (brute force? less overhead possibly? not sure...)
I'll try to post patches of my changes later (along with PostgreSQL compatibility fixes that I don't think will hurt MySQL)
PS: ms_memberships admin function is also leaving a bunch of junk in user data, should be relatively simple to clean that up, I think...







