spree_core 2.4.10 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/app/assets/images/logo/spree_50.png +0 -0
  4. data/app/controllers/spree/base_controller.rb +1 -2
  5. data/app/helpers/spree/base_helper.rb +41 -131
  6. data/app/helpers/spree/products_helper.rb +1 -1
  7. data/app/models/concerns/spree/adjustment_source.rb +51 -15
  8. data/app/models/concerns/spree/calculated_adjustments.rb +1 -0
  9. data/app/models/concerns/spree/display_money.rb +32 -0
  10. data/app/models/concerns/spree/named_type.rb +1 -1
  11. data/app/models/concerns/spree/number_generator.rb +39 -0
  12. data/app/models/concerns/spree/user_reporting.rb +3 -8
  13. data/app/models/spree/address.rb +0 -2
  14. data/app/models/spree/adjustable/adjustments_updater.rb +70 -0
  15. data/app/models/spree/adjustable/promotion_accumulator.rb +75 -0
  16. data/app/models/spree/adjustment.rb +17 -26
  17. data/app/models/spree/app_configuration.rb +4 -33
  18. data/app/models/spree/base.rb +0 -3
  19. data/app/models/spree/calculator.rb +0 -5
  20. data/app/models/spree/classification.rb +1 -1
  21. data/app/models/spree/country.rb +10 -4
  22. data/app/models/spree/credit_card.rb +14 -15
  23. data/app/models/spree/customer_return.rb +18 -25
  24. data/app/models/spree/gateway/bogus.rb +0 -4
  25. data/app/models/spree/line_item.rb +2 -5
  26. data/app/models/spree/option_type.rb +2 -4
  27. data/app/models/spree/option_value.rb +0 -2
  28. data/app/models/spree/order.rb +74 -134
  29. data/app/models/spree/order/checkout.rb +1 -1
  30. data/app/models/spree/order_contents.rb +9 -8
  31. data/app/models/spree/order_updater.rb +8 -1
  32. data/app/models/spree/payment.rb +13 -23
  33. data/app/models/spree/payment/gateway_options.rb +86 -0
  34. data/app/models/spree/payment/processing.rb +8 -39
  35. data/app/models/spree/payment_method.rb +3 -6
  36. data/app/models/spree/price.rb +2 -6
  37. data/app/models/spree/product.rb +27 -16
  38. data/app/models/spree/product_property.rb +1 -5
  39. data/app/models/spree/promotion.rb +7 -15
  40. data/app/models/spree/promotion/actions/create_adjustment.rb +4 -45
  41. data/app/models/spree/promotion/actions/create_item_adjustments.rb +8 -63
  42. data/app/models/spree/promotion/actions/create_line_items.rb +3 -12
  43. data/app/models/spree/promotion/actions/free_shipping.rb +4 -24
  44. data/app/models/spree/promotion/rules/option_value.rb +49 -0
  45. data/app/models/spree/promotion_action.rb +6 -0
  46. data/app/models/spree/promotion_handler/cart.rb +14 -18
  47. data/app/models/spree/promotion_handler/coupon.rb +1 -1
  48. data/app/models/spree/promotion_rule.rb +0 -1
  49. data/app/models/spree/property.rb +0 -2
  50. data/app/models/spree/refund.rb +0 -15
  51. data/app/models/spree/reimbursement.rb +4 -4
  52. data/app/models/spree/reimbursement_type/credit.rb +1 -1
  53. data/app/models/spree/reimbursement_type/original_payment.rb +1 -1
  54. data/app/models/spree/return_authorization.rb +4 -11
  55. data/app/models/spree/return_item.rb +16 -11
  56. data/app/models/spree/return_item/eligibility_validator/default.rb +2 -0
  57. data/app/models/spree/return_item/eligibility_validator/inventory_shipped.rb +16 -0
  58. data/app/models/spree/return_item/eligibility_validator/no_reimbursements.rb +16 -0
  59. data/app/models/spree/shipment.rb +20 -31
  60. data/app/models/spree/shipment_handler.rb +1 -1
  61. data/app/models/spree/shipping_method.rb +12 -13
  62. data/app/models/spree/state.rb +7 -0
  63. data/app/models/spree/state_change.rb +1 -6
  64. data/app/models/spree/stock/availability_validator.rb +9 -10
  65. data/app/models/spree/stock/coordinator.rb +1 -1
  66. data/app/models/spree/stock/estimator.rb +6 -6
  67. data/app/models/spree/stock/quantifier.rb +1 -1
  68. data/app/models/spree/stock_item.rb +1 -7
  69. data/app/models/spree/stock_location.rb +3 -1
  70. data/app/models/spree/stock_movement.rb +1 -8
  71. data/app/models/spree/stock_transfer.rb +11 -5
  72. data/app/models/spree/store.rb +2 -2
  73. data/app/models/spree/tax_rate.rb +30 -55
  74. data/app/models/spree/taxon.rb +8 -8
  75. data/app/models/spree/taxonomy.rb +8 -13
  76. data/app/models/spree/tracker.rb +1 -1
  77. data/app/models/spree/variant.rb +6 -15
  78. data/app/models/spree/zone.rb +43 -9
  79. data/config/initializers/user_class_extensions.rb +0 -12
  80. data/config/locales/en.yml +76 -85
  81. data/config/routes.rb +1 -1
  82. data/db/default/spree/countries.rb +23 -13
  83. data/db/default/spree/states.rb +24 -12
  84. data/db/default/spree/stores.rb +1 -1
  85. data/db/migrate/20120831092320_spree_one_two.rb +36 -36
  86. data/db/migrate/20120831092359_spree_promo_one_two.rb +1 -1
  87. data/db/migrate/20130211190146_create_spree_stock_items.rb +1 -1
  88. data/db/migrate/20130211191120_create_spree_stock_locations.rb +1 -1
  89. data/db/migrate/20130301162924_create_shipping_method_categories.rb +1 -1
  90. data/db/migrate/20130304162240_create_spree_shipping_rates.rb +1 -1
  91. data/db/migrate/20130305143310_create_stock_movements.rb +1 -1
  92. data/db/migrate/20130418125341_create_spree_stock_transfers.rb +1 -1
  93. data/db/migrate/20140205120320_create_spree_payment_capture_events.rb +1 -1
  94. data/db/migrate/20140309024355_create_spree_stores.rb +1 -1
  95. data/db/migrate/20140309033438_create_store_from_preferences.rb +0 -7
  96. data/db/migrate/20140625214618_create_spree_refunds.rb +1 -1
  97. data/db/migrate/20140702140656_create_spree_return_authorization_inventory_unit.rb +1 -1
  98. data/db/migrate/20140713140455_create_spree_return_authorization_reasons.rb +1 -1
  99. data/db/migrate/20140713140527_create_spree_refund_reasons.rb +1 -1
  100. data/db/migrate/20140715182625_create_spree_promotion_categories.rb +1 -1
  101. data/db/migrate/20140718133010_create_spree_customer_returns.rb +1 -1
  102. data/db/migrate/20140725131539_create_spree_reimbursements.rb +1 -1
  103. data/db/migrate/20140731150017_create_spree_reimbursement_types.rb +1 -1
  104. data/db/migrate/20140911173301_add_kind_to_zone.rb +11 -0
  105. data/db/migrate/20141215232040_remove_token_permissions_table.rb +6 -0
  106. data/db/migrate/20141215235502_remove_extra_products_slug_index.rb +5 -0
  107. data/db/migrate/20141217215630_update_product_slug_index.rb +6 -0
  108. data/db/migrate/20141218025915_rename_identifier_to_number_for_payment.rb +5 -0
  109. data/db/migrate/20150121022521_remove_environment_from_payment_method.rb +6 -0
  110. data/db/migrate/20150122145607_add_resellable_to_return_items.rb +5 -0
  111. data/db/migrate/20150122202432_add_code_to_spree_promotion_categories.rb +5 -0
  112. data/db/migrate/20150128032538_remove_environment_from_tracker.rb +6 -0
  113. data/db/migrate/20150128060325_remove_spree_configurations.rb +16 -0
  114. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  115. data/lib/generators/spree/install/templates/config/initializers/spree.rb +4 -0
  116. data/lib/spree/core.rb +2 -12
  117. data/lib/spree/core/controller_helpers/respond_with.rb +8 -18
  118. data/lib/spree/core/engine.rb +1 -7
  119. data/lib/spree/core/routes.rb +1 -1
  120. data/lib/spree/core/version.rb +1 -1
  121. data/lib/spree/money.rb +10 -10
  122. data/lib/spree/permitted_attributes.rb +4 -8
  123. data/lib/spree/testing_support/authorization_helpers.rb +3 -5
  124. data/lib/spree/testing_support/capybara_ext.rb +3 -3
  125. data/lib/spree/testing_support/common_rake.rb +2 -2
  126. data/lib/spree/testing_support/factories/order_factory.rb +3 -13
  127. data/lib/spree/testing_support/factories/payment_method_factory.rb +0 -3
  128. data/lib/spree/testing_support/factories/prototype_factory.rb +5 -0
  129. data/lib/spree/testing_support/factories/return_item_factory.rb +5 -1
  130. data/lib/spree/testing_support/factories/stock_location_factory.rb +3 -3
  131. data/lib/spree/testing_support/factories/tracker_factory.rb +0 -1
  132. data/lib/spree/testing_support/factories/user_factory.rb +1 -1
  133. data/lib/spree/testing_support/factories/zone_factory.rb +8 -0
  134. data/lib/tasks/core.rake +1 -1
  135. data/lib/tasks/email.rake +6 -3
  136. metadata +48 -35
  137. data/app/helpers/spree/checkout_helper.rb +0 -31
  138. data/app/helpers/spree/orders_helper.rb +0 -17
  139. data/app/helpers/spree/store_helper.rb +0 -16
  140. data/app/helpers/spree/taxons_helper.rb +0 -19
  141. data/app/models/concerns/spree/ransackable_attributes.rb +0 -19
  142. data/app/models/friendly_id/slug_decorator.rb +0 -3
  143. data/app/models/spree/billing_integration.rb +0 -21
  144. data/app/models/spree/configuration.rb +0 -5
  145. data/app/models/spree/item_adjustments.rb +0 -82
  146. data/app/models/spree/order_merger.rb +0 -65
  147. data/app/models/spree/order_populator.rb +0 -43
  148. data/app/models/spree/product_scope/scopes.rb +0 -47
  149. data/app/models/spree/variant/scopes.rb +0 -42
  150. data/db/migrate/20150515211137_fix_adjustment_order_id.rb +0 -70
  151. data/db/migrate/20150522181728_add_deleted_at_to_friendly_id_slugs.rb +0 -6
  152. data/db/migrate/20150707204155_enable_acts_as_paranoid_on_calculators.rb +0 -6
  153. data/lib/spree/core/controller_helpers/ssl.rb +0 -60
  154. data/lib/spree/core/permalinks.rb +0 -71
  155. data/lib/spree/testing_support/factories/configuration_factory.rb +0 -6
