spree_promo 1.0.7 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,3 @@
1
-
2
- var initProductRuleSourceField = function(){
3
-
4
- $products_source_field = jQuery('.products_rule_products_source_field input');
5
- $products_source_field.click(function() {
6
- $rule_container = jQuery(this).parents('.promotion_rule');
7
- if(this.checked){
8
- if(this.value == 'manual'){
9
- $rule_container.find('.products_rule_products').show();
10
- $rule_container.find('.products_rule_product_group').hide();
11
- } else {
12
- $rule_container.find('.products_rule_products').hide();
13
- $rule_container.find('.products_rule_product_group').show();
14
- }
15
- }
16
- });
17
- $products_source_field.each(function() {
18
- $(this).triggerHandler('click');
19
- });
20
-
21
- };
22
-
23
1
  var initProductActions = function(){
24
2
 
25
3
  $("#add_product_name").product_autocomplete();
@@ -100,7 +78,6 @@ var initProductActions = function(){
100
78
  }
101
79
 
102
80
  $(document).ready(function() {
103
- initProductRuleSourceField();
104
81
  initProductActions();
105
82
 
106
83
  // toggle fields for specific events
@@ -3,7 +3,11 @@ class Spree::Admin::PromotionRulesController < Spree::Admin::BaseController
3
3
 
4
4
  def create
5
5
  @promotion = Spree::Promotion.find(params[:promotion_id])
6
- @promotion_rule = params[:promotion_rule][:type].constantize.new(params[:promotion_rule])
6
+ # Remove type key from this hash so that we don't attempt
7
+ # to set it when creating a new record, as this is raises
8
+ # an error in ActiveRecord 3.2.
9
+ promotion_rule_type = params[:promotion_rule].delete(:type)
10
+ @promotion_rule = promotion_rule_type.constantize.new(params[:promotion_rule])
7
11
  @promotion_rule.promotion = @promotion
8
12
  if @promotion_rule.save
9
13
  flash.notice = I18n.t(:successfully_created, :resource => I18n.t(:promotion_rule))
@@ -6,9 +6,14 @@ module Spree
6
6
 
7
7
  protected
8
8
  def build_resource
9
- @promotion = Promotion.new(params[:promotion])
10
- if params[:promotion] && params[:promotion][:calculator_type]
11
- @promotion.calculator = params[:promotion][:calculator_type].constantize.new
9
+ if params[:promotion]
10
+ calculator_type = params[:promotion].delete(:calculator_type)
11
+ @promotion = Promotion.new(params[:promotion])
12
+ if calculator_type
13
+ @promotion.calculator = calculator_type.constantize.new
14
+ end
15
+ else
16
+ @promotion = Promotion.new
12
17
  end
13
18
  @promotion
14
19
  end
@@ -22,4 +27,4 @@ module Spree
22
27
  end
23
28
  end
24
29
  end
25
- end
30
+ end
@@ -2,8 +2,7 @@ Spree::Product.class_eval do
2
2
  has_and_belongs_to_many :promotion_rules, :join_table => 'spree_products_promotion_rules'
3
3
 
4
4
  def possible_promotions
5
- rules_with_matching_product_groups = product_groups.map(&:promotion_rules).flatten
6
- all_rules = promotion_rules + rules_with_matching_product_groups
5
+ all_rules = promotion_rules
7
6
  promotion_ids = all_rules.map(&:activator_id).uniq
8
7
  Spree::Promotion.advertised.where(:id => promotion_ids)
9
8
  end
@@ -21,13 +21,12 @@ module Spree
21
21
  # set to false if the amount is 0
22
22
  def create_adjustment(label, target, calculable, mandatory=false)
23
23
  amount = compute_amount(calculable)
24
- target.adjustments.create({
25
- :amount => amount,
26
- :source => calculable,
27
- :originator => self,
28
- :label => label,
29
- :mandatory => mandatory
30
- }, :without_protection => true)
24
+ params = { :amount => amount,
25
+ :source => calculable,
26
+ :originator => self,
27
+ :label => label,
28
+ :mandatory => mandatory }
29
+ target.adjustments.create(params, :without_protection => true)
31
30
  end
32
31
 
33
32
  # Ensure a negative amount which does not exceed the sum of the order's item_total and ship_total
@@ -23,10 +23,7 @@ module Spree
23
23
  value.to_s.split(',').each do |str|
24
24
  variant_id, quantity = str.split('x')
25
25
  if variant_id && quantity && variant = Variant.find_by_id(variant_id)
26
- promotion_action_line_items.create({
27
- :variant => variant,
28
- :quantity => quantity.to_i,
29
- }, :without_protection => true)
26
+ promotion_action_line_items.create({:variant => variant, :quantity => quantity.to_i}, :without_protection => true)
30
27
  end
31
28
  end
32
29
  end
@@ -4,6 +4,8 @@ module Spree
4
4
  preference :amount, :decimal, :default => 100.00
5
5
  preference :operator, :string, :default => '>'
6
6
 
7
+ attr_accessible :preferred_amount, :preferred_operator
8
+
7
9
  OPERATORS = ['gt', 'gte']
8
10
 
9
11
  def eligible?(order, options = {})
@@ -3,7 +3,6 @@
3
3
  # Valid products either come from assigned product group or are assingned directly to the rule.
4
4
  module Spree
5
5
  class Promotion::Rules::Product < PromotionRule
6
- belongs_to :product_group
7
6
  has_and_belongs_to_many :products, :class_name => '::Spree::Product', :join_table => 'spree_products_promotion_rules', :foreign_key => 'promotion_rule_id'
8
7
 
9
8
  MATCH_POLICIES = %w(any all)
@@ -11,7 +10,7 @@ module Spree
11
10
 
12
11
  # scope/association that is used to test eligibility
13
12
  def eligible_products
14
- product_group ? product_group.products : products
13
+ products
15
14
  end
16
15
 
17
16
  def eligible?(order, options = {})
@@ -23,12 +22,6 @@ module Spree
23
22
  end
24
23
  end
25
24
 
26
- def products_source=(source)
27
- if source.to_s == 'manual'
28
- self.product_group_id = nil
29
- end
30
- end
31
-
32
25
  def product_ids_string
33
26
  product_ids.join(',')
34
27
  end
@@ -15,9 +15,9 @@ module Spree
15
15
  accepts_nested_attributes_for :promotion_actions
16
16
 
17
17
  attr_accessible :name, :event_name, :code, :match_policy,
18
- :path, :advertise, :description, :usage_limit,
19
- :starts_at, :expires_at, :promotion_rules_attributes,
20
- :promotion_actions_attributes
18
+ :path, :advertise, :description, :usage_limit,
19
+ :starts_at, :expires_at, :promotion_rules_attributes,
20
+ :promotion_actions_attributes
21
21
 
22
22
  # TODO: This shouldn't be necessary with :autosave option but nested attribute updating of actions is broken without it
23
23
  after_save :save_rules_and_actions
@@ -30,17 +30,15 @@ module Spree
30
30
  validates :path, :presence => true, :if => lambda{|r| r.event_name == 'spree.content.visited' }
31
31
  validates :usage_limit, :numericality => { :greater_than => 0, :allow_nil => true }
32
32
 
33
- class << self
34
- def advertised
35
- where(:advertise => true)
36
- end
33
+ def self.advertised
34
+ where(:advertise => true)
37
35
  end
38
36
 
39
37
  # 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
40
38
  # is provided
41
39
  def save(*)
42
40
  if super
43
- promotion_rules.each { |p| p.save }
41
+ promotion_rules.each(&:save)
44
42
  end
45
43
  end
46
44
 
@@ -6,8 +6,6 @@ module Spree
6
6
 
7
7
  scope :of_type, lambda {|t| {:conditions => {:type => t}}}
8
8
 
9
- attr_accessible :line_items_string, :calculator_type, :calculator_attributes
10
-
11
9
  # This method should be overriden in subclass
12
10
  # Updates the state of the order or performs some other action depending on the subclass
13
11
  # options will contain the payload from the event that activated the promotion. This will include
@@ -8,7 +8,7 @@ module Spree
8
8
  validate :promotion, :presence => true
9
9
  validate :unique_per_activator, :on => :create
10
10
 
11
- attr_accessible :preferred_operator, :preferred_amount, :product, :product_ids_string, :preferred_match_policy
11
+ attr_accessible :preferred_operator, :preferred_amount
12
12
 
13
13
  def eligible?(order, options = {})
14
14
  raise 'eligible? should be implemented in a sub-class of Promotion::PromotionRule'
@@ -1,7 +1,6 @@
1
1
  $('#rules').append('<%= escape_javascript( render(:partial => 'spree/admin/promotions/promotion_rule', :object => @promotion_rule) ) %>');
2
2
  $('#<%= dom_id @promotion_rule %>').hide();
3
3
  $('#<%= dom_id @promotion_rule %>').fadeIn();
4
- initProductRuleSourceField();
5
4
  $('#<%= dom_id @promotion_rule %> .tokeninput.products').productPicker();
6
5
  $('#<%= dom_id @promotion_rule %> .tokeninput.users').userPicker();
7
6
 
@@ -7,17 +7,17 @@
7
7
  <% end %>
8
8
 
9
9
  <%= f.field_container :event_name do %>
10
- <%= f.label :event_name, t(:event) %><br />
10
+ <%= f.label :event_name %><br />
11
11
  <%= f.select :event_name, Spree::Activator.event_names.map{|name| [t("events.#{name}"), name] } %>
12
12
  <% end %>
13
13
 
14
14
  <%= f.field_container :code do %>
15
- <%= f.label :code, t(:code) %><br />
15
+ <%= f.label :code %><br />
16
16
  <%= f.text_field :code %>
17
17
  <% end %>
18
18
 
19
19
  <%= f.field_container :path do %>
20
- <%= f.label :path, t(:path) %><br />
20
+ <%= f.label :path %><br />
21
21
  <%= f.text_field :path %>
22
22
  <% end %>
23
23
 
@@ -28,7 +28,7 @@
28
28
 
29
29
  <%= f.field_container :advertise do %>
30
30
  <%= f.check_box :advertise %>
31
- <%= f.label :advertise, t(:advertise) %>
31
+ <%= f.label :advertise %>
32
32
  <% end %>
33
33
 
34
34
  </fieldset>
@@ -36,7 +36,7 @@
36
36
  <fieldset id="expiry_fields">
37
37
  <legend><%= t(:expiry) %></legend>
38
38
  <p>
39
- <%= f.label :usage_limit, t(:usage_limit) %><br />
39
+ <%= f.label :usage_limit %><br />
40
40
  <%= f.text_field :usage_limit %>
41
41
  </p>
42
42
 
@@ -15,7 +15,7 @@
15
15
  <div class="settings">
16
16
  <% promotion_action.calculator.preferences.keys.map do |key| %>
17
17
  <% field_name = "#{param_prefix}[calculator_attributes][preferred_#{key}]" %>
18
- <%= label_tag field_name, key.to_s.titleize %>
18
+ <%= label_tag field_name, t(key.to_s) %>
19
19
  <%= preference_field_tag(field_name,
20
20
  promotion_action.calculator.get_preference(key),
21
21
  :type => promotion_action.calculator.preference_type(key)) %>
@@ -24,4 +24,4 @@
24
24
  </div>
25
25
  <% end %>
26
26
 
27
- </div>
27
+ </div>
@@ -36,9 +36,8 @@
36
36
  <%= text_field_tag :add_quantity, 1 %>
37
37
  </div>
38
38
  <div style="float:left; width:j0%">
39
- <button class="add small">
40
- <span><%= t(:add) %></span>
41
- </button>
39
+ &nbsp;<br />
40
+ <button class="add small"> <%= t(:add) %></button>
42
41
  </div>
43
42
  </fieldset>
44
43
  </div>
@@ -22,7 +22,7 @@
22
22
  </thead>
23
23
  <tbody>
24
24
  <% @promotions.each do |promotion| %>
25
- <tr id="<%= dom_id promotion %>">
25
+ <tr id="<%= spree_dom_id promotion %>">
26
26
  <td><%= promotion.name %></td>
27
27
  <td><%= promotion.code %></td>
28
28
  <td><%= promotion.description %></td>
@@ -1,19 +1,10 @@
1
- <p class="field products_rule_products_source_field">
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>
4
- </p>
5
- <p class="field products_rule_product_group">
6
- <label><%= t(:product_group) %><br />
7
- <%= select_tag "#{param_prefix}[product_group_id]", options_from_collection_for_select(Spree::ProductGroup.all, :id, :name, promotion_rule.product_group_id), { :include_blank => true } %></label>
8
- </p>
9
1
  <p class="field products_rule_products">
10
2
  <label>
11
3
  <%= t('product_rule.choose_products') %><br />
12
4
  <%= product_picker_field "#{param_prefix}[product_ids_string]", promotion_rule.product_ids_string %>
13
- </label>
14
5
  </p>
15
6
  <p>
16
7
  <label>
17
- <%= t('product_rule.label', :select => select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Spree::Promotion::Rules::Product::MATCH_POLICIES.map{|s| [t("product_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy))).html_safe %>
8
+ <%= t('product_rule.label', :select => select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Spree::Promotion::Rules::Product::MATCH_POLICIES.map{|s| [t("product_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy)), :include_blank => true).html_safe %>
18
9
  </label>
19
10
  </p>
@@ -1,17 +1,19 @@
1
1
  ---
2
2
  en:
3
- activemodel:
3
+ activerecord:
4
4
  attributes:
5
- promotion:
6
- name: Name
7
- description: Description
5
+ spree/promotion:
6
+ advertise: Advertise
8
7
  code: Code
9
- usage_limit: Usage limit
10
- starts_at: Starts at
11
- expires_at: Expires at
8
+ description: Description
9
+ event_name: Event Name
10
+ expires_at: Expires At
11
+ name: Name
12
+ path: Path
13
+ starts_at: Starts At
14
+ usage_limit: Usage Limit
12
15
  add_action_of_type: Add action of type
13
16
  add_rule_of_type: Add rule of type
14
- advertise: Advertise
15
17
  coupon: Coupon
16
18
  coupon_code: Coupon code
17
19
  editing_promotion: Editing Promotion
@@ -23,17 +25,26 @@ en:
23
25
  visited: Visit static content page
24
26
  expiry: Expiry
25
27
  free_shipping: Free Shipping
28
+ item_total_rule:
29
+ operators:
30
+ gt: greater than
31
+ gte: greater than or equal to
32
+ landing_page_rule:
33
+ path: Path
26
34
  new_promotion: New Promotion
27
35
  no_rules_added: No rules added
36
+ product_rule:
37
+ choose_products: Choose products
38
+ label: "Order must contain %{select} of these products"
39
+ match_any: at least one
40
+ match_all: all
41
+ product_source:
42
+ group: From product group
43
+ manual: Manually choose
28
44
  promotion_not_found: The coupon code you entered doesn't exist. Please try again.
29
45
  promotion: Promotion
46
+ promotion_action: Promotion Action
30
47
  promotion_actions: Actions
31
- promotions: Promotions
32
- promotion_form:
33
- match_policies:
34
- all: Match all of these rules
35
- any: Match any of these rules
36
- promotions_description: Manage offers and coupons with promotions
37
48
  promotion_action_types:
38
49
  create_adjustment:
39
50
  name: Create adjustment
@@ -44,43 +55,35 @@ en:
44
55
  give_store_credit:
45
56
  name: Give store credit
46
57
  description: Gives the user store credit of the amount specified
58
+ promotion_form:
59
+ match_policies:
60
+ all: Match all of these rules
61
+ any: Match any of these rules
62
+ promotions: Promotions
63
+ promotions_description: Manage offers and coupons with promotions
64
+ promotion_rule: Promotion Rule
47
65
  promotion_rule_types:
48
- user:
49
- name: User
50
- description: Available only to the specified users
51
- product:
52
- name: Product(s)
53
- description: Order includes specified product(s)
54
- item_total:
55
- name: Item total
56
- description: Order total meets these criteria
57
66
  first_order:
58
67
  name: First order
59
68
  description: "Must be the customer's first order"
69
+ item_total:
70
+ name: Item total
71
+ description: Order total meets these criteria
60
72
  landing_page:
61
73
  name: Landing Page
62
74
  description: Customer must have visited the specified page
75
+ product:
76
+ name: Product(s)
77
+ description: Order includes specified product(s)
78
+ user:
79
+ name: User
80
+ description: Available only to the specified users
63
81
  user_logged_in:
64
82
  name: User Logged In
65
83
  description: Available only to logged in users
66
- product_rule:
67
- choose_products: Choose products
68
- label: "Order must contain %{select} of these products"
69
- match_any: at least one
70
- match_all: all
71
- product_source:
72
- group: From product group
73
- manual: Manually choose
74
84
  rules: Rules
75
85
  spree/order:
76
86
  coupon_code: Coupon Code
77
87
  user_rule:
78
88
  choose_users: Choose users
79
- item_total_rule:
80
- operators:
81
- gt: greater than
82
- gte: greater than or equal to
83
- landing_page_rule:
84
- path: Path
85
- promotion_action: Promotion Action
86
- promotion_rule: Promotion Rule
89
+
@@ -1,7 +1,7 @@
1
1
  class MigrateAdjustments < ActiveRecord::Migration
2
2
  def up
3
3
  execute "UPDATE spree_adjustments SET amount = 0.0 WHERE amount IS NULL"
4
- execute "UPDATE spree_adjustments SET mandatory = 't' WHERE locked = 't'"
4
+ execute "UPDATE spree_adjustments SET mandatory = #{quoted_true} WHERE locked = #{quoted_true}"
5
5
  end
6
6
 
7
7
  def down
@@ -8,6 +8,13 @@ module Spree
8
8
  Dir.glob(File.join(File.dirname(__FILE__), '../../../app/**/*_decorator*.rb')) do |c|
9
9
  Rails.configuration.cache_classes ? require(c) : load(c)
10
10
  end
11
+
12
+ # Include list of visited paths in notification payload hash
13
+ Spree::Core::ControllerHelpers.class_eval do
14
+ def default_notification_payload
15
+ { :user => current_user, :order => current_order, :visited_paths => session[:visited_paths] }
16
+ end
17
+ end
11
18
  end
12
19
 
13
20
  config.autoload_paths += %W(#{config.root}/lib)
metadata CHANGED
@@ -1,48 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_promo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
5
- prerelease:
4
+ version: 1.1.0.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - David North
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70127245898980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - =
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.7
21
+ version: 1.1.0.rc1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - '='
28
- - !ruby/object:Gem::Version
29
- version: 1.0.7
24
+ version_requirements: *70127245898980
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: spree_auth
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70127245915000 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
- - - '='
30
+ - - =
36
31
  - !ruby/object:Gem::Version
37
- version: 1.0.7
32
+ version: 1.1.0.rc1
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - '='
44
- - !ruby/object:Gem::Version
45
- version: 1.0.7
35
+ version_requirements: *70127245915000
46
36
  description: Required dependency for Spree
47
37
  email: david@spreecommerce.com
48
38
  executables: []
@@ -66,7 +56,6 @@ files:
66
56
  - app/models/spree/calculator/free_shipping.rb
67
57
  - app/models/spree/order_decorator.rb
68
58
  - app/models/spree/product_decorator.rb
69
- - app/models/spree/product_group_decorator.rb
70
59
  - app/models/spree/promotion/actions/create_adjustment.rb
71
60
  - app/models/spree/promotion/actions/create_line_items.rb
72
61
  - app/models/spree/promotion/rules/first_order.rb
@@ -138,16 +127,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
127
  required_rubygems_version: !ruby/object:Gem::Requirement
139
128
  none: false
140
129
  requirements:
141
- - - ! '>='
130
+ - - ! '>'
142
131
  - !ruby/object:Gem::Version
143
- version: '0'
144
- segments:
145
- - 0
146
- hash: 558996978230033383
132
+ version: 1.3.1
147
133
  requirements:
148
134
  - none
149
135
  rubyforge_project:
150
- rubygems_version: 1.8.23
136
+ rubygems_version: 1.8.10
151
137
  signing_key:
152
138
  specification_version: 3
153
139
  summary: Promotion functionality for use with Spree.
@@ -1,3 +0,0 @@
1
- Spree::ProductGroup.class_eval do
2
- has_many :promotion_rules
3
- end