spree_core 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7aeecb32436b2f2e63f695ae7f8e72e0fc5d3dff
4
- data.tar.gz: d3d9c62816751345378389914b51d876ac8f2910
3
+ metadata.gz: cf4b040c67cbc697e8ff23b19862515ad3ec40e5
4
+ data.tar.gz: 4338ea645e72ff94a0a52ffa3531319f4e64824c
5
5
  SHA512:
6
- metadata.gz: 36a03013620da8c4081e87c51c29722106df038560a5cc0da2a6c3d39e5441d073e7deb643c349aacf276d96fb0c53f6fa3bb880ba6082dcb5ef86add172c2ce
7
- data.tar.gz: e7e6816d26ae750cc2c9b5faee24fe5814d280679758e77e271d9a35952dcb52eb85e4bd54fb9598a1ea0240426f4870a51eb29a3725457b4573381bbce1fcdb
6
+ metadata.gz: b68a89ef41087957b53b64bb1519040c52b9de295f6f4a0cee305f9e236bb2ecfdf474eb8f466eb0b6c80f525ebb76913db76bdddba44022e2d8732d48ba18a4
7
+ data.tar.gz: f223ee12cd500420b4c590d66918da99d69c0f1c46eaac008d18fa5164889aa2eeea266ff15867873291c6c54a78377ae1ad5befcaf321c2e2625e66089dcf44
@@ -92,6 +92,7 @@ module Spree
92
92
  def define_image_method(style)
93
93
  self.class.send :define_method, "#{style}_image" do |product, *options|
94
94
  options = options.first || {}
95
+ options[:alt] ||= product.name
95
96
  if product.images.empty?
96
97
  if !product.is_a?(Spree::Variant) && !product.variant_images.empty?
97
98
  create_product_image_tag(product.variant_images.first, product, options, style)
@@ -135,7 +135,7 @@ module Spree
135
135
  return if !TwitterCldr::Shared::PostalCodes.territories.include?(country.iso.downcase.to_sym)
136
136
 
137
137
  postal_code = TwitterCldr::Shared::PostalCodes.for_territory(country.iso)
138
- errors.add(:zipcode, :invalid) if !postal_code.valid?(zipcode.to_s)
138
+ errors.add(:zipcode, :invalid) if !postal_code.valid?(zipcode.to_s.strip)
139
139
  end
140
140
  end
141
141
  end
@@ -446,7 +446,7 @@ module Spree
446
446
  end
447
447
 
448
448
  def create_proposed_shipments
449
- adjustments.shipping.delete_all
449
+ all_adjustments.shipping.delete_all
450
450
  shipments.destroy_all
451
451
  self.shipments = Spree::Stock::Coordinator.new(self).shipments
452
452
  end
@@ -595,7 +595,7 @@ module Spree
595
595
  if shipments.empty? || shipments.any? { |shipment| shipment.shipping_rates.blank? }
596
596
  # After this point, order redirects back to 'address' state and asks user to pick a proper address
597
597
  # Therefore, shipments are not necessary at this point.
598
- shipments.delete_all
598
+ shipments.destroy_all
599
599
  errors.add(:base, Spree.t(:items_cannot_be_shipped)) and return false
600
600
  end
601
601
  end
@@ -1,338 +1,338 @@
1
1
  module Spree
2
2
  class Order < Spree::Base
3
3
  module Checkout
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- class_attribute :next_event_transitions
8
- class_attribute :previous_states
9
- class_attribute :checkout_flow
10
- class_attribute :checkout_steps
11
- class_attribute :removed_transitions
12
-
13
- self.checkout_steps ||= {}
14
- self.next_event_transitions ||= []
15
- self.previous_states ||= [:cart]
16
- self.removed_transitions ||= []
17
-
18
- def self.checkout_flow(&block)
19
- if block_given?
20
- @checkout_flow = block
21
- define_state_machine!
22
- else
23
- @checkout_flow
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ class_attribute :next_event_transitions
7
+ class_attribute :previous_states
8
+ class_attribute :checkout_flow
9
+ class_attribute :checkout_steps
10
+ class_attribute :removed_transitions
11
+
12
+ self.checkout_steps ||= {}
13
+ self.next_event_transitions ||= []
14
+ self.previous_states ||= [:cart]
15
+ self.removed_transitions ||= []
16
+
17
+ def self.checkout_flow(&block)
18
+ if block_given?
19
+ @checkout_flow = block
20
+ define_state_machine!
21
+ else
22
+ @checkout_flow
23
+ end
24
24
  end