@@ -60,10 +60,6 @@ module Spree
60
60
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
61
61
  end
62
62
 
63
- def cancel(_response_code)
64
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
65
- end
66
-
67
63
  def test?
68
64
  # Test mode is not really relevant with bogus gateway (no such thing as live server)
69
65
  true
@@ -35,9 +35,6 @@ module Spree
35
35
 
36
36
  attr_accessor :target_shipment
37
37
 
38
- self.whitelisted_ransackable_associations = ['variant']
39
- self.whitelisted_ransackable_attributes = ['variant_id']
40
-
41
38
  def copy_price
42
39
  if variant
43
40
  self.price = variant.price if price.nil?
@@ -141,11 +138,11 @@ module Spree
141
138
  end
142
139
 
143
140
  def recalculate_adjustments
144
- Spree::ItemAdjustments.new(self).update
141
+ Adjustable::AdjustmentsUpdater.update(self)
145
142
  end
146
143
 
147
144
  def update_tax_charge
148
- Spree::TaxRate.adjust(order.tax_zone, [self])
145
+ Spree::TaxRate.adjust(order, [self])
149
146
  end
150
147
 
151
148
  def ensure_proper_currency
@@ -1,16 +1,14 @@
1
1
  module Spree
2
2
  class OptionType < Spree::Base
