spree_promo 1.3.0 → 1.3.1

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.
@@ -5,25 +5,28 @@ Spree::CheckoutController.class_eval do
5
5
  if @order.update_attributes(object_params)
6
6
 
7
7
  fire_event('spree.checkout.update')
8
- render :edit and return unless apply_coupon_code
8
+ unless apply_coupon_code
9
+ respond_with(@order) { |format| format.html { render :edit } }
10
+ return
11
+ end
9
12
 
10
13
  if @order.next
11
14
  state_callback(:after)
12
15
  else
13
16
  flash[:error] = t(:payment_processing_failed)
14
- redirect_to checkout_state_path(@order.state)
17
+ respond_with(@order, :location => checkout_state_path(@order.state))
15
18
  return
16
19
  end
17
20
 
18
21
  if @order.state == 'complete' || @order.completed?
19
22
  flash.notice = t(:order_processed_successfully)
20
23
  flash[:commerce_tracking] = 'nothing special'
21
- redirect_to completion_route
24
+ respond_with(@order, :location => completion_route)
22
25
  else
23
- redirect_to checkout_state_path(@order.state)
26
+ respond_with(@order, :location => checkout_state_path(@order.state))
24
27
  end
25
28
  else
26
- render :edit
29
+ respond_with(@order) { |format| format.html { render :edit } }
27
30
  end
28
31
  end
29
32
 
@@ -8,30 +8,31 @@ module Spree
8
8
 
9
9
  has_many :promotion_rules, :foreign_key => :activator_id, :autosave => true, :dependent => :destroy
10
10
  alias_method :rules, :promotion_rules
11
- accepts_nested_attributes_for :promotion_rules
12
11
 
13
12
  has_many :promotion_actions, :foreign_key => :activator_id, :autosave => true, :dependent => :destroy
14
13
  alias_method :actions, :promotion_actions
15
- accepts_nested_attributes_for :promotion_actions
16
14
 
17
- validates_associated :rules
15
+ accepts_nested_attributes_for :promotion_actions, :promotion_rules
18
16
 
19
17
  attr_accessible :name, :event_name, :code, :match_policy,
20
18
  :path, :advertise, :description, :usage_limit,
21
19
  :starts_at, :expires_at, :promotion_rules_attributes,
22
20
  :promotion_actions_attributes
23
21
 
24
- # TODO: This shouldn't be necessary with :autosave option but nested attribute updating of actions is broken without it
25
- after_save :save_rules_and_actions
26
- def save_rules_and_actions
27
- (rules + actions).each &:save
28
- end
22
+ validates_associated :rules
29
23
 
30
24
  validates :name, :presence => true
31
25
  validates :code, :presence => true, :if => lambda{|r| r.event_name == 'spree.checkout.coupon_code_added' }
32
26
  validates :path, :presence => true, :if => lambda{|r| r.event_name == 'spree.content.visited' }
33
27
  validates :usage_limit, :numericality => { :greater_than => 0, :allow_nil => true }
34
28
 
29
+ # TODO: This shouldn't be necessary with :autosave option but nested attribute updating of actions is broken without it
30
+ after_save :save_rules_and_actions
31
+
32
+ def save_rules_and_actions
33
+ (rules + actions).each &:save
34
+ end
35
+
35
36
  def self.advertised
36
37
  where(:advertise => true)
37
38
  end
@@ -77,7 +78,9 @@ module Spree
77
78
 
78
79
  # Products assigned to all product rules
79
80
  def products
80
- @products ||= rules.of_type('Spree::Promotion::Rules::Product').map(&:products).flatten.uniq
81
+ @products ||= self.rules.all.inject([]) do |products, rule|
82
+ rule.respond_to?(:products) ? products << rule.products : products
83
+ end.flatten.uniq
81
84
  end
82
85
 
83
86
  def usage_limit_exceeded?(order = nil)
@@ -100,6 +103,5 @@ module Spree
100
103
  def code=(coupon_code)
101
104
  write_attribute(:code, (coupon_code.downcase.strip rescue nil))
102
105
  end
103
-
104
106
  end
105
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_promo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
16
- requirement: &70356031603360 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - =
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.3.0
21
+ version: 1.3.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70356031603360
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.1
25
30
  description: Required dependency for Spree
26
31
  email: david@spreecommerce.com
27
32
  executables: []
@@ -118,11 +123,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
123
  version: '0'
119
124
  segments:
120
125
  - 0
121
- hash: 1788889926812188579
126
+ hash: -3509403428169566053
122
127
  requirements:
123
128
  - none
124
129
  rubyforge_project:
125
- rubygems_version: 1.8.10
130
+ rubygems_version: 1.8.23
126
131
  signing_key:
127
132
  specification_version: 3
128
133
  summary: Promotion functionality for use with Spree.