spree_promo 0.70.0.rc2 → 0.70.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/LICENSE +1 -1
  2. data/app/assets/javascripts/admin/promotions.js +13 -17
  3. data/app/controllers/admin/promotions_controller.rb +1 -1
  4. data/app/models/calculator/free_shipping.rb +0 -5
  5. data/app/models/promotion.rb +5 -1
  6. data/app/models/promotion_action.rb +0 -2
  7. data/app/models/promotion_rule.rb +0 -2
  8. data/app/views/admin/promotion_actions/create.js.erb +4 -4
  9. data/app/views/admin/promotion_actions/destroy.js.erb +1 -1
  10. data/app/views/admin/promotion_rules/create.js.erb +5 -5
  11. data/app/views/admin/promotion_rules/destroy.js.erb +1 -1
  12. data/app/views/admin/promotions/_actions.html.erb +8 -9
  13. data/app/views/admin/promotions/_form.html.erb +3 -3
  14. data/app/views/admin/promotions/_promotion_action.html.erb +1 -1
  15. data/app/views/admin/promotions/_promotion_rule.html.erb +1 -1
  16. data/app/views/admin/promotions/_rules.html.erb +10 -10
  17. data/app/views/admin/promotions/actions/_create_adjustment.html.erb +2 -2
  18. data/app/views/admin/promotions/actions/_create_line_items.html.erb +13 -23
  19. data/app/views/admin/promotions/edit.html.erb +4 -4
  20. data/app/views/admin/promotions/index.html.erb +10 -10
  21. data/app/views/admin/promotions/new.html.erb +4 -4
  22. data/app/views/admin/promotions/rules/_item_total.html.erb +1 -1
  23. data/app/views/admin/promotions/rules/_landing_page.html.erb +1 -1
  24. data/app/views/admin/promotions/rules/_product.html.erb +3 -3
  25. data/app/views/admin/promotions/rules/_user_logged_in.html.erb +1 -1
  26. data/app/views/products/_promotions.html.erb +3 -3
  27. data/config/locales/en.yml +6 -6
  28. data/lib/spree/promo/environment.rb +9 -0
  29. data/lib/spree_promo.rb +27 -25
  30. metadata +13 -20
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2010, Rails Dog LLC and other contributors
1
+ Copyright (c) 2007-2011, Rails Dog LLC and other contributors
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
@@ -51,24 +51,21 @@ var initProductActions = function(){
51
51
  // Autocomplete product and populate variant select
52
52
  if($('.promotion_action.create_line_items ').is('*')){
53
53
  $(".promotion_action.create_line_items input[name='add_product_name']").autocomplete("/admin/products.json?authenticity_token=" + $('meta[name=csrf-token]').attr("content"), {
54
- parse: prep_autocomplete_data,
54
+ parse: prep_product_autocomplete_data,
55
55
  formatItem: function(item) {
56
- return format_autocomplete(item);
56
+ return format_product_autocomplete(item);
57
57
  }
58
58
  }).result(function(event, data, formatted) {
59
59
  if(data){
60
- // $('#add_product_id').val(data.product.id);
61
- var url = "/admin/products/" + data.product.permalink + "/variants.json?authenticity_token=" + $('meta[name=csrf-token]').attr("content");
62
- var $variant_select = $("select[name='add_line_item_variant_id']");
63
- $variant_select.html('');
64
- $.getJSON(url, {}, function(variants_data){
65
- $.each(variants_data, function(){
66
- $variant_select.append($("<option />").val(this.id).text(this.label));
67
- });
68
- });
60
+ if(data['variant']==undefined){
61
+ // product
62
+ $('#add_line_item_variant_id').val(data['product']['master']['id']);
63
+ }else{
64
+ // variant
65
+ $('#add_line_item_variant_id').val(data['variant']['id']);
66
+ }
69
67
  }
70
- }
71
- );
68
+ });
72
69
  }
73
70
 