3
- acts_as_list
4
-
5
3
  has_many :option_values, -> { order(:position) }, dependent: :destroy, inverse_of: :option_type
6
4
  has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
7
5
  has_many :products, through: :product_option_types
8
6
  has_and_belongs_to_many :prototypes, join_table: 'spree_option_types_prototypes'
9
7
 
10
- validates :name, presence: true, uniqueness: true
8
+ validates :name, presence: true, uniqueness: true
11
9
  validates :presentation, presence: true
12
10
 
13
- default_scope -> { order("#{self.table_name}.position") }
11
+ default_scope { order("#{self.table_name}.position") }
14
12
 
15
13
  accepts_nested_attributes_for :option_values, reject_if: lambda { |ov| ov[:name].blank? || ov[:presentation].blank? }, allow_destroy: true
16
14
 
@@ -9,8 +9,6 @@ module Spree
9
9
 
10
10
  after_touch :touch_all_variants
11
11
 
12
- self.whitelisted_ransackable_attributes = ['presentation']
13
-
14
12
  def touch_all_variants
15
13
  variants.update_all(updated_at: Time.current)
16
14
  end
@@ -3,14 +3,26 @@ require 'spree/order/checkout'
3
3
 
4
4
  module Spree
5
5
  class Order < Spree::Base