25
- end
26
-
27
- def self.define_state_machine!
28
- self.checkout_steps = {}
29
- self.next_event_transitions = []
30
- self.previous_states = [:cart]
31
- self.removed_transitions = []
32
25
 
33
- # Build the checkout flow using the checkout_flow defined either
34
- # within the Order class, or a decorator for that class.
35
- #
36
- # This method may be called multiple times depending on if the
37
- # checkout_flow is re-defined in a decorator or not.
38
- instance_eval(&checkout_flow)
39
-
40
- klass = self
41
-
42
- # To avoid a ton of warnings when the state machine is re-defined
43
- StateMachines::Machine.ignore_method_conflicts = true
44
- # To avoid multiple occurrences of the same transition being defined
45
- # On first definition, state_machines will not be defined
46
- state_machines.clear if respond_to?(:state_machines)
47
- state_machine :state, initial: :cart, use_transactions: false, action: :save_state do
48
- klass.next_event_transitions.each { |t| transition(t.merge(on: :next)) }
49
-
50
- # Persist the state on the order
51
- after_transition do |order, transition|
52
- order.state = order.state
53
- order.state_changes.create(
54
- previous_state: transition.from,
55
- next_state: transition.to,
56
- name: 'order',
57
- user_id: order.user_id
58
- )
59
- order.save
60
- end
26
+ def self.define_state_machine!
27
+ self.checkout_steps = {}
28
+ self.next_event_transitions = []
29
+ self.previous_states = [:cart]
30
+ self.removed_transitions = []
31
+
32
+ # Build the checkout flow using the checkout_flow defined either
33
+ # within the Order class, or a decorator for that class.
34
+ #
35
+ # This method may be called multiple times depending on if the
36
+ # checkout_flow is re-defined in a decorator or not.
37
+ instance_eval(&checkout_flow)
38
+
39
+ klass = self
40
+
41
+ # To avoid a ton of warnings when the state machine is re-defined
42
+ StateMachines::Machine.ignore_method_conflicts = true
43
+ # To avoid multiple occurrences of the same transition being defined
44
+ # On first definition, state_machines will not be defined
45
+ state_machines.clear if respond_to?(:state_machines)
46
+ state_machine :state, initial: :cart, use_transactions: false, action: :save_state do
47
+ klass.next_event_transitions.each { |t| transition(t.merge(on: :next)) }
48
+
49
+ # Persist the state on the order
50
+ after_transition do |order, transition|
51
+ order.state = order.state
52
+ order.state_changes.create(
53
+ previous_state: transition.from,
54
+ next_state: transition.to,
55
+ name: 'order',
56
+ user_id: order.user_id
57
+ )
58
+ order.save
59
+ end
61
60
 
62
- event :cancel do
63
- transition to: :canceled, if: :allow_cancel?
64
- end
61
+ event :cancel do
62
+ transition to: :canceled, if: :allow_cancel?
63
+ end
65
64
 
66
- event :return do
67
- transition to: :returned,
68
- from: [:complete, :awaiting_return, :canceled],
69
- if: :all_inventory_units_returned?
70
- end
65
+ event :return do
66
+ transition to: :returned,
67
+ from: [:complete, :awaiting_return, :canceled],
68
+ if: :all_inventory_units_returned?
69
+ end
71
70
 
72
- event :resume do
73
- transition to: :resumed, from: :canceled, if: :canceled?
74
- end
71
+ event :resume do
72
+ transition to: :resumed, from: :canceled, if: :canceled?
73
+ end
75
74
 
76
- event :authorize_return do
77
- transition to: :awaiting_return
78
- end
75
+ event :authorize_return do
76
+ transition to: :awaiting_return
77
+ end
79
78
 
