spree_affiliate 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/LICENSE +23 -0
- data/README.md +23 -0
- data/Rakefile +54 -0
- data/app/controllers/admin/affiliate_settings_controller.rb +13 -0
- data/app/controllers/affiliates_controller.rb +6 -0
- data/app/controllers/checkout_controller_decorator.rb +16 -0
- data/app/controllers/email_sender_controller_decorator.rb +10 -0
- data/app/controllers/spree/base_controller_decorator.rb +9 -0
- data/app/controllers/users_controller_decorator.rb +35 -0
- data/app/models/affiliate.rb +13 -0
- data/app/models/affiliate_event.rb +5 -0
- data/app/models/user_decorator.rb +22 -0
- data/app/views/admin/affiliate_settings/edit.html.erb +28 -0
- data/app/views/admin/affiliate_settings/show.html.erb +26 -0
- data/app/views/affiliates/_mail_to_friend.html.erb +13 -0
- data/app/views/affiliates/show.html.erb +0 -0
- data/app/views/email_sender/_fields.html.erb +16 -0
- data/app/views/users/_affiliate.html.erb +15 -0
- data/config/database.yml +17 -0
- data/config/environments/cucumber.rb +38 -0
- data/config/locales/en.yml +12 -0
- data/config/routes.rb +7 -0
- data/lib/affiliate_credits.rb +29 -0
- data/lib/generators/spree_affiliate/install_generator.rb +14 -0
- data/lib/generators/templates/db/migrate/20101022121217_create_affiliates.rb +14 -0
- data/lib/generators/templates/db/migrate/20101104145139_create_affiliate_events.rb +16 -0
- data/lib/spree_affiliate.rb +18 -0
- data/lib/spree_affiliate_hooks.rb +9 -0
- data/lib/tasks/spree_affiliate.rake +1 -0
- data/spec/models/user_spec.rb +8 -0
- data/spec/spec_helper.rb +27 -0
- data/spree_affiliate.gemspec +24 -0
- metadata +165 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without modification,
|
2
|
+
are permitted provided that the following conditions are met:
|
3
|
+
|
4
|
+
* Redistributions of source code must retain the above copyright notice,
|
5
|
+
this list of conditions and the following disclaimer.
|
6
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer in the documentation
|
8
|
+
and/or other materials provided with the distribution.
|
9
|
+
* Neither the name of the Rails Dog LLC nor the names of its
|
10
|
+
contributors may be used to endorse or promote products derived from this
|
11
|
+
software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
14
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
15
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
16
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
17
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
18
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
19
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
20
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
21
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
22
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Spree Affiliate
|
2
|
+
===============
|
3
|
+
Allows customers to refer friends and earn store credit for each user who registers and/or orders.
|
4
|
+
|
5
|
+
You can also give store credit to the refered friends on signup and after first order.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
============
|
9
|
+
|
10
|
+
1. Add to Gemfile:
|
11
|
+
|
12
|
+
gem "spree_store_credits"
|
13
|
+
gem "spree_email_to_friend"
|
14
|
+
gem "spree_affiliate"
|
15
|
+
|
16
|
+
1. Run `bundle install`
|
17
|
+
1. Run install generators for all extensions:
|
18
|
+
|
19
|
+
rails g spree_store_credits:install -f
|
20
|
+
rails g spree_affiliate:install -f
|
21
|
+
|
22
|
+
1. Run `rake db:migrate`
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
desc "Default Task"
|
7
|
+
task :default => [ :spec ]
|
8
|
+
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
RSpec::Core::RakeTask.new
|
11
|
+
|
12
|
+
require 'cucumber/rake/task'
|
13
|
+
Cucumber::Rake::Task.new do |t|
|
14
|
+
t.cucumber_opts = %w{--format pretty}
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Regenerates a rails 3 app for testing"
|
18
|
+
task :test_app do
|
19
|
+
SPREE_PATH = ENV['SPREE_PATH']
|
20
|
+
raise "SPREE_PATH should be specified" unless SPREE_PATH
|
21
|
+
require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator')
|
22
|
+
class AuthTestAppGenerator < Spree::Generators::TestAppGenerator
|
23
|
+
def tweak_gemfile
|
24
|
+
append_file 'Gemfile' do
|
25
|
+
<<-gems
|
26
|
+
gem 'spree_core', :path => '#{File.join(SPREE_PATH, 'core')}'
|
27
|
+
gem 'spree_auth', :path => '#{File.join(SPREE_PATH, 'auth')}'
|
28
|
+
gem 'spree_store_credits', :path => '#{File.join(SPREE_PATH, '..', 'spree_store_credits')}'
|
29
|
+
gem 'spree_email_to_friend', :path => '#{File.join(SPREE_PATH, '..', 'spree-email-to-friend')}'
|
30
|
+
gem 'spree_affiliate', :path => '#{File.dirname(__FILE__)}'
|
31
|
+
gems
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def install_gems
|
36
|
+
system("cd spec/test_app && rake spree_core:install")
|
37
|
+
system("cd spec/test_app && rake spree_auth:install")
|
38
|
+
generate 'spree_store_credits:install -f'
|
39
|
+
generate 'spree_affiliate:install -f'
|
40
|
+
end
|
41
|
+
|
42
|
+
def migrate_db
|
43
|
+
run_migrations
|
44
|
+
end
|
45
|
+
end
|
46
|
+
AuthTestAppGenerator.start
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :test_app do
|
50
|
+
desc 'Rebuild test and cucumber databases'
|
51
|
+
task :rebuild_dbs do
|
52
|
+
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
CheckoutController.class_eval do
|
2
|
+
include AffiliateCredits
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def after_complete
|
7
|
+
session[:order_id] = nil
|
8
|
+
|
9
|
+
if current_user && current_user.affiliate_partner && current_user.orders.where(:state => 'complete').count == 1
|
10
|
+
sender = current_user.partner
|
11
|
+
|
12
|
+
#create credit (if required)
|
13
|
+
create_affiliate_credits(sender, current_user, "purchase")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
EmailSenderController.class_eval do
|
2
|
+
private
|
3
|
+
|
4
|
+
def after_delivering_affiliate_mail
|
5
|
+
emails = @mail_to_friend.recipient_email.split(/,\s?/)
|
6
|
+
emails.each do |email|
|
7
|
+
current_user.affiliates.create(:affiliate_email => email) if Affiliate.where(:affiliate_email => email).count == 0
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
UserRegistrationsController.class_eval do
|
2
|
+
include AffiliateCredits
|
3
|
+
|
4
|
+
after_filter :check_affiliate, :only => :create
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def check_affiliate
|
9
|
+
return if cookies[:ref_id].blank? or @user.invalid?
|
10
|
+
sender = User.find_by_ref_id(cookies[:ref_id])
|
11
|
+
|
12
|
+
if sender
|
13
|
+
#see if email address used is an invited affiliate
|
14
|
+
affiliate = sender.affiliates.where(:affiliate_email => @user.email).first
|
15
|
+
|
16
|
+
#if none exist create an affiliate
|
17
|
+
if affiliate.nil? && Affiliate.where(:affiliate_email => @user.email).count == 0
|
18
|
+
affiliate = sender.affiliates.create(:affiliate_email => @user.email)
|
19
|
+
else
|
20
|
+
#affiliate is registered to a different account (other than the ref_id above). what should we do?
|
21
|
+
end
|
22
|
+
|
23
|
+
#link affiliate record with newly registered user
|
24
|
+
if affiliate and affiliate.user.nil?
|
25
|
+
affiliate.update_attribute(:user_id, @user.id)
|
26
|
+
end
|
27
|
+
|
28
|
+
#create credit (if required)
|
29
|
+
create_affiliate_credits(sender, @user, "register")
|
30
|
+
end
|
31
|
+
|
32
|
+
#destroy the cookie, as the affiliate record has been created.
|
33
|
+
cookies[:ref_id] = nil
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Affiliate < ActiveRecord::Base
|
2
|
+
belongs_to :partner, :class_name => "User", :foreign_key => :partner_id
|
3
|
+
belongs_to :user
|
4
|
+
has_many :events, :class_name => "AffiliateEvent"
|
5
|
+
|
6
|
+
def name
|
7
|
+
I18n.t(:affiliate_program)
|
8
|
+
end
|
9
|
+
|
10
|
+
def ref_id
|
11
|
+
partner ? partner.ref_id : ''
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
User.class_eval do
|
2
|
+
|
3
|
+
has_many :affiliates, :foreign_key => "partner_id"
|
4
|
+
has_one :affiliate_partner, :class_name => "Affiliate", :foreign_key => "user_id"
|
5
|
+
|
6
|
+
def partner
|
7
|
+
affiliate_partner.partner
|
8
|
+
end
|
9
|
+
|
10
|
+
def ref_id
|
11
|
+
self.id.to_s.reverse
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_or_create_affiliate
|
15
|
+
Affiliate.where(:partner_id => self.id, :affiliate_email => nil).first ||
|
16
|
+
Affiliate.create(:partner => self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_by_ref_id(ref_id)
|
20
|
+
User.find(ref_id.to_s.reverse)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t('affiliate_settings') %></h1>
|
4
|
+
|
5
|
+
<%= form_tag(admin_affiliate_settings_path, :method => :put) do %>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
<label><%= t("sender_credit_on_register_amount") %></label>
|
9
|
+
<%= text_field_tag('preferences[sender_credit_on_register_amount]', Spree::Config[:sender_credit_on_register_amount]) %>
|
10
|
+
</p>
|
11
|
+
<p>
|
12
|
+
<label><%= t('recipient_credit_on_register_amount') %></label>
|
13
|
+
<%= text_field_tag('preferences[recipient_credit_on_register_amount]', Spree::Config[:recipient_credit_on_register_amount])%>
|
14
|
+
</p>
|
15
|
+
<p>
|
16
|
+
<label><%= t("sender_credit_on_purchase_amount") %></label>
|
17
|
+
<%= text_field_tag('preferences[sender_credit_on_purchase_amount]', Spree::Config[:sender_credit_on_purchase_amount]) %>
|
18
|
+
</p>
|
19
|
+
<p>
|
20
|
+
<label><%= t('recipient_credit_on_purchase_amount') %></label>
|
21
|
+
<%= text_field_tag('preferences[recipient_credit_on_purchase_amount]', Spree::Config[:recipient_credit_on_purchase_amount])%>
|
22
|
+
</p>
|
23
|
+
|
24
|
+
<p class="form-buttons">
|
25
|
+
<%= button t('update') %>
|
26
|
+
<%= t("or") %> <%= link_to t("cancel"), admin_affiliate_settings_url %>
|
27
|
+
</p>
|
28
|
+
<% end %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t("affiliate_settings") %></h1>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<tr>
|
7
|
+
<th scope="row"><%= t("sender_credit_on_register_amount") %>:</th>
|
8
|
+
<td><%= number_to_currency Spree::Config[:sender_credit_on_register_amount] %></td>
|
9
|
+
</tr>
|
10
|
+
<tr>
|
11
|
+
<th scope="row"><%= t("recipient_credit_on_register_amount") %>:</th>
|
12
|
+
<td><%= number_to_currency Spree::Config[:recipient_credit_on_register_amount] %></td>
|
13
|
+
</tr>
|
14
|
+
<tr>
|
15
|
+
<th scope="row"><%= t("sender_credit_on_purchase_amount") %>:</th>
|
16
|
+
<td><%= number_to_currency Spree::Config[:sender_credit_on_purchase_amount] %></td>
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<th scope="row"><%= t("recipient_credit_on_purchase_amount") %>:</th>
|
20
|
+
<td><%= number_to_currency Spree::Config[:recipient_credit_on_purchase_amount] %></td>
|
21
|
+
</tr>
|
22
|
+
</table>
|
23
|
+
|
24
|
+
<p><%= link_to_with_icon 'edit', t("edit"), edit_admin_affiliate_settings_path %></p>
|
25
|
+
|
26
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= @mail.recipient_name %>,
|
2
|
+
|
3
|
+
I think you would like this affiliate program.
|
4
|
+
|
5
|
+
<% unless @mail.message.blank? -%>
|
6
|
+
<%= @mail.message %>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
<%= @mail.sender_name %>
|
10
|
+
|
11
|
+
Click the link below to to get store credit after first order:
|
12
|
+
|
13
|
+
<%= link_to root_url(:ref_id => @object.ref_id), root_url(:ref_id => @object.ref_id) %>
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<p>
|
2
|
+
<%= f.label(:sender_name, t('email_to_friend.sender_name')) %><br/>
|
3
|
+
<%= f.text_field(:sender_name) %>
|
4
|
+
</p>
|
5
|
+
<p>
|
6
|
+
<%= f.label(:sender_email, t('email_to_friend.sender_email')) %><br/>
|
7
|
+
<%= f.text_field(:sender_email) %>
|
8
|
+
</p>
|
9
|
+
<p>
|
10
|
+
<%= f.label(:recipient_email, t('email_to_friend.recipient_emails')) %><br/>
|
11
|
+
<%= f.text_field(:recipient_email) %>
|
12
|
+
</p>
|
13
|
+
<p>
|
14
|
+
<%= f.label(:message, t('email_to_friend.message')) %><br/>
|
15
|
+
<%= f.text_area(:message) %>
|
16
|
+
</p>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<p>
|
2
|
+
<strong><%= t('affiliate_link') %>:</strong>
|
3
|
+
<%= link_to root_url(:ref_id => @user.ref_id), root_url(:ref_id => @user.ref_id) %><br />
|
4
|
+
<%= link_to t('send_affiliate_link'), email_to_friend_url('affiliate', current_user.find_or_create_affiliate)
|
5
|
+
%>
|
6
|
+
</p>
|
7
|
+
<% @affiliates = @user.affiliates.where("affiliate_email IS NOT NULL") %>
|
8
|
+
<% if @affiliates.count > 0 %>
|
9
|
+
<h3><%= t('affiliate_links_already_sent_to') %></h3>
|
10
|
+
<ul>
|
11
|
+
<% @affiliates.each do |aff| %>
|
12
|
+
<li><%= aff.affiliate_email %> <%= aff.user_id ? "(#{t(:registered)})" : '' %></li>
|
13
|
+
<% end %>
|
14
|
+
</ul>
|
15
|
+
<% end %>
|
data/config/database.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
development:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: db/cucumber.sqlite3
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
|
7
|
+
test:
|
8
|
+
adapter: sqlite3
|
9
|
+
database: db/test.sqlite3
|
10
|
+
pool: 5
|
11
|
+
timeout: 5000
|
12
|
+
|
13
|
+
cucumber:
|
14
|
+
adapter: sqlite3
|
15
|
+
database: db/cucumber.sqlite3
|
16
|
+
pool: 5
|
17
|
+
timeout: 5000
|
@@ -0,0 +1,38 @@
|
|
1
|
+
TestApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
|
36
|
+
config.action_mailer.default_url_options = { :host => 'testapp.com' }
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
en:
|
2
|
+
affiliate_link: "Affiliate link"
|
3
|
+
affiliate_links_already_sent_to: "Already sent to:"
|
4
|
+
affiliate_program: "Affiliate Program"
|
5
|
+
affiliate_settings: "Affiliate settings"
|
6
|
+
manage_affiliate_settings: "Manage affiliate settings"
|
7
|
+
recipient_credit_on_purchase_amount: "Recipient credit amount (on first order)"
|
8
|
+
recipient_credit_on_register_amount: "Recipient credit amount (on register)"
|
9
|
+
registered: "registered"
|
10
|
+
send_affiliate_link: "Send affiliate link to friend"
|
11
|
+
sender_credit_on_purchase_amount: "Sender credit amount (on recipient's first order)"
|
12
|
+
sender_credit_on_register_amount: "Sender credit amount (on recipient register)"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module AffiliateCredits
|
2
|
+
private
|
3
|
+
|
4
|
+
def create_affiliate_credits(sender, recipient, event)
|
5
|
+
#check if sender should receive credit on affiliate register
|
6
|
+
if sender_credit_amount = Spree::Config["sender_credit_on_#{event}_amount".to_sym] and sender_credit_amount.to_f > 0
|
7
|
+
credit = StoreCredit.create(:amount => sender_credit_amount,
|
8
|
+
:remaining_amount => sender_credit_amount,
|
9
|
+
:reason => "Affiliate: #{event}", :user => sender)
|
10
|
+
|
11
|
+
log_event recipient.affiliate_partner, sender, credit, event
|
12
|
+
end
|
13
|
+
|
14
|
+
#check if affiliate should recevied credit on sign up
|
15
|
+
if recipient_credit_amount = Spree::Config["recipient_credit_on_#{event}_amount".to_sym] and recipient_credit_amount.to_f > 0
|
16
|
+
credit = StoreCredit.create(:amount => recipient_credit_amount,
|
17
|
+
:remaining_amount => recipient_credit_amount,
|
18
|
+
:reason => "Affiliate: #{event}", :user => recipient)
|
19
|
+
|
20
|
+
log_event recipient.affiliate_partner, recipient, credit, event
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def log_event(affiliate, user, credit, event)
|
26
|
+
affiliate.events.create(:reward => credit, :name => event, :user => user)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SpreeAffiliate
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Configures your Rails application for use with spree_affiliate"
|
7
|
+
|
8
|
+
def copy_migrations
|
9
|
+
directory "db"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateAffiliates < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :affiliates do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.integer :partner_id
|
6
|
+
t.string :affiliate_email
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :affiliates
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateAffiliateEvents < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :affiliate_events do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :reward_id
|
6
|
+
t.string :reward_type
|
7
|
+
t.references :affiliate
|
8
|
+
t.references :user
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :affiliate_events
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_affiliate_hooks'
|
3
|
+
|
4
|
+
module SpreeAffiliate
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
def self.activate
|
10
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
11
|
+
Rails.env == "production" ? require(c) : load(c)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
config.to_prepare &method(:activate).to_proc
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class SpreeAffiliateHooks < Spree::ThemeSupport::HookListener
|
2
|
+
insert_after :admin_configurations_menu do
|
3
|
+
"<%= configurations_menu_item(I18n.t('affiliate_settings'), admin_affiliate_settings_path, I18n.t('manage_affiliate_settings')) %>"
|
4
|
+
end
|
5
|
+
|
6
|
+
insert_before :account_my_orders, :partial => 'users/affiliate'
|
7
|
+
|
8
|
+
replace :send_mail_fields, :partial => 'email_sender/fields'
|
9
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# add custom rake tasks here
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
ENV["RAILS_ENV"] ||= 'test'
|
4
|
+
require File.expand_path("../test_app/config/environment", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# == Mock Framework
|
13
|
+
#
|
14
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
15
|
+
#
|
16
|
+
# config.mock_with :mocha
|
17
|
+
# config.mock_with :flexmock
|
18
|
+
# config.mock_with :rr
|
19
|
+
config.mock_with :rspec
|
20
|
+
|
21
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
22
|
+
|
23
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
24
|
+
# examples within a transaction, comment the following line or assign false
|
25
|
+
# instead of true.
|
26
|
+
config.use_transactional_fixtures = true
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
|
6
|
+
s.name = 'spree_affiliate'
|
7
|
+
s.version = '1.0.0'
|
8
|
+
s.authors = ['Rails Dog']
|
9
|
+
s.email = 'gems@railsdog.com'
|
10
|
+
s.homepage = 'http://github.com/spree/spree_affiliate'
|
11
|
+
s.summary = 'Affiliate support for Spree'
|
12
|
+
s.description = 'Affiliate support for Spree'
|
13
|
+
s.required_ruby_version = '>= 1.8.7'
|
14
|
+
s.rubygems_version = '1.3.6'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency('spree_core', '>= 0.40.0')
|
21
|
+
s.add_dependency('spree_auth', '>= 0.40.0')
|
22
|
+
s.add_dependency('spree_store_credits', '>= 1.0.0')
|
23
|
+
s.add_dependency('spree_email_to_friend', '>= 1.0.0')
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_affiliate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rails Dog
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-23 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: spree_core
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 191
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 40
|
33
|
+
- 0
|
34
|
+
version: 0.40.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: spree_auth
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 191
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 40
|
49
|
+
- 0
|
50
|
+
version: 0.40.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: spree_store_credits
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 23
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 0
|
65
|
+
- 0
|
66
|
+
version: 1.0.0
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: spree_email_to_friend
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 0
|
81
|
+
- 0
|
82
|
+
version: 1.0.0
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
description: Affiliate support for Spree
|
86
|
+
email: gems@railsdog.com
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files: []
|
92
|
+
|
93
|
+
files:
|
94
|
+
- .gitignore
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- app/controllers/admin/affiliate_settings_controller.rb
|
99
|
+
- app/controllers/affiliates_controller.rb
|
100
|
+
- app/controllers/checkout_controller_decorator.rb
|
101
|
+
- app/controllers/email_sender_controller_decorator.rb
|
102
|
+
- app/controllers/spree/base_controller_decorator.rb
|
103
|
+
- app/controllers/users_controller_decorator.rb
|
104
|
+
- app/models/affiliate.rb
|
105
|
+
- app/models/affiliate_event.rb
|
106
|
+
- app/models/user_decorator.rb
|
107
|
+
- app/views/admin/affiliate_settings/edit.html.erb
|
108
|
+
- app/views/admin/affiliate_settings/show.html.erb
|
109
|
+
- app/views/affiliates/_mail_to_friend.html.erb
|
110
|
+
- app/views/affiliates/show.html.erb
|
111
|
+
- app/views/email_sender/_fields.html.erb
|
112
|
+
- app/views/users/_affiliate.html.erb
|
113
|
+
- config/database.yml
|
114
|
+
- config/environments/cucumber.rb
|
115
|
+
- config/locales/en.yml
|
116
|
+
- config/routes.rb
|
117
|
+
- lib/affiliate_credits.rb
|
118
|
+
- lib/generators/spree_affiliate/install_generator.rb
|
119
|
+
- lib/generators/templates/db/migrate/20101022121217_create_affiliates.rb
|
120
|
+
- lib/generators/templates/db/migrate/20101104145139_create_affiliate_events.rb
|
121
|
+
- lib/spree_affiliate.rb
|
122
|
+
- lib/spree_affiliate_hooks.rb
|
123
|
+
- lib/tasks/spree_affiliate.rake
|
124
|
+
- spec/models/user_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- spree_affiliate.gemspec
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: http://github.com/spree/spree_affiliate
|
129
|
+
licenses: []
|
130
|
+
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 57
|
142
|
+
segments:
|
143
|
+
- 1
|
144
|
+
- 8
|
145
|
+
- 7
|
146
|
+
version: 1.8.7
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: 3
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
156
|
+
requirements: []
|
157
|
+
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.3.7
|
160
|
+
signing_key:
|
161
|
+
specification_version: 3
|
162
|
+
summary: Affiliate support for Spree
|
163
|
+
test_files:
|
164
|
+
- spec/models/user_spec.rb
|
165
|
+
- spec/spec_helper.rb
|