6
-
7
- ORDER_NUMBER_LENGTH = 9
8
- ORDER_NUMBER_LETTERS = false
9
- ORDER_NUMBER_PREFIX = 'R'
6
+ extend FriendlyId
7
+ friendly_id :number, slug_column: :number, use: :slugged
10
8
 
11
9
  include Spree::Order::Checkout
12
10
  include Spree::Order::CurrencyUpdater
13
11
  include Spree::Order::Payments
12
+ include Spree::NumberGenerator
13
+
14
+ def generate_number(options = {})
15
+ options[:prefix] ||= 'R'
16
+ super(options)
17
+ end
18
+
19
+ extend Spree::DisplayMoney
20
+ money_methods :outstanding_balance, :item_total, :adjustment_total,
21
+ :included_tax_total, :additional_tax_total, :tax_total,
22
+ :shipment_total, :promo_total, :total
23
+
24
+ alias :display_ship_total :display_shipment_total
25
+ alias_attribute :ship_total, :shipment_total
14
26
 
15
27
  checkout_flow do
16
28
  go_to_state :address
@@ -21,9 +33,6 @@ module Spree
21
33
  remove_transition from: :delivery, to: :confirm
22
34
  end
23
35
 
24
- self.whitelisted_ransackable_associations = %w[shipments user promotions bill_address ship_address line_items]
25
- self.whitelisted_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total considered_risky]
26
-
27
36
  attr_reader :coupon_code
28
37
  attr_accessor :temporary_address, :temporary_credit_card
29
38
 
@@ -44,10 +53,9 @@ module Spree
44
53
 
45
54
  belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address'
46
55
  alias_attribute :shipping_address, :ship_address
47
- alias_attribute :ship_total, :shipment_total
48
56
 
49
57
  belongs_to :store, class_name: 'Spree::Store'
50
- has_many :state_changes, as: :stateful, dependent: :destroy
58
+ has_many :state_changes, as: :stateful
51
59
  has_many :line_items, -> { order("#{LineItem.table_name}.created_at ASC") }, dependent: :destroy, inverse_of: :order
52
60
  has_many :payments, dependent: :destroy
53
61
  has_many :return_authorizations, dependent: :destroy, inverse_of: :order
@@ -59,11 +67,6 @@ module Spree
59
67
  has_many :products, through: :variants
60
68
  has_many :variants, through: :line_items
61
69
  has_many :refunds, through: :payments
62
- has_many :all_adjustments,
63
- class_name: 'Spree::Adjustment',
64
- foreign_key: :order_id,
65
- dependent: :destroy,
66
- inverse_of: :order
67
70
 
68
71
  has_and_belongs_to_many :promotions, join_table: 'spree_orders_promotions'
69
72
 
@@ -81,24 +84,18 @@ module Spree
81
84
 
82
85
  # Needs to happen before save_permalink is called
83
86
  before_validation :set_currency
84
- before_validation :generate_order_number, on: :create
85
87
  before_validation :clone_billing_address, if: :use_billing?