80
- if states[:payment]
81
- before_transition to: :complete do |order|
82
- if order.payment_required? && order.payments.valid.empty?
83
- order.errors.add(:base, Spree.t(:no_payment_found))
84
- false
85
- elsif order.payment_required?
86
- order.process_payments!
79
+ if states[:payment]
80
+ before_transition to: :complete do |order|
81
+ if order.payment_required? && order.payments.valid.empty?
82
+ order.errors.add(:base, Spree.t(:no_payment_found))
83
+ false
84
+ elsif order.payment_required?
85
+ order.process_payments!
86
+ end
87
87
  end
88
+ after_transition to: :complete, do: :persist_user_credit_card
89
+ before_transition to: :payment, do: :set_shipments_cost
90
+ before_transition to: :payment, do: :create_tax_charge!
91
+ before_transition to: :payment, do: :assign_default_credit_card
88
92
  end
89
- after_transition to: :complete, do: :persist_user_credit_card
90
- before_transition to: :payment, do: :set_shipments_cost
91
- before_transition to: :payment, do: :create_tax_charge!
92
- before_transition to: :payment, do: :assign_default_credit_card
93
- end
94
93
 
95
- before_transition from: :cart, do: :ensure_line_items_present
94
+ before_transition from: :cart, do: :ensure_line_items_present
96
95
 
97
- if states[:address]
98
- before_transition from: :address, do: :create_tax_charge!
99
- before_transition to: :address, do: :assign_default_addresses!
100
- before_transition from: :address, do: :persist_user_address!
101
- end
96
+ if states[:address]
97
+ before_transition from: :address, do: :create_tax_charge!
98
+ before_transition to: :address, do: :assign_default_addresses!
99
+ before_transition from: :address, do: :persist_user_address!
100
+ end
102
101
 
103
- if states[:delivery]
104
- before_transition to: :delivery, do: :create_proposed_shipments
105
- before_transition to: :delivery, do: :ensure_available_shipping_rates
106
- before_transition to: :delivery, do: :set_shipments_cost
107
- before_transition from: :delivery, do: :apply_free_shipping_promotions
108
- end
102
+ if states[:delivery]
103
+ before_transition to: :delivery, do: :create_proposed_shipments
104
+ before_transition to: :delivery, do: :ensure_available_shipping_rates
105
+ before_transition to: :delivery, do: :set_shipments_cost
106
+ before_transition from: :delivery, do: :apply_free_shipping_promotions
107
+ end
109
108
 
110
- before_transition to: :resumed, do: :ensure_line_item_variants_are_not_deleted
111
- before_transition to: :resumed, do: :ensure_line_items_are_in_stock
109
+ before_transition to: :resumed, do: :ensure_line_item_variants_are_not_deleted
110
+ before_transition to: :resumed, do: :ensure_line_items_are_in_stock
112
111
 
113
- before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted
114
- before_transition to: :complete, do: :ensure_line_items_are_in_stock
112
+ before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted
113
+ before_transition to: :complete, do: :ensure_line_items_are_in_stock
115
114
 
116
- after_transition to: :complete, do: :finalize!
117
- after_transition to: :resumed, do: :after_resume
118
- after_transition to: :canceled, do: :after_cancel
115
+ after_transition to: :complete, do: :finalize!
116
+ after_transition to: :resumed, do: :after_resume
117
+ after_transition to: :canceled, do: :after_cancel
119
118
 
120
- after_transition from: any - :cart, to: any - [:confirm, :complete] do |order|
121
- order.update_totals
122
- order.persist_totals
119
+ after_transition from: any - :cart, to: any - [:confirm, :complete] do |order|
120
+ order.update_totals
121
+ order.persist_totals
122
+ end
123
123
  end
124
- end
125
-
126
- alias_method :save_state, :save
127
- end
128
124
 
129
- def self.go_to_state(name, options = {})
130
- self.checkout_steps[name] = options
131
- previous_states.each do |state|
132
- add_transition({ from: state, to: name }.merge(options))
125
+ alias_method :save_state, :save
133
126
  end
134
- if options[:if]
135
- previous_states << name
136
- else
137
- self.previous_states = [name]
138
- end
139
- end
140
127
 
