Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 2 stable #14

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ source 'https://rubygems.org'

gem 'haml-rails'

gem 'spree_auth_devise',
github: 'spree/spree_auth_devise',
branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'

gem 'spree_store_credits',
github: 'spree/spree_store_credits',
branch: '2-2-stable'
gem 'spree_store_credits', github: 'spree/spree_store_credits', branch: '2-2-stable'

gemspec
2 changes: 1 addition & 1 deletion app/controllers/spree/base_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
private

def remember_affiliate
cookies.permanent[:ref_id] = params[:ref_id] if params[:ref_id]
cookies.permanent[:ref_token] = params[:ref_token] if params[:ref_token]
end
end
2 changes: 1 addition & 1 deletion app/helpers/spree/base_helper_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Spree::BaseHelper.class_eval do
def referral_url(referrer)
root_url(ref_id: referrer.ref_id)
root_url(ref_token: referrer.ref_token)
end

def link_to_referral_url(referrer, options = {})
Expand Down
1 change: 1 addition & 0 deletions app/models/spree/affiliate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def name
def ref_id
partner.try(:ref_id) || ''
end

end
9 changes: 7 additions & 2 deletions app/models/spree/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
foreign_key: 'partner_id'
has_many :referred_users,
class_name: 'Spree::User',
through: :affiliates
through: :affiliates,
source: :user
has_one :affiliate_partner,
class_name:'Spree::Affiliate',
foreign_key: 'user_id'

def referred_by
affiliate_partner.partner
affiliate_partner.try :partner
end

def ref_id
self.id.to_s.reverse
end

def ref_token
Base64.encode64 email
end

def self.find_by_ref_id(ref_id)
Spree::User.find(ref_id.to_s.reverse)
end
Expand Down
7 changes: 4 additions & 3 deletions lib/affiliate_credits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def log_event(affiliate, user, credit, event)

def check_affiliate
@user.reload if @user.present? and not @user.new_record?
return if cookies[:ref_id].blank? || @user.nil? || @user.invalid?
sender = Spree.user_class.find_by_ref_id(cookies[:ref_id])
return if cookies[:ref_token].blank? || @user.nil? || @user.invalid?
email = Base64.decode64 cookies[:ref_token]
sender = Spree.user_class.find_by(email: email)

if sender
sender.affiliates.create(:user_id => @user.id)
Expand All @@ -44,6 +45,6 @@ def check_affiliate
end

#destroy the cookie, as the affiliate record has been created.
cookies[:ref_id] = nil
cookies[:ref_token] = nil
end
end
1 change: 1 addition & 0 deletions lib/spree_affiliate/engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module SpreeAffiliate
class Engine < Rails::Engine
require 'spree/core'
require 'haml'
isolate_namespace Spree
engine_name 'spree_affiliate'

Expand Down
3 changes: 2 additions & 1 deletion spree_affiliate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '~> 2.3.0.beta'
s.add_dependency 'spree_core', '~> 2.2.1'
s.add_dependency 'haml-rails'

s.add_development_dependency 'capybara', '~> 2.1'
s.add_development_dependency 'coffee-rails'
Expand Down