74
71
  var hideOrShowItemTables = function(){
@@ -99,15 +96,14 @@ var initProductActions = function(){
99
96
  };
100
97
  setupRemoveLineItems();
101
98
  // Add line item to list
102
- $(".promotion_action.create_line_items button.add").click(function(){
99
+ $(".promotion_action.create_line_items button.add").live('click',function(){
103
100
  var $container = $(this).parents('.promotion_action');
104
101
  var product_name = $container.find("input[name='add_product_name']").val();
105
- var variant_id = $container.find("select[name='add_line_item_variant_id']").val();
106
- var variant_name = $container.find("select[name='add_line_item_variant_id'] option:selected").text();
102
+ var variant_id = $container.find("input[name='add_line_item_variant_id']").val();
107
103
  var quantity = $container.find("input[name='add_quantity']").val();
108
104
  if(variant_id){
109
105
  // Add to the table
110
- var newRow = "<tr><td>" + product_name + "</td><td>" + variant_name + "</td><td>" + quantity + "</td><td><img src='/admin/images/icons/cross.png' /></td></tr>";
106
+ var newRow = "<tr><td>" + product_name + "</td><td>" + quantity + "</td><td><img src='/assets/admin/icons/cross.png' /></td></tr>";
111
107
  $container.find('table').append(newRow);
112
108
  // Add to serialized string in hidden text field
113
109
  var $hiddenField = $container.find("input[type='hidden']");
@@ -16,6 +16,6 @@ class Admin::PromotionsController < Admin::ResourceController
16
16
  end
17
17
 
18
18
  def load_data
19
- @calculators = Promotion::Actions::CreateAdjustment.calculators
19
+ @calculators = Rails.application.config.spree.calculators.promotion_actions_create_adjustments
20
20
  end
21
21
  end
@@ -4,11 +4,6 @@ class Calculator::FreeShipping < ::Calculator
4
4
  I18n.t("free_shipping")
5
5
  end
6
6
 
7
- def self.register
8
- super
9
- Promotion.register_calculator(self)
10
- end
11
-
12
7
  def compute(object)
13
8
  if object.is_a?(Array)
14
9
  return if object.empty?
@@ -31,7 +31,11 @@ class Promotion < Activator
31
31
  validates :name, :presence => true
32
32
  validates :preferred_code, :presence => true, :if => lambda{|r| r.event_name == 'spree.ceckout.coupon_code_added' }
33
33
 
34
- scope :advertised, includes(:stored_preferences).where(:preferences => {:name => 'advertise', :value => '1'})
34
+ class << self
35
+ def advertised
36
+ includes(:stored_preferences).where(:preferences => {:name => 'advertise', :value => '1'})
37
+ end
38
+ end
35
39
 
36
40
  # TODO: Remove that after fix for https://rails.lighthouseapp.com/projects/8994/tickets/4329-has_many-through-association-does-not-link-models-on-association-save
37
41
  # is provided
@@ -1,8 +1,6 @@
1
1
  # Base class for all types of promotion action.
2
2
  # PromotionActions perform the necessary tasks when a promotion is activated by an event and determined to be eligible.
3
3
  class PromotionAction < ActiveRecord::Base
4
- include SubclassRegistration
5
-
6
4
  belongs_to :promotion, :foreign_key => 'activator_id'
7
5
 
8
6
  scope :of_type, lambda {|t| {:conditions => {:type => t}}}
@@ -1,7 +1,5 @@
1
1
  # Base class for all promotion rules
2
2
  class PromotionRule < ActiveRecord::Base
3
- include SubclassRegistration
4
-
5
3
  belongs_to :promotion, :foreign_key => 'activator_id'
6
4
 
7
5
  scope :of_type, lambda {|t| {:conditions => {:type => t}}}
@@ -1,7 +1,7 @@
1
- jQuery('#actions_container').html('<%= escape_javascript( render(:partial => 'admin/promotions/actions') ) %>');
1
+ $('#actions_container').html('<%= escape_javascript( render(:partial => 'admin/promotions/actions') ) %>');
2
2
  initProductActions();
3
3
 
4
- jQuery('#<%= dom_id @promotion_action %>').hide();
5
- jQuery('#<%= dom_id @promotion_action %>').fadeIn();
6
- jQuery('#<%= dom_id @promotion_action %> .tokeninput.products').productPicker();
4
+ $('#<%= dom_id @promotion_action %>').hide();
5
+ $('#<%= dom_id @promotion_action %>').fadeIn();
6
+ $('#<%= dom_id @promotion_action %> .tokeninput.products').productPicker();
7
7
 
@@ -1,2 +1,2 @@
1
- jQuery('#<%= dom_id @promotion_action %>').fadeOut().remove();
1
+ $('#<%= dom_id @promotion_action %>').fadeOut().remove();
2
2
 
@@ -1,6 +1,6 @@
1
- jQuery('#rules').append('<%= escape_javascript( render(:partial => 'admin/promotions/promotion_rule', :object => @promotion_rule) ) %>');
2
- jQuery('#<%= dom_id @promotion_rule %>').hide();
3
- jQuery('#<%= dom_id @promotion_rule %>').fadeIn();
1
+ $('#rules').append('<%= escape_javascript( render(:partial => 'admin/promotions/promotion_rule', :object => @promotion_rule) ) %>');
2
+ $('#<%= dom_id @promotion_rule %>').hide();
3
+ $('#<%= dom_id @promotion_rule %>').fadeIn();
4
4
  initProductRuleSourceField();
5
- jQuery('#<%= dom_id @promotion_rule %> .tokeninput.products').productPicker();
6
- jQuery('#<%= dom_id @promotion_rule %> .tokeninput.users').userPicker();
5
+ $('#<%= dom_id @promotion_rule %> .tokeninput.products').productPicker();
6
+ $('#<%= dom_id @promotion_rule %> .tokeninput.users').userPicker();
@@ -1 +1 @@
1
- jQuery('#<%= dom_id @promotion_rule %>').fadeOut().remove();
1
+ $('#<%= dom_id @promotion_rule %>').fadeOut().remove();
@@ -1,7 +1,7 @@
1
1
  <fieldset id="action_fields">
2
2
  <legend><%= t(:promotion_actions) %></legend>
3
3
 
4
- <%= form_for(@promotion, :url => admin_promotion_path(@promotion), :html => { :method => :put }) do |f| %>
4
+ <%= form_for @promotion, :url => admin_promotion_path(@promotion), :html => { :method => :put } do |f| %>
5
5
  <div id="actions" class="filter_list">
6
6
  <% if @promotion.actions.any? %>
7
7
  <%#= render :partial => 'promotion_action', :collection => @promotion.actions, :locals => {:f => f} %>
@@ -11,22 +11,21 @@
11
11
  <% end %>
12
12
 
13
13
  <% else %>
14
- <!-- <p><%= t('no_actions_added') %></p> -->
14
+ <!-- <p><%= t(:no_actions_added) %></p> -->
15
15
  <% end %>
16
16
  </div>
17
17
  <p class="form-buttons">
18
- <%= button t("update") %>
18
+ <%= button t(:update) %>
19
19
  </p>
20
20
  <% end %>
21
21
 
22
- <%= form_tag(admin_promotion_promotion_actions_path(@promotion), :remote => true, :id => 'new_promotion_action_form') do %>
23
- <% options = options_for_select( PromotionAction.registered_class_names.map {|name| [ t("promotion_action_types.#{name.demodulize.underscore}.name"), name] } ) %>
22
+ <%= form_tag admin_promotion_promotion_actions_path(@promotion), :remote => true, :id => 'new_promotion_action_form' do %>
23
+ <% options = options_for_select( Rails.application.config.spree.promotions.actions.map(&:name).map {|name| [ t("promotion_action_types.#{name.demodulize.underscore}.name"), name] } ) %>
24
24
  <p>
25
- <label for="promotion_action_type"><%= t('add_action_of_type') %></label>
26
- <%= select_tag("promotion_action[type]", options) %>
27
- <input type="submit" value="<%= t('add') %>" />
25
+ <%= label_tag :promotion_action_type, t(:add_action_of_type) %>
26
+ <%= select_tag 'promotion_action[type]', options %>
27
+ <%= submit_tag t(:add) %>
28
28
  </p>
29
29
  <% end %>
30
30
 
31
31
  </fieldset>
32
-
@@ -1,4 +1,4 @@
1
- <%= render "shared/error_messages", :target => @promotion %>
1
+ <%= render 'shared/error_messages', :target => @promotion %>
2
2
  <fieldset id="general_fields">
3
3
  <legend><%= t(:general) %></legend>
4
4
  <%= f.field_container :name do %>
@@ -18,12 +18,12 @@
18
18
 
19
19
  <%= f.field_container :description do %>
20
20
  <%= f.label :description %><br />
21
- <%= f.text_area :description, :style => "height:50px" %>
21
+ <%= f.text_area :description, :style => "height:50px;" %>
22
22
  <% end %>
23
23
 
24
24
  <%= f.field_container :preferred_advertise do %>
25
25
  <%= f.check_box :preferred_advertise %>
26
- <%= f.label :preferred_advertise, t('advertise') %>
26
+ <%= f.label :preferred_advertise, t(:advertise) %>
27
27
  <% end %>
28
28
 
29
29
  </fieldset>
@@ -6,7 +6,7 @@
6
6
  <% type_name = promotion_action.class.name.demodulize.underscore %>
7
7
  <% param_prefix = "promotion[promotion_actions_attributes][#{promotion_action.id}]" %>
8
8
  <%#= hidden_field_tag "#{param_prefix}[id]", promotion_action.id %>
9
- <p><%= t "promotion_action_types.#{type_name}.description" %></p>
9
+ <p><%= t("promotion_action_types.#{type_name}.description") %></p>
10
10
 
11
11
  <%= render "admin/promotions/actions/#{type_name}", :action_form => action_form, :promotion_action => promotion_action, :param_prefix => param_prefix %>
12
12
  </div>
@@ -3,6 +3,6 @@
3
3
  <% type_name = promotion_rule.class.name.demodulize.underscore %>
4
4
  <% param_prefix = "promotion[promotion_rules_attributes][#{promotion_rule.id}]" %>
5
5
  <%= hidden_field_tag "#{param_prefix}[id]", promotion_rule.id %>
6
- <p><%= t "promotion_rule_types.#{type_name}.description" %></p>
6
+ <p><%= t("promotion_rule_types.#{type_name}.description") %></p>
7
7
  <%= render "admin/promotions/rules/#{type_name}", :promotion_rule => promotion_rule, :param_prefix => param_prefix %>
8
8
  </div>
@@ -1,9 +1,9 @@
1
1
  <fieldset id="rule_fields">
2
2
  <legend><%= t(:rules) %></legend>
3
3
 
4
- <%= form_for(@promotion, :url => object_url, :html => { :method => :put }) do |f| %>
4
+ <%= form_for @promotion, :url => object_url, :html => { :method => :put } do |f| %>
5
5
  <p>
6
- <% for policy in Promotion::MATCH_POLICIES %>
6
+ <% Promotion::MATCH_POLICIES.each do |policy| %>
7
7
  <label><%= f.radio_button :preferred_match_policy, policy %> <%= t "promotion_form.match_policies.#{policy}" %></label> &nbsp;
8
8
  <% end %>
9
9
  </p>
@@ -11,21 +11,21 @@
11
11
  <% if @promotion.rules.any? %>
12
12
  <%= render :partial => 'promotion_rule', :collection => @promotion.rules, :locals => {} %>
13
13
  <% else %>
14
- <!-- <p><%= t('no_rules_added') %></p> -->
14
+ <!-- <p><%= t(:no_rules_added) %></p> -->
15
15
  <% end %>
16
16
  </div>
17
17
  <p class="form-buttons">
18
- <%= button t("update") %>
18
+ <%= button t(:update) %>
19
19
  </p>
20
20
  <% end %>
21
21
 
22
- <%= form_tag(admin_promotion_promotion_rules_path(@promotion), :remote => true,
23
- :id => 'new_product_rule_form') do %>
24
- <% options = options_for_select( PromotionRule.registered_class_names.map {|name| [ t("promotion_rule_types.#{name.demodulize.underscore}.name"), name] } ) %>
22
+ <%= form_tag admin_promotion_promotion_rules_path(@promotion), :remote => true,
23
+ :id => 'new_product_rule_form' do %>
24
+ <% options = options_for_select( Rails.application.config.spree.promotions.rules.map(&:name).map {|name| [ t("promotion_rule_types.#{name.demodulize.underscore}.name"), name] } ) %>
25
25
  <p>
26
- <label for="promotion_rule_type"><%= t('add_rule_of_type') %></label>
27
- <%= select_tag("promotion_rule[type]", options) %>
28
- <input type="submit" value="<%= t('add') %>" />
26
+ <%= label_tag :promotion_rule_type, t(:add_rule_of_type) %>
27
+ <%= select_tag('promotion_rule[type]', options) %>
28
+ <%= submit_tag t(:add) %>
29
29
  </p>
30
30
  <% end %>
31
31
 
@@ -1,10 +1,10 @@
1
1
  <div class="calculator-fields">
2
2
 
3
3
  <p class="field">
4
- <%= action_form.label :calculator_type, t("calculator") %>
4
+ <%= action_form.label :calculator_type, t(:calculator) %>
5
5
  <%= action_form.collection_select :calculator_type, @calculators, :to_s, :description, {}, {:class => 'type-select'} %>
6
6
  <% if promotion_action.calculator.respond_to?(:preferences) %>
7
- &nbsp; <span class="warning"><%= t('calculator_settings_warning')%></span>
7
+ &nbsp; <span class="warning"><%= t(:calculator_settings_warning)%></span>
8
8
  <% end %>
9
9
  </p>
10
10
 
@@ -1,51 +1,41 @@
1
1
  <table class="index">
2
2
  <tr>
3
- <th>Product</th>
4
- <th>Variant</th>
5
- <th>Quantity</th>
3
+ <th><%= t(:product) %></th>
4
+ <th><%= t(:qty) %></th>
6
5
  <th>&nbsp;</th>
7
6
  </tr>
8
- <% for item in promotion_action.promotion_action_line_items %>
7
+ <% promotion_action.promotion_action_line_items.each do |item| %>
9
8
  <tr>
10
9
  <td>
11
- <%= item.variant.product.name %>
12
- </td>
13
- <td>
14
- <%= item.variant.options_text.presence || t("master") %>
10
+ <%= item.variant.product.name %> <%= item.variant.options_text %>
15
11
  </td>
16
12
  <td>
17
13
  <%= item.quantity %>
18
14
  </td>
19
15
  <td>
20
- <img src='/admin/images/icons/cross.png' />
16
+ <%= image_tag 'admin/icons/cross.png' %>
21
17
  </td>
22
18
  </tr>
23
19
  <% end %>
24
20
  </table>
25
21
 
26
-
27
-
28
22
  <%= action_form.hidden_field :line_items_string %>
29
23
 
30
-
31
24
  <div class="add-line-item">
32
25
  <fieldset>
33
- <legend><%= t('add_product') %></legend>
34
- <div style="float:left;width:50%;margin-right:5%;">
35
- <%= label_tag :add_product_name, t("name_or_sku") %>
26
+ <legend><%= t(:add_product) %></legend>
27
+ <div style="float:left; width:50%; margin-right:5%;">
28
+ <%= label_tag :add_product_name, t(:name_or_sku) %>
36
29
  <%= text_field_tag :add_product_name, nil, :class => 'fullwidth' %>
30
+ <%= hidden_field_tag :add_line_item_variant_id %>
37
31
  </div>
38
- <div style="float:left;width:10%;margin-right:5%;">
39
- <%= label_tag :add_line_item_variant_id, t("variant") %><br />
40
- <select name="add_line_item_variant_id" class="fullwidth"></select>
41
- </div>
42
- <div style="float:left;width:10%;margin-right:5%;">
43
- <%= label_tag :add_quantity, t("qty") %>
32
+ <div style="float:left; width:10%; margin-right:5%;">
33
+ <%= label_tag :add_quantity, t(:qty) %>
44
34
  <%= text_field_tag :add_quantity, 1 %>
45
35
  </div>
46
- <div style="float:left;width:j0%">
36
+ <div style="float:left; width:j0%">
47
37
  &nbsp;<br />
48
- <button class="add small"> <%= t("add") %></button>
38
+ <button class="add small"> <%= t(:add) %></button>
49
39
  </div>
50
40
 
51
41
  </fieldset>
@@ -1,8 +1,8 @@
1
- <h1><%= t("editing_promotion") %></h1>
1
+ <h1><%= t(:editing_promotion) %></h1>
2
2
 
3
- <%= form_for(@promotion, :url => object_url, :html => { :method => :put }) do |f| %>
4
- <%= render :partial => "form", :locals => { :f => f } %>
5
- <%= render "admin/shared/edit_resource_links" %>
3
+ <%= form_for @promotion, :url => object_url, :html => { :method => :put } do |f| %>
4
+ <%= render :partial => 'form', :locals => { :f => f } %>
5
+ <%= render 'admin/shared/edit_resource_links' %>
6
6
  <% end %>
7
7
 
8
8
  <%= render 'rules' %>
@@ -1,27 +1,27 @@
1
1
  <div class='toolbar'>
2
2
  <ul class='actions'>
3
3
  <li>
4
- <%= button_link_to t("new_promotion"), new_object_url, :icon => 'add' %>
4
+ <%= button_link_to t(:new_promotion), new_object_url, :icon => 'add' %>
5
5
  </li>
6
6
  </ul>
7
- <br class='clear' />
7
+ <br class="clear" />
8
8
  </div>
9
9
 
10
- <h1><%= t("promotions") %></h1>
10
+ <h1><%= t(:promotions) %></h1>
11
11
 
12
12
  <table class="index">
13
13
  <thead>
14
14
  <tr>
15
- <th><%= t("name") %></th>
16
- <th><%= t("code") %></th>
17
- <th><%= t("description") %></th>
18
- <th><%= t("usage_limit") %></th>
19
- <th><%= t("expiration") %></th>
20
- <th width="150"><%= t("action") %></th>
15
+ <th><%= t(:name) %></th>
16
+ <th><%= t(:code) %></th>
17
+ <th><%= t(:description) %></th>
18
+ <th><%= t(:usage_limit) %></th>
19
+ <th><%= t(:expiration) %></th>
20
+ <th style="width:150px;"><%= t(:action) %></th>
21
21
  </tr>
22
22
  </thead>
23
23
  <tbody>
24
- <% for promotion in @promotions %>
24
+ <% @promotions.each do |promotion| %>
25
25
  <tr id="<%= dom_id promotion %>">
26
26
  <td><%= promotion.name %></td>
27
27
  <td><%= promotion.code %></td>
@@ -1,6 +1,6 @@
1
- <h1><%= t("new_promotion") %></h1>
1
+ <h1><%= t(:new_promotion) %></h1>
2
2
 
3
- <%= form_for(:promotion, :url => collection_url) do |f| %>
4
- <%= render :partial => "form", :locals => { :f => f } %>
5
- <%= render :partial => "admin/shared/new_resource_links" %>
3
+ <%= form_for :promotion, :url => collection_url do |f| %>
4
+ <%= render :partial => 'form', :locals => { :f => f } %>
5
+ <%= render :partial => 'admin/shared/new_resource_links' %>
6
6
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <p class="field">
2
2
  <label for="<%= "#{param_prefix}_preferred_amount" %>">
3
- Item total must be
3
+ <%= t('promotion_rule_types.item_total.description') %>
4
4
  <%= select_tag "#{param_prefix}[preferred_operator]", options_for_select(Promotion::Rules::ItemTotal::OPERATORS.map{|o| [t("item_total_rule.operators.#{o}"),o]}, promotion_rule.preferred_operator) %>
5
5
  <%= text_field_tag "#{param_prefix}[preferred_amount]", promotion_rule.preferred_amount, :size => 10 %>
6
6
  </label>
@@ -1,6 +1,6 @@
1
1
  <p class="field">
2
2
  <label for="<%= "#{param_prefix}_preferred_path" %>">
3
- User must have visited the path:
3
+ <%= t('promotion_rule_types.landing_page.description') %>:
4
4
  <%= t('landing_page_rule.must_have_visited_path') %>
5
5
  <%= text_field_tag "#{param_prefix}[preferred_path]", promotion_rule.preferred_path, :size => 10 %>
6
6
  </label>
@@ -1,9 +1,9 @@
1
1
  <p class="field products_rule_products_source_field">
2
2
  <label><%= radio_button_tag "#{param_prefix}[products_source]", :manual, promotion_rule.product_group.nil? %> <%= t "product_rule.product_source.manual" %></label> &nbsp;
3
- <label><%= radio_button_tag "#{param_prefix}[products_source]", :group, promotion_rule.product_group.present? %> <%= t "product_rule.product_source.group" %></label>
3
+ <label><%= radio_button_tag "#{param_prefix}[products_source]", :group, promotion_rule.product_group.present? %> <%= t('product_rule.product_source.group') %></label>
4
4
  </p>
5
5
  <p class="field products_rule_product_group">
6
- <label><%= t('product_group') %><br />
6
+ <label><%= t(:product_group) %><br />
7
7
  <%= select_tag "#{param_prefix}[product_group_id]", options_from_collection_for_select(ProductGroup.all, :id, :name, promotion_rule.product_group_id) %></label>
8
8
  </p>
9
9
  <p class="field products_rule_products">
@@ -13,6 +13,6 @@
13
13
  </p>
14
14
  <p>
15
15
  <label>
16
- <%= t("product_rule.label", :select => select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Promotion::Rules::Product::MATCH_POLICIES.map{|s| [t("product_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy))).html_safe %>
16
+ <%= t('product_rule.label', :select => select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Promotion::Rules::Product::MATCH_POLICIES.map{|s| [t("product_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy))).html_safe %>
17
17
  </label>
18
18
  </p>
@@ -1,3 +1,3 @@
1
1
  <%# the spree promo code requires a partial exist. That's why there's not much here %>
2
- <p class="field"><label>User must be logged in</label></p>
2
+ <p class="field"><%= label_tag nil, t('promotion_rule_types.user_logged_in.description') %></p>
3
3
 
@@ -1,15 +1,15 @@
1
1
  <% promotions = @product.possible_promotions %>
2
2
  <% if promotions.any? %>
3
3
  <div id="promotions">
4
- <h3><%= t 'promotions' %></h3>
4
+ <h3><%= t(:promotions) %></h3>
5
5
 
6
- <% for promotion in promotions %>
6
+ <% promotions.each do |promotion| %>
7
7
  <div>
8
8
  <h4><%= promotion.name %></h4>
9
9
  <p><%= promotion.description %></p>
10
10
  <% if promotion.products.any? %>
11
11
  <ul>
12
- <% for product in promotion.products %>
12
+ <% promotion.products.each do |product| %>
13
13
  <li><%= link_to product.name, product_path(product) %></li>
14
14
  <% end %>
15
15
  </ul>
@@ -3,12 +3,12 @@ en:
3
3
  activemodel:
4
4
  attributes:
5
5
  promotion:
6
- name: "Name"
7
- description: "Description"
8
- code: "Code"
9
- usage_limit: "Usage limit"
10
- starts_at: "Starts at"
11
- expires_at: "Expires at"
6
+ name: Name
7
+ description: Description
8
+ code: Code
9
+ usage_limit: Usage limit
10
+ starts_at: Starts at
11
+ expires_at: Expires at
12
12
  add_action_of_type: Add action of type
13
13
  add_rule_of_type: Add rule of type
14
14
  advertise: Advertise
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ module Promo
3
+ class Environment
4
+ include EnvironmentExtension
5
+
6
+ attr_accessor :rules, :actions
7
+ end
8
+ end
9
+ end
data/lib/spree_promo.rb CHANGED
@@ -19,38 +19,40 @@ module SpreePromo
19
19
  {:user => current_user, :order => current_order, :visited_paths => session[:visited_paths]}
20
20
  end
21
21
  end
22
+ end
23
+
24
+ config.autoload_paths += %W(#{config.root}/lib)
25
+ config.to_prepare &method(:activate).to_proc
26
+
27
+ initializer "spree.promo.environment", :after => "spree.environment" do |app|
28
+ app.config.spree.add_class('promotions')
29
+ app.config.spree.promotions = Spree::Promo::Environment.new
30
+ end
22
31
 
23
- if Activator.table_exists?
24
- # register promotion rules and actions
25
- [Promotion::Rules::ItemTotal,
32
+ initializer "spree.promo.register.promotion.calculators" do |app|
33
+ app.config.spree.calculators.add_class('promotion_actions_create_adjustments')
34
+ app.config.spree.calculators.promotion_actions_create_adjustments = [
35
+ Calculator::FlatPercentItemTotal,
36
+ Calculator::FlatRate,
37
+ Calculator::FlexiRate,
38
+ Calculator::PerItem,
39
+ Calculator::FreeShipping
40
+ ]
41
+ end
42
+
43
+ initializer "spree.promo.register.promotions.rules" do |app|
44
+ app.config.spree.promotions.rules = [Promotion::Rules::ItemTotal,
26
45
  Promotion::Rules::Product,
27
46
  Promotion::Rules::User,
28
47
  Promotion::Rules::FirstOrder,
29
48
  Promotion::Rules::LandingPage,
30
- Promotion::Rules::UserLoggedIn,
31
- Promotion::Actions::CreateAdjustment,
32
- Promotion::Actions::CreateLineItems
33
- ].each &:register
34
-
35
- # register default promotion calculators
36
- [
37
- Calculator::FlatPercentItemTotal,
38
- Calculator::FlatRate,
39
- Calculator::FlexiRate,
40
- Calculator::PerItem,
41
- Calculator::FreeShipping
42
- ].each{|c_model|
43
- begin
44
- Promotion::Actions::CreateAdjustment.register_calculator(c_model) if c_model.table_exists?
45
- rescue Exception => e
46
- $stderr.puts "Error registering promotion calculator #{c_model}"
47
- end
48
- }
49
- end
49
+ Promotion::Rules::UserLoggedIn]
50
+ end
50
51
 
52
+ initializer "spree.promo.register.promotions.actions" do |app|
53
+ app.config.spree.promotions.actions = [Promotion::Actions::CreateAdjustment,
54
+ Promotion::Actions::CreateLineItems]
51
55
  end
52
56
 
53
- config.autoload_paths += %W(#{config.root}/lib)
54
- config.to_prepare &method(:activate).to_proc
55
57
  end
56
58
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_promo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15425137
5
- prerelease: 7
4
+ hash: 263
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 70
9
9
  - 0
10
- - rc
11
- - 2
12
- version: 0.70.0.rc2
10
+ version: 0.70.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - David North
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2011-09-30 00:00:00 Z
18
+ date: 2011-10-07 00:00:00 Z
21
19
  dependencies:
22
20
  - !ruby/object:Gem::Dependency
23
21
  type: :runtime
@@ -27,14 +25,12 @@ dependencies:
27
25
  requirements:
28
26
  - - "="
29
27
  - !ruby/object:Gem::Version
30
- hash: 15425137
28
+ hash: 263
31
29
  segments:
32
30
  - 0
33
31
  - 70
34
32
  - 0
35
- - rc
36
- - 2
37
- version: 0.70.0.rc2
33
+ version: 0.70.0
38
34
  version_requirements: *id001
39
35
  name: spree_core
40
36
  - !ruby/object:Gem::Dependency
@@ -45,14 +41,12 @@ dependencies:
45
41
  requirements:
46
42
  - - "="
47
43
  - !ruby/object:Gem::Version
48
- hash: 15425137
44
+ hash: 263
49
45
  segments:
50
46
  - 0
51
47
  - 70
52
48
  - 0
53
- - rc
54
- - 2
55
- version: 0.70.0.rc2
49
+ version: 0.70.0
56
50
  version_requirements: *id002
57
51
  name: spree_auth
58
52
  description: Required dependency for Spree
@@ -123,6 +117,7 @@ files:
123
117
  - config/cucumber.yml
124
118
  - config/locales/en.yml
125
119
  - config/routes.rb
120
+ - lib/spree/promo/environment.rb
126
121
  - lib/spree_promo.rb
127
122
  - lib/tasks/promotions.rake
128
123
  - lib/tasks/promotions_extension_tasks.rake
@@ -158,14 +153,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
153
  required_rubygems_version: !ruby/object:Gem::Requirement
159
154
  none: false
160
155
  requirements:
161
- - - ">"
156
+ - - ">="
162
157
  - !ruby/object:Gem::Version
163
- hash: 25
158
+ hash: 3
164
159
  segments:
165
- - 1
166
- - 3
167
- - 1
168
- version: 1.3.1
160
+ - 0
161
+ version: "0"
169
162
  requirements:
170
163
  - none
171
164
  rubyforge_project: spree_promo