spree referral extension

291 views
Skip to first unread message

Stephane

unread,
May 14, 2012, 3:20:36 PM5/14/12
to spree...@googlegroups.com
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.

Brian Quinn

unread,
May 14, 2012, 3:35:26 PM5/14/12
to spree...@googlegroups.com
Stephane,
You should take a look at: https://github.com/spree/spree_affiliate

It was built on top of spree_store_credits and used in production with an earlier version of Spree. Looks like there's a few forks that are up-to-date with 1.0 at least.

It supports giving credit to the referrer and/or referee on signup and/or first order.


--
Brian Quinn

Co-Founder, CTO
Spree Commerce, Inc.

--
You received this message because you are subscribed to the Google Groups "Spree" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spree-user/-/oKPGINxxpLIJ.
To post to this group, send email to spree...@googlegroups.com.
To unsubscribe from this group, send email to spree-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.

Stephane

unread,
May 15, 2012, 4:14:54 AM5/15/12
to spree...@googlegroups.com
Thanks Brian, this is what I am looking for! Indeed, my approach was over-engineered...

There are some few features that I would like to bring, like giving store credit to the referrer only when the referee order is paid.
I will provide pull request asap !

Stephane.
To unsubscribe from this group, send email to spree-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages