spree_promo 0.40.4 → 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,27 @@
1
1
  class Admin::PromotionRulesController < Admin::BaseController
2
- resource_controller
2
+ resource_controller
3
3
  belongs_to :promotion
4
-
5
- create.response do |wants|
4
+
5
+ create.response do |wants|
6
6
  wants.html { redirect_to edit_admin_promotion_path(parent_object) }
7
7
  wants.js { render :action => 'create', :layout => false}
8
8
  end
9
- destroy.response do |wants|
9
+ destroy.response do |wants|
10
10
  wants.html { redirect_to edit_admin_promotion_path(parent_object) }
11
11
  wants.js { render :action => 'destroy', :layout => false}
12
12
  end
13
13
 
14
14
  private
15
-
15
+
16
16
  def build_object
17
17
  return @object if @object.present?
18
18
  if params[:promotion_rule] && params[:promotion_rule][:type]
19
- @object = params[:promotion_rule][:type].constantize.new(object_params)
19
+ @object = params[:promotion_rule][:type].constantize.new(object_params)
20
20
  @object.promotion = parent_object
21
21
  else
22
22
  @object = end_of_association_chain.build(object_params)
23
23
  end
24
24
  @object
25
25
  end
26
-
26
+
27
27
  end
@@ -1,18 +1,18 @@
1
1
  class Admin::PromotionsController < Admin::BaseController
2
- resource_controller
2
+ resource_controller
3
3
  before_filter :load_data
4
4
 
5
5
  update.wants.html { redirect_to edit_object_url }
6
6
  create.wants.html { redirect_to edit_object_url }
7
7
  destroy.success.wants.js { render_js_for_destroy }
8
8
 
9
- private
9
+ private
10
10
  def build_object
11
- @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
11
+ @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
12
12
  @object.calculator = params[:promotion][:calculator_type].constantize.new if params[:promotion]
13
13
  end
14
-
15
- def load_data
14
+
15
+ def load_data
16
16
  @calculators = Promotion.calculators
17
- end
17
+ end
18
18
  end
@@ -19,6 +19,6 @@ class Calculator::FreeShipping < ::Calculator
19
19
 
20
20
  order.ship_total
21
21
  end
22
-
22
+
23
23
  end
24
24
 
@@ -9,5 +9,4 @@ class Promotion::Rules::ItemTotal < PromotionRule
9
9
  def eligible?(order)
10
10
  order.item_total.send(preferred_operator == 'gte' ? :>= : :>, preferred_amount)
11
11
  end
12
-
13
12
  end
@@ -1,6 +1,6 @@
1
1
  # A rule to limit a promotion based on products in the order.
2
2
  # Can require all or any of the products to be present.
3
- # Valid products either come from assigned product group or are assingned directly to the rule.
3
+ # Valid products either come from assigned product group or are assingned directly to the rule.
4
4
  class Promotion::Rules::Product < PromotionRule
5
5
 
6
6
  belongs_to :product_group
@@ -13,7 +13,7 @@ class Promotion::Rules::Product < PromotionRule
13
13
  def eligible_products
14
14
  product_group ? product_group.products : products
15
15
  end
16
-
16
+
17
17
  def eligible?(order)
18
18
  return true if eligible_products.empty?
19
19
  if preferred_match_policy == 'all'
@@ -22,19 +22,19 @@ class Promotion::Rules::Product < PromotionRule
22
22
  order.products.any? {|p| eligible_products.include?(p) }
23
23
  end
24
24
  end
25
-
25
+
26
26
 
27
27
  def products_source=(source)
28
28
  if source.to_s == 'manual'
29
29
  self.product_group_id = nil
30
30
  end
31
31
  end
32
-
32
+
33
33
  def product_ids_string
34
34
  product_ids.join(',')
35
35
  end
36
36
  def product_ids_string=(s)
37
37
  self.product_ids = s.to_s.split(',').map(&:strip)
38
38
  end
39
-
39
+
40
40
  end
@@ -3,12 +3,20 @@ class Promotion < ActiveRecord::Base
3
3
  calculated_adjustments
4
4
  alias credits promotion_credits
5
5
 
6
- has_many :promotion_rules
6
+ has_many :promotion_rules, :autosave => true
7
7
  accepts_nested_attributes_for :promotion_rules
8
8
  alias_method :rules, :promotion_rules
9
9
 
10
10
  validates :name, :code, :presence => true
11
11
 
12
+ # 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
13
+ # is provided
14
+ def save(*)
15
+ if super
16
+ promotion_rules.each { |p| p.save }
17
+ end
18
+ end
19
+
12
20
  MATCH_POLICIES = %w(all any)
13
21
 
14
22
  scope :automatic, where("code IS NULL OR code = ''")
@@ -41,12 +49,13 @@ class Promotion < ActiveRecord::Base
41
49
  if eligible?(order) and amount = calculator.compute(order)
