How to add Affiliation features to Spree Commerce
What is Spree Affiliate?
Spree Reffiliate is a spree extension that provides the functionality of user referrals and affiliate features to your spree store.
A unique link is generated for users which is shareable to friends and once users purchase a product via that path, then affiliate gain benefits.
Affiliate users are users who earn commission while placing an order or user registrations on their affiliate links sharing.
- A specific role for an affiliate user who gets a commission as per the commission rules created.
- Affiliates get the information about the commissions received in the account panel.
- Referral codes are generated for users, used to refer to other users.
- Users can see the number of referred users and their details in their account panel.
- Add “spree_reffiliate” to your Gemfile.
gem 'spree_reffiliate', github: 'vinsol-spree-contrib/spree_reffiliate'
- Install the dependencies using:
- Run the installation generator:
bundle exec rails g spree_reffiliate:install
- If you already have users in your database, then generate the referral codes for the existing users using the following code:
bundle exec rake reffiliate:generate
- Open rails console and create commission rules for User Registration and Order placement as shown below:
EGISTRATION, fixed_commission: true)
PLACEMENT, fixed_commission: false)
Changes in View:
- Login as admin
- Following links will be available in the side menu:
Configurations > Affiliates
Configurations > Referrals
3. If you visit
Configurations > Affiliates, you will see,
4. If you visit
Configurations > Referrals, you will see,
Here, in the below image, these configurations are global settings to award the user credits as store credits on referrals and provide benefits.
Implementation: Basically, there are 2 flows:
- Affiliation: It works as a third party and gets a commission on user registration and order placement.
- Referrals: Users get store credits in their account by sharing the unique codes generated to their friends and get benefits.
- Admin end ( Backend )
- Login as admin
- Create an affiliate user by visiting the link
Configurations > Affiliates > Add New Affiliate:
- Path: A custom path for affiliate users which is shareable to any user to earn benefits as per the commission rules defined.
- Commission Rules:
- Here, we created the commission rules above for User Registration and Order Placement.
- The affiliate user will get benefits on every user registration and order placement by using the affiliate link as per the rules defined.
- The user registration rule should have some amount.
- The order placement rule should have value in percentage (%).
Note: The rules defined are applied to every affiliate user and can be customized as per the affiliate’s requirement.
- After successful creation, the affiliate user will be notified using an email with the activation link to activate the affiliate account.
- Affiliate side
Hit the link provided in the email, and you will be redirected to the edit password page for affiliate users.
Fill in the form with the password and confirmation password, and you will be logged in as an affiliate user in the application.
The affiliate link is shared with other users to gain benefits.
If there is a partial while creating an affiliate, then it will redirect to the home page embedded with the specified partial. Otherwise, it will be redirected to the home page.
Partial should be available at
app/views/spree/affiliates path for customizations.
Affiliate users share their affiliate link available in the
MyAccount via any media source.
Other users can visit the affiliate’s link, and can purchase products or goods as per their requirements.
- User side
Hit the affiliate link received.
Register the user to the application.
Affiliate User for the newly registered user will get a commission on user registration as defined for that respective affiliate.
To check out the commission received, go to MyAccount panel of the affiliate user.
After successful registration, if the newly registered user places an order with the standard checkout process, the respective affiliate user will earn commission as per the commission rule defined for order placement.
Commission Transactions can be viewed in MyAccount section for the order placed.
Note: If the user places an order without hitting the affiliate link then the affiliate user will not get the respective commissions.
But after hitting the affiliate link, successful user registration, placing an order with a standard checkout process will provide the commission amount for User Registration and Order Placement to the respective affiliate user.
Admin can view the affiliates list, their transactions, and commissions received for what type, i.e. User registration/Order Placement.
How will the Commission be Paid to Affiliate Users?
The commission paid to the affiliate will be paid by admin when the commission cycle will complete.
- Commission Created for affiliate user has a start date and end date.
- Let’s suppose a new user is registered using the affiliate’s link on Dec 19, 2019 ( 19-12-2019 )
- Commission for that respective affiliate user will be created for user registration.
- Start date for the commission will be the current month’s start date for when the commission is created.
- For e.g.: Commission for user registration will be created on 19-12-2019, hence start date = 1-12-2019.
- End date for the commission will be the current month’s end date for when the commission is created.
- End date = 31-12-2019.
- The commission cycle completes at the end of the current month.
- Hence, after the current month’s completion, admin is able to pay the commissions to the affiliate users.
- Admin can gain benefits by sharing the referral codes to his friends, family, colleagues, etc.
- Any user can share their referral codes with other end users.
- Users visiting the referral links get the benefit in the form of store credits configured globally in the admin panel as well as it can be user-specific.
- Some configurations are required to be done from the admin panel to avail referrals credits.
- Login as admin
- Visit the referrals section from
Configurations > Referrals:
Store Credits to be awardedare the credits the user would be getting on any referral.
- Fill this input with the value with the credits you want to award with.
- Check the flag
Give Referral Benefitsto avail referral credits.
Note: If you don’t want the referral credits to be awarded just uncheck the flag
Give Referral Benefits in
Configurations > Referrals
If you want to user-specific store credits to be received, then you can always edit as shown below by visiting the Users edit link.
On this user’s successful referrals, referrer (firstname.lastname@example.org) will receive $10 as store credit as it is configured to be user-specific.
How do Referrals Work?
Login as admin.
Visit the account panel.
Admin can share the referral link via any media source to other users.
Users with the referral link of the referred user hit the link in the browser gets benefits on sign up.
Hit the referral link in the browser.
Sign up for a new user.
Admin receives the referral award that can be viewed in the account panel.
Admin can view his referrals details in his account panel.
When you click on View Details, you will be able to see the number of referred users and credits received on referrals.
Admin can view the referral store credits in the Users section, as shown below:
Note: Here, the admin receives the store credits configured in the global settings section above rather than the newly registered user.
But, customizations can be done as per the requirement.
- A registered user can also share his referral code with his friends, family, colleagues to earn benefits.
- Registered users can also follow the same procedure as admin referred to other users by following steps 2 to 4 in the above section.
There is no constraint in the number of users to be referred that can up to infinity too!!
- Referral links will be in the form of
- Affiliate links will be in the form of
BoTree Technologies is a leading spree commerce development company in Ahmedabad that builds top-notch software and ecommerce solutions to increase business revenue and maximize productivity. Get a FREE CONSULTATION from our CEO.
Choose Your Language
- Digital Marketing
- IT Consulting
- Project Management