141
- def self.insert_checkout_step(name, options = {})
142
- before = options.delete(:before)
143
- after = options.delete(:after) unless before
144
- after = self.checkout_steps.keys.last unless before || after
145
-
146
- cloned_steps = self.checkout_steps.clone
147
- cloned_removed_transitions = self.removed_transitions.clone
148
- checkout_flow do
149
- cloned_steps.each_pair do |key, value|
150
- go_to_state(name, options) if key == before
151
- go_to_state(key, value)
152
- go_to_state(name, options) if key == after
128
+ def self.go_to_state(name, options = {})
129
+ self.checkout_steps[name] = options
130
+ previous_states.each do |state|
131
+ add_transition({ from: state, to: name }.merge(options))
153
132
  end
154
- cloned_removed_transitions.each do |transition|
155
- remove_transition(transition)
133
+ if options[:if]
134
+ previous_states << name
135
+ else
136
+ self.previous_states = [name]
156
137
  end
157
138
  end
158
- end
159
139
 
160
- def self.remove_checkout_step(name)
161
- cloned_steps = self.checkout_steps.clone
162
- cloned_removed_transitions = self.removed_transitions.clone
163
- checkout_flow do
164
- cloned_steps.each_pair do |key, value|
165
- go_to_state(key, value) unless key == name
140
+ def self.insert_checkout_step(name, options = {})
141
+ before = options.delete(:before)
142
+ after = options.delete(:after) unless before
143
+ after = self.checkout_steps.keys.last unless before || after
144
+
145
+ cloned_steps = self.checkout_steps.clone
146
+ cloned_removed_transitions = self.removed_transitions.clone
147
+ checkout_flow do
148
+ cloned_steps.each_pair do |key, value|
149
+ go_to_state(name, options) if key == before
150
+ go_to_state(key, value)
151
+ go_to_state(name, options) if key == after
152
+ end
153
+ cloned_removed_transitions.each do |transition|
154
+ remove_transition(transition)
155
+ end
166
156
  end
167
- cloned_removed_transitions.each do |transition|
168
- remove_transition(transition)
157
+ end
158
+
159
+ def self.remove_checkout_step(name)
160
+ cloned_steps = self.checkout_steps.clone
161
+ cloned_removed_transitions = self.removed_transitions.clone
162
+ checkout_flow do
163
+ cloned_steps.each_pair do |key, value|
164
+ go_to_state(key, value) unless key == name
165
+ end
166
+ cloned_removed_transitions.each do |transition|
167
+ remove_transition(transition)
168
+ end
169
169
  end
170
170
  end
171
- end
172
171
 
173
- def self.remove_transition(options = {})
174
- self.removed_transitions << options
175
- self.next_event_transitions.delete(find_transition(options))
176
- end
172
+ def self.remove_transition(options = {})
173
+ self.removed_transitions << options
174
+ self.next_event_transitions.delete(find_transition(options))
175
+ end
177
176
 
178
- def self.find_transition(options = {})
179
- return nil if options.nil? || !options.include?(:from) || !options.include?(:to)
180
- self.next_event_transitions.detect do |transition|
181
- transition[options[:from].to_sym] == options[:to].to_sym
177
+ def self.find_transition(options = {})
178
+ return nil if options.nil? || !options.include?(:from) || !options.include?(:to)
179
+ self.next_event_transitions.detect do |transition|
180
+ transition[options[:from].to_sym] == options[:to].to_sym
181
+ end
182
182
  end
183
- end
184
183
 
185
- def self.checkout_step_names
186
- self.checkout_steps.keys
187
- end
184
+ def self.checkout_step_names
185
+ self.checkout_steps.keys
186
+ end
188
187
 
189
- def self.add_transition(options)
190
- self.next_event_transitions << { options.delete(:from) => options.delete(:to) }.merge(options)
191
- end
188
+ def self.add_transition(options)
189
+ self.next_event_transitions << { options.delete(:from) => options.delete(:to) }.merge(options)
190
+ end
192
191
 
