Resetting Affiliate Totals
affil:OnResetStatistics event, that is executed on each page. The event checks for any affiliate records, where affiliate plan period is over and resets their totals:
- total items count, from orders associated with particular affiliate
- order total amounts, from orders associated with particular affiliate
Instead I recommend doing that in Scheduled Task once per day at 00:00.
Calculating Affiliate Commissions
Right now affiliate commission calculations happens real-time when order is approved.
This has 2 implications:
- ridiculously complex commission calculation code (we need to recalculate commissions for each past order in current affiliate plan period on every new approved order)
- affiliate gets commissions from orders, that were first approved, but then declined
Right now if user is affiliate himself and he makes a purchase, then he earns commissions from his own purchase, which doesn't really make sense.
To solve above issues I propose:
- To move commission calculation code from "order approval method" to "affiliate statistics reset method"
- Don't consider affiliate user login reason to create affiliate association. In fact if one affiliate makes purchase using another affiliate code, then another affiliate (code owner) should get credit for that.
- administrator/affiliate don't see any intermediate commissions that might be different once affiliate plan period is over
- actual commission % (from affiliate plan) is determined once per period, which reduces error factor greatly
- until affiliate plan period is over nobody knows what is earned by each affiliate, because we only see that a particular order has affiliate association and nothing more