42
50
  amount = order.item_total if amount > order.item_total
43
51
  order.promotion_credits.reload.clear unless combine? and order.promotion_credits.all? { |credit| credit.source.combine? }
44
- order.promotion_credits.create({
52
+ order.update!
53
+ PromotionCredit.create!({
45
54
  :label => "#{I18n.t(:coupon)} (#{code})",
46
55
  :source => self,
47
- :amount => -amount.abs
56
+ :amount => -amount.abs,
57
+ :order => order
48
58
  })
49
- order.update!
50
59
  end
51
60
  end
52
61
 
@@ -23,7 +23,7 @@ class PromotionCredit < ::Adjustment
23
23
  amount = order.item_total if amount > order.item_total
24
24
  -1 * amount
25
25
  end
26
-
26
+
27
27
  def total
28
28
  map(&:amount).sum
29
29
  end
@@ -2,9 +2,9 @@
2
2
  class PromotionRule < ActiveRecord::Base
3
3
 
4
4
  belongs_to :promotion
5
-
5
+
6
6
  scope :of_type, lambda {|t| {:conditions => {:type => t}}}
7
-
7
+
8
8
  def eligible?(order)
9
9
  raise 'eligible? should be implemented in a sub-class of Promotion::PromotionRule'
10
10
  end
@@ -18,9 +18,9 @@ class PromotionRule < ActiveRecord::Base
18
18
  def self.rule_classes
19
19
  @@rule_classes.to_a
20
20
  end
21
-
21
+
22
22
  def self.rule_class_names
23
23
  PromotionRule.rule_classes.map(&:name)
24
24
  end
25
-
25
+
26
26
  end
@@ -1 +1 @@
1
- jQuery('#<%= dom_id object %>').fadeOut();
1
+ jQuery('#<%= dom_id object %>').fadeOut().remove();
@@ -1,6 +1,6 @@
1
1
  <%= render "shared/error_messages", :target => @promotion %>
2
2
  <fieldset id="general_fields">
3
- <legend>General</legend>
3
+ <legend><%= t(:general) %></legend>
4
4
  <%= f.field_container :name do %>
5
5
  <%= f.label :name %><br />
6
6
  <%= f.text_field :name %>
@@ -19,14 +19,14 @@
19
19
  <%= f.field_container :combine do %>
20
20
  <label>
21
21
  <%= f.check_box :combine %>
22
- May be combined with other promotions
22
+ <%= t(:may_be_combined_with_other_promotions) %>
23
23
  </label>
24
24
  <% end %>
25
25
 
26
26
  </fieldset>
27
27
 
28
28
  <fieldset id="expiry_fields">
29
- <legend>Expiry</legend>
29
+ <legend><%= t(:expiry) %></legend>
30
30
  <p>
31
31
  <%= f.label :usage_limit %><br />
32
32
  <%= f.text_field :usage_limit %>
@@ -34,11 +34,11 @@
34
34
 
35
35
  <p id="starts_at_field">
36
36
  <%= f.label :starts_at %>
37
- <%= date_select :promotion, :starts_at, :prompt => true, :use_month_numbers => true %>
37
+ <%= f.spree_date_picker :starts_at, :prompt => true, :use_month_numbers => true %>
38
38
  </p>
39
39
  <p id="expires_at_field">
40
40
  <%= f.label :expires_at %>
41
- <%= date_select :promotion, :expires_at, :prompt => true, :use_month_numbers => true %>
41
+ <%= f.spree_date_picker :expires_at, :prompt => true, :use_month_numbers => true %>
42
42
  </p>
43
43
  </fieldset>
44
44
 
@@ -6,8 +6,8 @@
6
6
  <% end %>
7
7
 
8
8
  <fieldset id="rule_fields">
9
- <legend>Rules</legend>
10
-
9
+ <legend><%= t(:rules) %></legend>
10
+
11
11
  <%= form_for(@promotion, :url => object_url, :html => { :method => :put }) do |f| %>
12
12
  <p>
13
13
  <% for policy in Promotion::MATCH_POLICIES %>
@@ -26,7 +26,8 @@
26
26
  </p>
27
27
  <% end %>
28
28
 
29
- <%= form_tag(admin_promotion_promotion_rules_path(@promotion), 'data-remote' => true, :id => 'new_product_rule_form') do |f| %>
29
+ <%= form_tag(admin_promotion_promotion_rules_path(@promotion), 'data-remote' => true,
30
+ :id => 'new_product_rule_form') do %>
30
31
  <% options = options_for_select( PromotionRule.rule_class_names.map {|name| [ t("promotion_rule_types.#{name.demodulize.underscore}.name"), name] } ) %>
31
32
  <p>
32
33
  <label for="promotion_rule_type"><%= t('add_rule_of_type') %></label>
@@ -34,7 +35,7 @@
34
35
  <input type="submit" value="<%= t('add') %>" />
35
36
  </p>
36
37
  <% end %>
37
-
38
+
38
39
  </fieldset>
39
40
 
40
41
 
@@ -1,7 +1,7 @@
1
1
  <p class="field">
2
- <label>
2
+ <label for="<%= "#{param_prefix}_preferred_amount" %>">
3
3
  Item total must be
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>
7
- </p>
7
+ </p>
@@ -0,0 +1,4 @@
1
+ <p>
2
+ <%= form.label :coupon_code %><br />
3
+ <%= form.text_field :coupon_code %>
4
+ </p>
@@ -0,0 +1,10 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5
+ ci_opts = "--format progress --strict"
6
+ %>
7
+ default: <%= std_opts %> features
8
+ wip: --tags @wip:3 --wip features
9
+ ci: <%= ci_opts %> features CI=true
10
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -4,7 +4,9 @@ en:
4
4
  coupon: Coupon
5
5
  coupon_code: Coupon code
6
6
  editing_promotion: Editing Promotion
7
+ expiry: Expiry
7
8
  free_shipping: Free Shipping
9
+ may_be_combined_with_other_promotions: May be combined with other promotions
8
10
  new_promotion: New Promotion
9
11
  no_rules_added: No rules added
10
12
  promotions: Promotions
@@ -34,6 +36,7 @@ en:
34
36
  product_source:
35
37
  group: From product group
36
38
  manual: Manually choose
39
+ rules: Rules
37
40
  user_rule:
38
41
  choose_users: Choose users
39
42
  item_total_rule:
@@ -3,11 +3,11 @@ class CreatePromotionRules < ActiveRecord::Migration
3
3
  create_table :promotion_rules do |t|
4
4
  t.references :promotion, :user, :product_group
5
5
  t.timestamps
6
- t.string :type
6
+ t.string :type
7
7
  end
8
8
  add_index :promotion_rules, :product_group_id
9
9
  add_index :promotion_rules, :user_id
10
-
10
+
11
11
  create_table :products_promotion_rules do |t|
12
12
  t.integer :product_id, :promotion_rule_id
13
13
  end
@@ -5,7 +5,7 @@ class CreatePromotionRulesUsers < ActiveRecord::Migration
5
5
  end
6
6
  remove_column :promotion_rules_users, :id
7
7
  add_index :promotion_rules_users, :user_id
8
- add_index :promotion_rules_users, :promotion_rule_id
8
+ add_index :promotion_rules_users, :promotion_rule_id
9
9
  end
10
10
 
11
11
  def self.down
@@ -1,4 +1,4 @@
1
- class PromoHooks < Spree::ThemeSupport::HookListener
1
+ class SpreePromoHooks < Spree::ThemeSupport::HookListener
2
2
 
3
3
  insert_after :admin_tabs do
4
4
  %(<%= tab(:promotions) %>)
@@ -6,4 +6,6 @@ class PromoHooks < Spree::ThemeSupport::HookListener
6
6
 
7
7
  insert_after :product_properties, 'products/promotions'
8
8
 
9
+ replace :coupon_code_field, 'checkout/coupon_code_field'
10
+
9
11
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_promo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 183
5
- prerelease:
4
+ hash: 215
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 40
9
- - 4
10
- version: 0.40.4
8
+ - 50
9
+ - 0
10
+ version: 0.50.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David North
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-21 00:00:00 Z
18
+ date: 2011-03-23 00:00:00 -04:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: spree_core
@@ -25,12 +26,12 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 183
29
+ hash: 215
29
30
  segments:
30
31
  - 0
31
- - 40
32
- - 4
33
- version: 0.40.4
32
+ - 50
33
+ - 0
34
+ version: 0.50.0
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  description: Required dependancy for Spree
@@ -64,7 +65,9 @@ files:
64
65
  - app/views/admin/promotions/rules/_item_total.html.erb
65
66
  - app/views/admin/promotions/rules/_product.html.erb
66
67
  - app/views/admin/promotions/rules/_user.html.erb
68
+ - app/views/checkout/_coupon_code_field.html.erb
67
69
  - app/views/products/_promotions.html.erb
70
+ - config/cucumber.yml
68
71
  - config/locales/en.yml
69
72
  - config/routes.rb
70
73
  - lib/spree_promo.rb
@@ -81,6 +84,7 @@ files:
81
84
  - db/migrate/20100923095305_update_calculable_type_for_promotions.rb
82
85
  - public/javascripts/admin/promotions.js
83
86
  - public/stylesheets/admin/promotions.css
87
+ has_rdoc: true
84
88
  homepage: http://spreecommerce.com
85
89
  licenses: []
86
90
 
@@ -112,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
116
  requirements:
113
117
  - none
114
118
  rubyforge_project: spree_promo
115
- rubygems_version: 1.8.10
119
+ rubygems_version: 1.3.7
116
120
  signing_key:
117
121
  specification_version: 3
118
122
  summary: Promotion functionality for use with Spree.