193
- def checkout_steps
194
- steps = (self.class.checkout_steps.each_with_object([]) do |(step, options), checkout_steps|
195
- next if options.include?(:if) && !options[:if].call(self)
196
- checkout_steps << step
197
- end).map(&:to_s)
198
- # Ensure there is always a complete step
199
- steps << "complete" unless steps.include?("complete")
200
- steps
201
- end
192
+ def checkout_steps
193
+ steps = (self.class.checkout_steps.each_with_object([]) do |(step, options), checkout_steps|
194
+ next if options.include?(:if) && !options[:if].call(self)
195
+ checkout_steps << step
196
+ end).map(&:to_s)
197
+ # Ensure there is always a complete step
198
+ steps << "complete" unless steps.include?("complete")
199
+ steps
200
+ end
202
201
 
203
- def has_checkout_step?(step)
204
- step.present? && self.checkout_steps.include?(step)
205
- end
202
+ def has_checkout_step?(step)
203
+ step.present? && self.checkout_steps.include?(step)
204
+ end
206
205
 
207
- def passed_checkout_step?(step)
208
- has_checkout_step?(step) && checkout_step_index(step) < checkout_step_index(state)
209
- end
206
+ def passed_checkout_step?(step)
207
+ has_checkout_step?(step) && checkout_step_index(step) < checkout_step_index(state)
208
+ end
210
209
 
211
- def checkout_step_index(step)
212
- self.checkout_steps.index(step).to_i
213
- end
210
+ def checkout_step_index(step)
211
+ self.checkout_steps.index(step).to_i
212
+ end
214
213
 
215
- def can_go_to_state?(state)
216
- return false unless has_checkout_step?(self.state) && has_checkout_step?(state)
217
- checkout_step_index(state) > checkout_step_index(self.state)
218
- end
214
+ def can_go_to_state?(state)
215
+ return false unless has_checkout_step?(self.state) && has_checkout_step?(state)
216
+ checkout_step_index(state) > checkout_step_index(self.state)
217
+ end
219
218
 
220
- define_callbacks :updating_from_params, terminator: ->(_target, result) { result == false }
219
+ define_callbacks :updating_from_params, terminator: ->(_target, result) { result == false }
221
220
 
222
- set_callback :updating_from_params, :before, :update_params_payment_source
221
+ set_callback :updating_from_params, :before, :update_params_payment_source
223
222
 
224
- def update_from_params(params, permitted_params, request_env = {})
225
- success = false
226
- @updating_params = params
227
- run_callbacks :updating_from_params do
228
- # Set existing card after setting permitted parameters because
229
- # rails would slice parameters containg ruby objects, apparently
230
- existing_card_id = @updating_params[:order] ? @updating_params[:order].delete(:existing_card) : nil
223
+ def update_from_params(params, permitted_params, request_env = {})
224
+ success = false
225
+ @updating_params = params
226
+ run_callbacks :updating_from_params do
227
+ # Set existing card after setting permitted parameters because
228
+ # rails would slice parameters containg ruby objects, apparently
229
+ existing_card_id = @updating_params[:order] ? @updating_params[:order].delete(:existing_card) : nil
231
230
 
232
- attributes = @updating_params[:order] ? @updating_params[:order].permit(permitted_params).delete_if { |_k, v| v.nil? } : {}
231
+ attributes = @updating_params[:order] ? @updating_params[:order].permit(permitted_params).delete_if { |_k, v| v.nil? } : {}
233
232
 
234
- if existing_card_id.present?
235
- credit_card = CreditCard.find existing_card_id
236
- if credit_card.user_id != user_id || credit_card.user_id.blank?
237
- raise Core::GatewayError.new Spree.t(:invalid_credit_card)
238
- end
233
+ if existing_card_id.present?
234
+ credit_card = CreditCard.find existing_card_id
235
+ if credit_card.user_id != user_id || credit_card.user_id.blank?
236
+ raise Core::GatewayError.new Spree.t(:invalid_credit_card)
237
+ end
239
238
 
240
- credit_card.verification_value = params[:cvc_confirm] if params[:cvc_confirm].present?
239
+ credit_card.verification_value = params[:cvc_confirm] if params[:cvc_confirm].present?
241
240
 