86
88
  attr_accessor :use_billing
87
89
 
88
-
89
90
  before_create :create_token
90
91
  before_create :link_by_email
91
92
  before_update :homogenize_line_item_currencies, if: :currency_changed?
92
93
 
93
94
  validates :email, presence: true, if: :require_email
94
95
  validates :email, email: true, if: :require_email, allow_blank: true
95
- validates :number, presence: true, uniqueness: { allow_blank: true }
96
96
  validate :has_available_shipment
97
97
 
98
- make_permalink field: :number
99
-
100
98
  delegate :update_totals, :persist_totals, :to => :updater
101
- delegate :merge!, to: :merger
102
99
 
103
100
  class_attribute :update_hooks
104
101
  self.update_hooks = Set.new
@@ -106,24 +103,12 @@ module Spree
106
103
  class_attribute :line_item_comparison_hooks
107
104
  self.line_item_comparison_hooks = Set.new
108
105
 
109
- def self.by_number(number)
110
- where(number: number)
111
- end
112
-
113
106
  scope :created_between, ->(start_date, end_date) { where(created_at: start_date..end_date) }
114
107
  scope :completed_between, ->(start_date, end_date) { where(completed_at: start_date..end_date) }
115
108
 
116
109
  # shows completed orders first, by their completed_at date, then uncompleted orders by their created_at
117
110
  scope :reverse_chronological, -> { order('spree_orders.completed_at IS NULL', completed_at: :desc, created_at: :desc) }
118
111
 
119
- def self.by_customer(customer)
120
- joins(:user).where("#{Spree.user_class.table_name}.email" => customer)
121
- end
122
-
123
- def self.by_state(state)
124
- where(state: state)
125
- end
126
-
127
112
  def self.complete
128
113
  where.not(completed_at: nil)
129
114
  end
@@ -144,6 +129,11 @@ module Spree
144
129
  self.line_item_comparison_hooks.add(hook)
145
130
  end
146
131
 
132
+ def all_adjustments
133
+ Adjustment.where("order_id = :order_id OR (adjustable_id = :order_id AND adjustable_type = 'Spree::Order')",
134
+ order_id: self.id)
135
+ end
136
+
147
137
  # For compatiblity with Calculator::PriceSack
148
138
  def amount
149
139
  line_items.inject(0.0) { |sum, li| sum + li.amount }
@@ -158,47 +148,10 @@ module Spree
158
148
  self[:currency] || Spree::Config[:currency]
159
149
  end
160
150
 
161
- def display_outstanding_balance
162
- Spree::Money.new(outstanding_balance, { currency: currency })
163
- end
164
-
165
- def display_item_total
166
- Spree::Money.new(item_total, { currency: currency })
167
- end
168
-
169
- def display_adjustment_total
170
- Spree::Money.new(adjustment_total, { currency: currency })
171
- end
172
-
173
- def display_included_tax_total
174
- Spree::Money.new(included_tax_total, { currency: currency })
175
- end
176
-
177
- def display_additional_tax_total
178
- Spree::Money.new(additional_tax_total, { currency: currency })
179
- end
180
-
181
- def display_tax_total
182
- Spree::Money.new(tax_total, { currency: currency })
183
- end
184
-
185
- def display_shipment_total
186
- Spree::Money.new(shipment_total, { currency: currency })
187
- end
188
- alias :display_ship_total :display_shipment_total
189
-
190
- def display_total
191
- Spree::Money.new(total, { currency: currency })
192
- end
193
-
194
151
  def shipping_discount
195
152
  shipment_adjustments.eligible.sum(:amount) * - 1
196
153
  end
197
154
 
198
- def to_param
199
- number.to_s.to_url.upcase
200
- end
201
-
202
155
  def completed?
203
156
  completed_at.present?
204
157
  end
@@ -249,10 +202,6 @@ module Spree
249
202
  updater.update
250
203
  end
251
204
 
252
- def merger
253
- @merger ||= Spree::OrderMerger.new(self)
254
- end
255
-
256
205
  def clone_billing_address
257
206
  if bill_address and self.ship_address.nil?
258
207
  self.ship_address = bill_address.clone
@@ -289,35 +238,6 @@ module Spree
289
238
  end
290
239
  end
