Hi,
I working on a spree_referral extension to allow people to invite friends to signup and reward them with a promotion.
The basic need :
- every user have an unique referral_token so we can create a unique url used by their friends to sign up.
- when a friend's first order is paid, a promotion will be created to the referral user.
To implement this feature, I was thinking of having a referral model which links the user (referral) and his friend :
class Spree::Referral
belongs_to :user #friend
belongs_to :referral, :class_name => "Spree::User" #referral user
state_machine :initial => 'created' do
end
end
The state basically allow us to know in which state is the friend : user signed up, order complete or paid,...
There are different callbacks :
- friend signing up with referral_token
- friend order paid
- user creating new order
I am thinking about using the same architecture (rails notifications) as the promotions by inheriting from Spree::Activator model.
However I am not sure how to proceed to have a clean way to define the different spree referral activators and it should be flexible enough for admins to :
- define if the referral (user) should be the only one to be eligible to a promotion or only the friend user, or both.
- define the different set of rules.
I don't know if my approach is over-engineered or there might be a simpler way to implement this feature.
I hope my explanation was clear enough, if not please let me know so I can rephrase it.
Stephane.