242
- attributes[:payments_attributes].first[:source] = credit_card
243
- attributes[:payments_attributes].first[:payment_method_id] = credit_card.payment_method_id
244
- attributes[:payments_attributes].first.delete :source_attributes
245
- end
241
+ attributes[:payments_attributes].first[:source] = credit_card
242
+ attributes[:payments_attributes].first[:payment_method_id] = credit_card.payment_method_id
243
+ attributes[:payments_attributes].first.delete :source_attributes
244
+ end
245
+
246
+ if attributes[:payments_attributes]
247
+ attributes[:payments_attributes].first[:request_env] = request_env
248
+ end
246
249
 
247
- if attributes[:payments_attributes]
248
- attributes[:payments_attributes].first[:request_env] = request_env
250
+ success = update_attributes(attributes)
251
+ set_shipments_cost if shipments.any?
249
252
  end
250
253
 
251
- success = update_attributes(attributes)
252
- set_shipments_cost if shipments.any?
254
+ @updating_params = nil
255
+ success
253
256
  end
254
257
 
255
- @updating_params = nil
256
- success
257
- end
258
+ def assign_default_addresses!
259
+ if user
260
+ clone_billing
261
+ # Skip setting ship address if order doesn't have a delivery checkout step
262
+ # to avoid triggering validations on shipping address
263
+ clone_shipping if checkout_steps.include?("delivery")
264
+ end
265
+ end
258
266
 
259
- def assign_default_addresses!
260
- if user
261
- clone_billing
262
- # Skip setting ship address if order doesn't have a delivery checkout step
263
- # to avoid triggering validations on shipping address
264
- clone_shipping if checkout_steps.include?("delivery")
267
+ def clone_billing
268
+ if !bill_address_id && user.bill_address.try(:valid?)
269
+ self.bill_address = user.bill_address.try(:clone)
270
+ end
265
271
  end
266
- end
267
272
 
268
- def clone_billing
269
- if !bill_address_id && user.bill_address.try(:valid?)
270
- self.bill_address = user.bill_address.try(:clone)
273
+ def clone_shipping
274
+ if !ship_address_id && user.ship_address.try(:valid?)
275
+ self.ship_address = user.ship_address.try(:clone)
276
+ end
271
277
  end
272
- end
273
278
 
274
- def clone_shipping
275
- if !ship_address_id && user.ship_address.try(:valid?)
276
- self.ship_address = user.ship_address.try(:clone)
279
+ def persist_user_address!
280
+ if !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id
281
+ user.persist_order_address(self)
282
+ end
277
283
  end
278
- end
279
284
 
280
- def persist_user_address!
281
- if !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id
282
- user.persist_order_address(self)
285
+ def persist_user_credit_card
286
+ if !temporary_credit_card && user_id && valid_credit_cards.present?
287
+ default_cc = valid_credit_cards.first
288
+ default_cc.user_id = user_id
289
+ default_cc.default = true
290
+ default_cc.save
291
+ end
283
292
  end
284
- end
285
293
 
286
- def persist_user_credit_card
287
- if !temporary_credit_card && user_id && valid_credit_cards.present?
288
- default_cc = valid_credit_cards.first
289
- default_cc.user_id = user_id
290
- default_cc.default = true
291
- default_cc.save
294
+ def assign_default_credit_card
295
+ if payments.from_credit_card.count == 0 && user_has_valid_default_card? && payment_required?
296
+ cc = user.default_credit_card
297
+ payments.create!(payment_method_id: cc.payment_method_id, source: cc, amount: total)
298
+ end
292
299
  end
293
- end
294
300
 
295
- def assign_default_credit_card
296
- if payments.from_credit_card.count == 0 && user_has_valid_default_card? && payment_required?
297
- cc = user.default_credit_card
298
- payments.create!(payment_method_id: cc.payment_method_id, source: cc, amount: total)
301
+ def user_has_valid_default_card?
302
+ user && user.default_credit_card.try(:valid?)
299
303
  end
300
- end
301
304
 
302
- def user_has_valid_default_card?
303
- user && user.default_credit_card.try(:valid?)
304
- end
305
+ private
305
306
 
