Permalink
Browse files

Move everything into Spree namespace. Fix admin interface

  • Loading branch information...
1 parent 1432605 commit 5fe520fc57cd49c32cba54392a48dbd6bfafa567 @davidnorth committed Apr 11, 2012
@@ -1,8 +1,8 @@
-class Admin::AffiliateSettingsController < Admin::BaseController
+class Spree::Admin::AffiliateSettingsController < Spree::Admin::BaseController
def update
- Spree::Config.set(params[:preferences])
-
+ SpreeAffiliate::Config.set(params[:preferences])
+
respond_to do |format|
format.html {
redirect_to admin_affiliate_settings_path
@@ -1,4 +1,4 @@
-class AffiliatesController < Spree::BaseController
+class Spree::AffiliatesController < Spree::BaseController
def show
flash[:notice] = request.flash[:notice]
redirect_to account_url
View
@@ -1,13 +0,0 @@
-class Affiliate < ActiveRecord::Base
- belongs_to :partner, :class_name => "User", :foreign_key => :partner_id
- belongs_to :user
- has_many :events, :class_name => "AffiliateEvent"
-
- def name
- I18n.t(:affiliate_program)
- end
-
- def ref_id
- partner ? partner.ref_id : ''
- end
-end
@@ -1,5 +0,0 @@
-class AffiliateEvent < ActiveRecord::Base
- belongs_to :affiliate
- belongs_to :reward, :polymorphic => true
- belongs_to :user
-end
@@ -0,0 +1,13 @@
+class Spree::Affiliate < ActiveRecord::Base
+ belongs_to :partner, :class_name => "Spree::User", :foreign_key => :partner_id
+ belongs_to :user, :class_name => 'Spree::User'
+ has_many :events, :class_name => "Spree::AffiliateEvent"
+
+ def name
+ I18n.t(:affiliate_program)
+ end
+
+ def ref_id
+ partner ? partner.ref_id : ''
+ end
+end
@@ -0,0 +1,5 @@
+class Spree::AffiliateEvent < ActiveRecord::Base
+ belongs_to :affiliate, :class_name => 'Spree::Affiliate'
+ belongs_to :reward, :polymorphic => true
+ belongs_to :user, :class_name => 'Spree::User'
+end
@@ -1,7 +1,7 @@
Spree::User.class_eval do
- has_many :affiliates, :foreign_key => "partner_id"
- has_one :affiliate_partner, :class_name => "Affiliate", :foreign_key => "user_id"
+ has_many :affiliates, :class_name => 'Spree::Affiliate', :foreign_key => "partner_id"
+ has_one :affiliate_partner, :class_name => "Spree::Affiliate", :foreign_key => "user_id"
def partner
affiliate_partner.partner
@@ -12,11 +12,11 @@ def ref_id
end
def find_or_create_affiliate
- Affiliate.where(:partner_id => self.id, :affiliate_email => nil).first ||
- Affiliate.create(:partner => self)
+ Spree::Affiliate.where(:partner_id => self.id, :affiliate_email => nil).first ||
+ Spree::Affiliate.create(:partner => self)
end
def self.find_by_ref_id(ref_id)
- User.find(ref_id.to_s.reverse)
+ Spree::User.find(ref_id.to_s.reverse)
end
end
@@ -0,0 +1,12 @@
+Deface::Override.new(:virtual_path => "spree/admin/configurations/index",
+ :name => "converted_admin_configurations_menu_294924217",
+ :insert_after => "[data-hook='admin_configurations_menu'], #admin_configurations_menu[data-hook]",
+ :text => "<%= configurations_menu_item(I18n.t('affiliate_settings'), spree.admin_affiliate_settings_path, I18n.t('manage_affiliate_settings')) %>")
+
+Deface::Override.new(:virtual_path => "spree/users/show",
+ :name => "converted_account_my_orders_69371225",
+ :insert_before => "[data-hook='account_my_orders'], #account_my_orders[data-hook]",
+ :partial => "spree/users/affiliate")
+
+# I can't find this hook anywhere, so leaving it here, in its deprecated state, so it will still 'work' (I'm not attempting to 'deface' it)
+# replace :send_mail_fields, :partial => 'email_sender/fields'
@@ -1,24 +1,24 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render 'spree/admin/shared/configuration_menu' %>
<h1><%= t('affiliate_settings') %></h1>
<%= form_tag(admin_affiliate_settings_path, :method => :put) do %>
<p>
<label><%= t("sender_credit_on_register_amount") %></label>
- <%= text_field_tag('preferences[sender_credit_on_register_amount]', Spree::Config[:sender_credit_on_register_amount]) %>
+ <%= text_field_tag('preferences[sender_credit_on_register_amount]', SpreeAffiliate::Config[:sender_credit_on_register_amount]) %>
</p>
<p>
<label><%= t('recipient_credit_on_register_amount') %></label>
- <%= text_field_tag('preferences[recipient_credit_on_register_amount]', Spree::Config[:recipient_credit_on_register_amount])%>
+ <%= text_field_tag('preferences[recipient_credit_on_register_amount]', SpreeAffiliate::Config[:recipient_credit_on_register_amount])%>
</p>
<p>
<label><%= t("sender_credit_on_purchase_amount") %></label>
- <%= text_field_tag('preferences[sender_credit_on_purchase_amount]', Spree::Config[:sender_credit_on_purchase_amount]) %>
+ <%= text_field_tag('preferences[sender_credit_on_purchase_amount]', SpreeAffiliate::Config[:sender_credit_on_purchase_amount]) %>
</p>
<p>
<label><%= t('recipient_credit_on_purchase_amount') %></label>
- <%= text_field_tag('preferences[recipient_credit_on_purchase_amount]', Spree::Config[:recipient_credit_on_purchase_amount])%>
+ <%= text_field_tag('preferences[recipient_credit_on_purchase_amount]', SpreeAffiliate::Config[:recipient_credit_on_purchase_amount])%>
</p>
<p class="form-buttons">
@@ -1,23 +1,23 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render 'spree/admin/shared/configuration_menu' %>
<h1><%= t("affiliate_settings") %></h1>
<table>
<tr>
<th scope="row"><%= t("sender_credit_on_register_amount") %>:</th>
- <td><%= number_to_currency Spree::Config[:sender_credit_on_register_amount] %></td>
+ <td><%= number_to_currency SpreeAffiliate::Config[:sender_credit_on_register_amount] %></td>
</tr>
<tr>
<th scope="row"><%= t("recipient_credit_on_register_amount") %>:</th>
- <td><%= number_to_currency Spree::Config[:recipient_credit_on_register_amount] %></td>
+ <td><%= number_to_currency SpreeAffiliate::Config[:recipient_credit_on_register_amount] %></td>
</tr>
<tr>
<th scope="row"><%= t("sender_credit_on_purchase_amount") %>:</th>
- <td><%= number_to_currency Spree::Config[:sender_credit_on_purchase_amount] %></td>
+ <td><%= number_to_currency SpreeAffiliate::Config[:sender_credit_on_purchase_amount] %></td>
</tr>
<tr>
<th scope="row"><%= t("recipient_credit_on_purchase_amount") %>:</th>
- <td><%= number_to_currency Spree::Config[:recipient_credit_on_purchase_amount] %></td>
+ <td><%= number_to_currency SpreeAffiliate::Config[:recipient_credit_on_purchase_amount] %></td>
</tr>
</table>
View
@@ -1,7 +1,7 @@
-Rails.application.routes.draw do
+Spree::Core::Engine.routes.append do
namespace :admin do
resource :affiliate_settings
end
-
+
resources :affiliates, :only => [:show, :index]
end
@@ -1,31 +0,0 @@
-class SpreeAffiliateHooks < Spree::ThemeSupport::HookListener
- def self.perform_deface_customizations
- Deface::Override.new(:virtual_path => "admin/configurations/index",
- :name => "converted_admin_configurations_menu_294924217",
- :insert_after => "[data-hook='admin_configurations_menu'], #admin_configurations_menu[data-hook]",
- :text => "<%= configurations_menu_item(I18n.t('affiliate_settings'), admin_affiliate_settings_path, I18n.t('manage_affiliate_settings')) %>",
- :disabled => false)
-
- Deface::Override.new(:virtual_path => "users/show",
- :name => "converted_account_my_orders_69371225",
- :insert_before => "[data-hook='account_my_orders'], #account_my_orders[data-hook]",
- :partial => "users/affiliate",
- :disabled => false)
-
- # I can't find this hook anywhere, so leaving it here, in its deprecated state, so it will still 'work' (I'm not attempting to 'deface' it)
- replace :send_mail_fields, :partial => 'email_sender/fields'
- end
-
- # detect if we have Deface support
- begin
- Deface::const_get "Deface"
- self.perform_deface_customizations
- rescue NameError
- insert_after :admin_configurations_menu do
- "<%= configurations_menu_item(I18n.t('affiliate_settings'), admin_affiliate_settings_path, I18n.t('manage_affiliate_settings')) %>"
- end
-
- insert_before :account_my_orders, :partial => 'users/affiliate'
- replace :send_mail_fields, :partial => 'email_sender/fields'
- end
-end

0 comments on commit 5fe520f

Please sign in to comment.