291
240
 
292
- def generate_order_number(options = {})
293
- options[:length] ||= ORDER_NUMBER_LENGTH
294
- options[:letters] ||= ORDER_NUMBER_LETTERS
295
- options[:prefix] ||= ORDER_NUMBER_PREFIX
296
-
297
- possible = (0..9).to_a
298
- possible += ('A'..'Z').to_a if options[:letters]
299
-
300
- self.number ||= loop do
301
- # Make a random number.
302
- random = "#{options[:prefix]}#{(0...options[:length]).map { possible.shuffle.first }.join}"
303
- # Use the random number if no other order exists with it.
304
- if self.class.exists?(number: random)
305
- # If over half of all possible options are taken add another digit.
306
- options[:length] += 1 if self.class.count > (10 ** options[:length] / 2)
307
- else
308
- break random
309
- end
310
- end
311
- end
312
-
313
- def shipped_shipments
314
- shipments.shipped
315
- end
316
-
317
- def contains?(variant, options = {})
318
- find_line_item_by_variant(variant, options).present?
319
- end
320
-
321
241
  def quantity_of(variant, options = {})
322
242
  line_item = find_line_item_by_variant(variant, options)
323
243
  line_item ? line_item.quantity : 0
@@ -350,22 +270,13 @@ module Spree
350
270
  # Creates new tax charges if there are any applicable rates. If prices already
351
271
  # include taxes then price adjustments are created instead.
352
272
  def create_tax_charge!
353
- # We want to only look up the applicable tax zone once and pass it to TaxRate calculation to avoid duplicated lookups.
354
- order_tax_zone = self.tax_zone
355
- Spree::TaxRate.adjust(order_tax_zone, line_items)
356
- Spree::TaxRate.adjust(order_tax_zone, shipments) if shipments.any?
273
+ Spree::TaxRate.adjust(self, line_items)
274
+ Spree::TaxRate.adjust(self, shipments) if shipments.any?
357
275
  end
358
276
 
359
277
  def outstanding_balance
360
278
  if state == 'canceled'
361
279
  -1 * payment_total
362
- elsif reimbursements.includes(:refunds).size > 0
363
- reimbursed = reimbursements.includes(:refunds).inject(0) do |sum, reimbursement|
364
- sum + reimbursement.refunds.sum(:amount)
365
- end
366
- # If reimbursement has happened add it back to total to prevent balance_due payment state
367
- # See: https://github.com/spree/spree/issues/6229
368
- total - (payment_total + reimbursed)
369
280
  else
370
281
  total - payment_total
371
282
  end
@@ -426,7 +337,7 @@ module Spree
426
337
  end
427
338
 
428
339
  def deliver_order_confirmation_email
429
- OrderMailer.confirm_email(self.id).deliver
340
+ OrderMailer.confirm_email(id).deliver_later
430
341
  update_column(:confirmation_delivered, true)
431
342
  end
432
343
 
@@ -474,12 +385,44 @@ module Spree
474
385
  end
475
386
  end
476
387
 
388
+ def merge!(order, user = nil)
389
+ order.line_items.each do |other_order_line_item|
390
+ next unless other_order_line_item.currency == currency
391
+
392
+ # Compare the line items of the other order with mine.
393
+ # Make sure you allow any extensions to chime in on whether or
394
+ # not the extension-specific parts of the line item match
395
+ current_line_item = self.line_items.detect { |my_li|
396
+ my_li.variant == other_order_line_item.variant &&
397
+ self.line_item_comparison_hooks.all? { |hook|
398
+ self.send(hook, my_li, other_order_line_item.serializable_hash)
399
+ }
400
+ }
401
+ if current_line_item
402
+ current_line_item.quantity += other_order_line_item.quantity
403
+ current_line_item.save!
404
+ else
405
+ other_order_line_item.order_id = self.id
406
+ other_order_line_item.save!
407
+ end
408
+ end
409
+
410
+ self.associate_user!(user) if !self.user && !user.blank?
411
+
412
+ updater.update_item_count
413
+ updater.update_item_total
414
+ updater.persist_totals
415
+
416
+ # So that the destroy doesn't take out line items which may have been re-assigned
417
+ order.line_items.reload
418
+ order.destroy
419
+ end
420
+
477
421
  def empty!
478
422
  line_items.destroy_all
479
423
  updater.update_item_count
480
424
  adjustments.destroy_all
481
425
  shipments.destroy_all
482
- state_changes.destroy_all
483
426
 
484
427
  update_totals
485
428
  persist_totals
@@ -519,14 +462,14 @@ module Spree
519
462
  end
520
463
 
521
464
  def create_proposed_shipments
522
- all_adjustments.shipping.delete_all
465
+ adjustments.shipping.delete_all
523
466
  shipments.destroy_all
524
467
  self.shipments = Spree::Stock::Coordinator.new(self).shipments
525
468
  end
526
469
 
527
470
  def apply_free_shipping_promotions
528
471
  Spree::PromotionHandler::FreeShipping.new(self).activate
529
- shipments.each { |shipment| ItemAdjustments.new(shipment).update }
472
+ shipments.each { |shipment| Adjustable::AdjustmentsUpdater.update(shipment) }
530
473
  updater.update_shipment_total
531
474
  persist_totals
532
475
  end
@@ -552,8 +495,8 @@ module Spree
552
495
  self.next! if self.line_items.size > 0
553
496
  end
554
497
 
555
- def refresh_shipment_rates
556
- shipments.map &:refresh_rates
498
+ def refresh_shipment_rates(shipping_method_filter = ShippingMethod::DISPLAY_ON_FRONT_END)
499
+ shipments.map { |s| s.refresh_rates(shipping_method_filter) }
557
500
  end
558
501
 
559
502
  def shipping_eq_billing_address?
@@ -612,19 +555,6 @@ module Spree
612
555
  update_column(:considered_risky, false)
613
556
  end
614
557
 
615
- # moved from api order_decorator. This is a better place for it.
616
- def update_line_items(line_item_params)
617
- return if line_item_params.blank?
618
- line_item_params.each_value do |attributes|
619
- if attributes[:id].present?
620
- self.line_items.find(attributes[:id]).update_attributes!(attributes)
621
- else
622
- self.line_items.create!(attributes)
623
- end
624
- end
625
- self.ensure_updated_shipments
626
- end
627
-
628
558
  def reload(options=nil)
629
559
  remove_instance_variable(:@tax_zone) if defined?(@tax_zone)
630
560
  super
@@ -643,6 +573,16 @@ module Spree
643
573
  payments.offset_payment.exists? # how old versions of spree stored refunds
644
574
  end
645
575
 
576
+ # determines whether the inventory is fully discounted
577
+ #
578
+ # Returns
579
+ # - true if inventory amount is the exact negative of inventory related adjustments
580
+ # - false otherwise
581
+ def fully_discounted?
582
+ adjustment_total + line_items.map(&:final_amount).sum == 0.0
583
+ end
584
+ alias_method :fully_discounted, :fully_discounted?
585
+
646
586
  private
647
587
 
648
588
  def link_by_email
@@ -671,7 +611,7 @@ module Spree
671
611
  if shipments.empty? || shipments.any? { |shipment| shipment.shipping_rates.blank? }
672
612
  # After this point, order redirects back to 'address' state and asks user to pick a proper address
673
613
  # Therefore, shipments are not necessary at this point.
674
- shipments.destroy_all
614
+ shipments.delete_all
675
615
  errors.add(:base, Spree.t(:items_cannot_be_shipped)) and return false
676
616
  end
677
617
  end
@@ -684,7 +624,7 @@ module Spree
684
624
  end
685
625
 
686
626
  def send_cancel_email
687
- OrderMailer.cancel_email(self.id).deliver
627
+ OrderMailer.cancel_email(id).deliver_later
688
628
  end
689
629
 
690
630
  def after_resume
@@ -34,7 +34,7 @@ module Spree
34
34
  klass = self
35
35
 
36
36
  # To avoid a ton of warnings when the state machine is re-defined
37
- StateMachine::Machine.ignore_method_conflicts = true
37
+ StateMachines::Machine.ignore_method_conflicts = true
38
38
  # To avoid multiple occurrences of the same transition being defined
39
39
  # On first definition, state_machines will not be defined
40
40
  state_machines.clear if respond_to?(:state_machines)