306
- private
307
-
308
- # For payment step, filter order parameters to produce the expected nested
309
- # attributes for a single payment and its source, discarding attributes
310
- # for payment methods other than the one selected
311
- #
312
- # In case a existing credit card is provided it needs to build the payment
313
- # attributes from scratch so we can set the amount. example payload:
314
- #
315
- # {
316
- # "order": {
317
- # "existing_card": "2"
318
- # }
319
- # }
320
- #
321
- def update_params_payment_source
322
- if @updating_params[:payment_source].present?
323
- source_params = @updating_params.
324
- delete(:payment_source)[@updating_params[:order][:payments_attributes].
325
- first[:payment_method_id].to_s]
326
-
327
- if source_params
328
- @updating_params[:order][:payments_attributes].first[:source_attributes] = source_params
307
+ # For payment step, filter order parameters to produce the expected nested
308
+ # attributes for a single payment and its source, discarding attributes
309
+ # for payment methods other than the one selected
310
+ #
311
+ # In case a existing credit card is provided it needs to build the payment
312
+ # attributes from scratch so we can set the amount. example payload:
313
+ #
314
+ # {
315
+ # "order": {
316
+ # "existing_card": "2"
317
+ # }
318
+ # }
319
+ #
320
+ def update_params_payment_source
321
+ if @updating_params[:payment_source].present?
322
+ source_params = @updating_params.
323
+ delete(:payment_source)[@updating_params[:order][:payments_attributes].
324
+ first[:payment_method_id].to_s]
325
+
326
+ if source_params
327
+ @updating_params[:order][:payments_attributes].first[:source_attributes] = source_params
328
+ end
329
329
  end
330
- end
331
330
 
332
- if @updating_params[:order] && (@updating_params[:order][:payments_attributes] ||
333
- @updating_params[:order][:existing_card])
334
- @updating_params[:order][:payments_attributes] ||= [{}]
335
- @updating_params[:order][:payments_attributes].first[:amount] = total
331
+ if @updating_params[:order] && (@updating_params[:order][:payments_attributes] ||
332
+ @updating_params[:order][:existing_card])
333
+ @updating_params[:order][:payments_attributes] ||= [{}]
334
+ @updating_params[:order][:payments_attributes].first[:amount] = total
335
+ end
336
336
  end
337
337
  end
338
338
  end
@@ -421,6 +421,7 @@ en:
421
421
  overview: Overview
422
422
  products: Products
423
423
  promotions: Promotions
424
+ promotion_categories: Promotion Categories
424
425
  properties: Properties
425
426
  prototypes: Prototypes
426
427
  reports: Reports
@@ -26,4 +26,4 @@ connection.execute <<-SQL
26
26
  VALUES (#{country_values.call});
27
27
  SQL
28
28
 
29
- Spree::Config[:default_country_id] = Spree::Country.find_by(name: "United States").id
29
+ Spree::Config[:default_country_id] = Spree::Country.find_by(iso: "US").id
@@ -1,17 +1,12 @@
1
1
  eu_vat = Spree::Zone.create!(name: "EU_VAT", description: "Countries that make up the EU VAT zone.")
2
2
  north_america = Spree::Zone.create!(name: "North America", description: "USA + Canada")
3
-
4
- ["Poland", "Finland", "Portugal", "Romania", "Germany", "France",
5
- "Slovakia", "Hungary", "Slovenia", "Ireland", "Austria", "Spain",
6
- "Italy", "Belgium", "Sweden", "Latvia", "Bulgaria", "United Kingdom",
7
- "Lithuania", "Cyprus", "Luxembourg", "Malta", "Denmark", "Netherlands",
8
- "Estonia"].
3
+ %w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG GB LT CY LU MT DK NL EE).
9
4
  each do |name|
10
- eu_vat.zone_members.create!(zoneable: Spree::Country.find_by!(name: name))
5
+ eu_vat.zone_members.create!(zoneable: Spree::Country.find_by!(iso: name))
11
6
  end
12
7
 
13
- ["United States", "Canada"].each do |name|
14
- north_america.zone_members.create!(zoneable: Spree::Country.find_by!(name: name))
8
+ %w(US CA).each do |name|
9
+ north_america.zone_members.create!(zoneable: Spree::Country.find_by!(iso: name))
15
10
  end
16
11
 
17
12
 
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- '3.0.2'
3
+ '3.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant