spree_core 3.7.11 → 4.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/app/controllers/spree/base_controller.rb +0 -1
  4. data/app/finders/spree/taxons/find.rb +6 -5
  5. data/app/helpers/spree/base_helper.rb +0 -9
  6. data/app/helpers/spree/products_helper.rb +1 -1
  7. data/app/models/concerns/spree/product_scopes.rb +254 -0
  8. data/app/models/concerns/spree/user_address.rb +5 -2
  9. data/app/models/friendly_id/slug_decorator.rb +8 -2
  10. data/app/models/spree/ability.rb +21 -22
  11. data/app/models/spree/address.rb +37 -24
  12. data/app/models/spree/adjustment.rb +0 -10
  13. data/app/models/spree/app_dependencies.rb +2 -2
  14. data/app/models/spree/asset.rb +1 -12
  15. data/app/models/spree/country.rb +2 -2
  16. data/app/models/spree/gateway/bogus.rb +1 -1
  17. data/app/models/spree/image.rb +8 -1
  18. data/app/models/spree/image/configuration/active_storage.rb +0 -2
  19. data/app/models/spree/order.rb +13 -78
  20. data/app/models/spree/order/address_book.rb +86 -0
  21. data/app/models/spree/order/checkout.rb +4 -22
  22. data/app/models/spree/order/currency_updater.rb +1 -1
  23. data/app/models/spree/order/store_credit.rb +0 -18
  24. data/app/models/spree/order_merger.rb +1 -0
  25. data/app/models/spree/payment.rb +4 -2
  26. data/app/models/spree/payment/gateway_options.rb +1 -1
  27. data/app/models/spree/payment/processing.rb +2 -0
  28. data/app/models/spree/preferences/configuration.rb +1 -1
  29. data/app/models/spree/product.rb +2 -3
  30. data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
  31. data/app/models/spree/return_item.rb +1 -1
  32. data/app/models/spree/return_item/eligibility_validator/default.rb +2 -0
  33. data/app/models/spree/return_item/eligibility_validator/{rma_required.rb → r_m_a_required.rb} +0 -0
  34. data/app/models/spree/shipment.rb +1 -1
  35. data/app/models/spree/store_credit.rb +4 -5
  36. data/app/models/spree/taxon_image.rb +1 -1
  37. data/app/models/spree/taxonomy.rb +1 -1
  38. data/app/services/spree/cart/add_item.rb +3 -1
  39. data/app/services/spree/cart/update.rb +1 -1
  40. data/config/locales/en.yml +15 -0
  41. data/db/default/spree/stores.rb +1 -0
  42. data/db/default/spree/zones.rb +16 -0
  43. data/db/migrate/20140806144901_add_type_to_reimbursement_type.rb +1 -1
  44. data/db/migrate/20141101231208_fix_adjustment_order_presence.rb +2 -2
  45. data/db/migrate/20170323151450_add_missing_unique_indexes_for_unique_attributes.rb +1 -1
  46. data/db/migrate/20190305121659_add_iso_and_iso3_validation_on_presence_and_uniqueness.rb +18 -0
  47. data/db/migrate/20190523092729_add_user_id_and_deleted_at_to_spree_addresses.rb +12 -0
  48. data/lib/generators/spree/dummy/dummy_generator.rb +2 -0
  49. data/lib/spree/core.rb +0 -2
  50. data/lib/spree/core/importer/order.rb +64 -103
  51. data/lib/spree/core/importer/product.rb +2 -2
  52. data/lib/spree/core/product_duplicator.rb +1 -5
  53. data/lib/spree/core/version.rb +1 -1
  54. data/lib/spree/permitted_attributes.rb +3 -1
  55. data/lib/spree/testing_support/ability_helpers.rb +3 -11
  56. data/lib/spree/testing_support/capybara_config.rb +4 -1
  57. data/lib/spree/testing_support/capybara_ext.rb +22 -98
  58. data/lib/spree/testing_support/controller_requests.rb +36 -26
  59. data/lib/spree/testing_support/factories/image_factory.rb +2 -6
  60. data/lib/spree/testing_support/factories/return_item_factory.rb +2 -2
  61. data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
  62. data/lib/spree/testing_support/i18n.rb +6 -8
  63. data/lib/spree/testing_support/image_helpers.rb +5 -11
  64. data/lib/tasks/exchanges.rake +35 -37
  65. data/spree_core.gemspec +11 -14
  66. metadata +63 -103
  67. data/app/models/concerns/spree/acts_as_taggable.rb +0 -11
  68. data/app/models/spree/image/configuration/paperclip.rb +0 -64
  69. data/app/models/spree/order_contents.rb +0 -54
  70. data/app/models/spree/product/scopes.rb +0 -250
  71. data/app/models/spree/tag.rb +0 -4
  72. data/app/models/spree/taxon_image/configuration/paperclip.rb +0 -27
  73. data/config/initializers/acts_as_taggable_on.rb +0 -9
  74. data/config/initializers/use_paperclip.rb +0 -3
  75. data/db/migrate/20160511071954_acts_as_taggable_on_spree_migration.rb +0 -40
  76. data/db/migrate/20160511072249_change_collation_for_spree_tag_names.rb +0 -9
  77. data/db/migrate/20160511072335_add_missing_indexes_to_spree_taggings.rb +0 -14
  78. data/lib/spree/core/controller_helpers/respond_with.rb +0 -67
  79. data/lib/spree/responder.rb +0 -44
  80. data/lib/spree/testing_support/factories/tag_factory.rb +0 -5
@@ -47,6 +47,7 @@ module Spree
47
47
  handle_error(current_line_item) unless current_line_item.save
48
48
  else
49
49
  other_order_line_item.order_id = order.id
50
+ other_order_line_item.adjustments.update_all(order_id: order.id)
50
51
  handle_error(other_order_line_item) unless other_order_line_item.save
51
52
  end
52
53
  end
@@ -1,3 +1,5 @@
1
+ require_dependency 'spree/payment/processing'
2
+
1
3
  module Spree
2
4
  class Payment < Spree::Base
3
5
  include Spree::Core::NumberGenerator.new(prefix: 'P', letters: true, length: 7)
@@ -227,7 +229,7 @@ module Spree
227
229
  state: 'pending',
228
230
  capture_on_dispatch: true
229
231
  ).authorize!
230
- update_attributes(amount: captured_amount)
232
+ update(amount: captured_amount)
231
233
  end
232
234
  end
233
235
 
@@ -252,7 +254,7 @@ module Spree
252
254
  return unless store_credit? && source.is_a?(Spree::StoreCredit)
253
255
 
254
256
  # creates the store credit event
255
- source.update_attributes!(action: Spree::StoreCredit::ELIGIBLE_ACTION,
257
+ source.update!(action: Spree::StoreCredit::ELIGIBLE_ACTION,
256
258
  action_amount: amount,
257
259
  action_authorization_code: response_code)
258
260
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- class Payment
2
+ class Payment < Spree::Base
3
3
  class GatewayOptions
4
4
  def initialize(payment)
5
5
  @payment = payment
@@ -1,3 +1,5 @@
1
+ require_dependency 'spree/payment/gateway_options'
2
+
1
3
  module Spree
2
4
  class Payment < Spree::Base
3
5
  module Processing
@@ -29,7 +29,7 @@ module Spree::Preferences
29
29
  end
30
30
 
31
31
  def preferences
32
- ScopedStore.new(self.class.name.underscore)
32
+ ::Spree::Preferences::ScopedStore.new(self.class.name.underscore)
33
33
  end
34
34
 
35
35
  def reset
@@ -21,7 +21,8 @@
21
21
  module Spree
22
22
  class Product < Spree::Base
23
23
  extend FriendlyId
24
- include ActsAsTaggable
24
+ include Spree::ProductScopes
25
+
25
26
  friendly_id :slug_candidates, use: :history
26
27
 
27
28
  acts_as_paranoid
@@ -432,5 +433,3 @@ module Spree
432
433
  end
433
434
  end
434
435
  end
435
-
436
- require_dependency 'spree/product/scopes'
@@ -29,7 +29,7 @@ module Spree
29
29
  additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
30
30
  included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
31
31
 
32
- return_item.update_attributes!(additional_tax_total: additional_tax_total,
32
+ return_item.update!(additional_tax_total: additional_tax_total,
33
33
  included_tax_total: included_tax_total)
34
34
  end
35
35
  end
@@ -171,7 +171,7 @@ module Spree
171
171
  private
172
172
 
173
173
  def persist_acceptance_status_errors
174
- update_attributes(acceptance_status_errors: validator.errors)
174
+ update(acceptance_status_errors: validator.errors)
175
175
  end
176
176
 
177
177
  def stock_item
@@ -1,3 +1,5 @@
1
+ require_relative 'r_m_a_required'
2
+
1
3
  module Spree
2
4
  class ReturnItem::EligibilityValidator::Default < Spree::ReturnItem::EligibilityValidator::BaseValidator
3
5
  class_attribute :permitted_eligibility_validators
@@ -307,7 +307,7 @@ module Spree
307
307
 
308
308
  # Update Shipment and make sure Order states follow the shipment changes
309
309
  def update_attributes_and_order(params = {})
310
- if update_attributes params
310
+ if update params
311
311
  if params.key? :selected_shipping_rate_id
312
312
  # Changing the selected Shipping Rate won't update the cost (for now)
313
313
  # so we persist the Shipment#cost before calculating order shipment
@@ -52,9 +52,8 @@ module Spree
52
52
  else
53
53
  authorization_code = generate_authorization_code
54
54
  end
55
-
56
55
  if validate_authorization(amount, order_currency)
57
- update_attributes!(
56
+ update!(
58
57
  action: AUTHORIZE_ACTION,
59
58
  action_amount: amount,
60
59
  action_originator: options[:action_originator],
@@ -85,7 +84,7 @@ module Spree
85
84
  errors.add(:base, Spree.t('store_credit_payment_method.currency_mismatch'))
86
85
  false
87
86
  else
88
- update_attributes!(
87
+ update!(
89
88
  action: CAPTURE_ACTION,
90
89
  action_amount: amount,
91
90
  action_originator: options[:action_originator],
@@ -103,7 +102,7 @@ module Spree
103
102
 
104
103
  def void(authorization_code, options = {})
105
104
  if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
106
- update_attributes!(
105
+ update!(
107
106
  action: VOID_ACTION,
108
107
  action_amount: auth_event.amount,
109
108
  action_authorization_code: authorization_code,
@@ -209,7 +208,7 @@ module Spree
209
208
  store_credit_events.where(action: ALLOCATION_ACTION).first_or_initialize
210
209
  end
211
210
 
212
- event.update_attributes!(
211
+ event.update!(
213
212
  amount: action_amount || amount,
214
213
  authorization_code: action_authorization_code || event.authorization_code || generate_authorization_code,
215
214
  user_total_amount: user.total_available_store_credit,
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class TaxonImage < Asset
3
- include Rails.application.config.use_paperclip ? Configuration::Paperclip : Configuration::ActiveStorage
3
+ include Configuration::ActiveStorage
4
4
  include Rails.application.routes.url_helpers
5
5
 
6
6
  def styles
@@ -19,7 +19,7 @@ module Spree
19
19
  end
20
20
 
21
21
  def set_root_taxon_name
22
- root.update_attributes(name: name)
22
+ root.update(name: name)
23
23
  end
24
24
  end
25
25
  end
@@ -35,7 +35,9 @@ module Spree
35
35
 
36
36
  return failure(line_item) unless line_item.save
37
37
 
38
- ::Spree::TaxRate.adjust(order, [line_item.reload]) if line_item_created
38
+ line_item.reload.update_price
39
+
40
+ ::Spree::TaxRate.adjust(order, [line_item]) if line_item_created
39
41
  success(order: order, line_item: line_item, line_item_created: line_item_created, options: options)
40
42
  end
41
43
  end
@@ -4,7 +4,7 @@ module Spree
4
4
  prepend Spree::ServiceModule::Base
5
5
 
6
6
  def call(order:, params:)
7
- return failure(order) unless order.update_attributes(filter_order_items(order, params))
7
+ return failure(order) unless order.update(filter_order_items(order, params))
8
8
 
9
9
  order.line_items = order.line_items.select { |li| li.quantity > 0 }
10
10
  # Update totals, then check if the order is eligible for any cart promotions.
@@ -478,6 +478,20 @@ en:
478
478
  address1: Address
479
479
  address2: Address (contd.)
480
480
  addresses: Addresses
481
+ address_book:
482
+ other_address: "Other address"
483
+ add_new_shipping_address: "Add new address"
484
+ new_shipping_address: "New Address"
485
+ edit_shipping_address: "Edit Address"
486
+ no_shipping_addresses_on_file: "No addresses on file"
487
+ shipping_addresses: "Addresses"
488
+ successfully_created: "Address has been successfully created."
489
+ successfully_removed: "Address has been successfully removed."
490
+ successfully_saved: "Saved successfully"
491
+ unsuccessfully_saved: "There was an error while trying to save your address."
492
+ successfully_updated: "Updated successfully"
493
+ unsuccessfully_updated: "There was an update while trying to update your address."
494
+ save: "Save"
481
495
  adjustable: Adjustable
482
496
  adjustment: Adjustment
483
497
  adjustment_amount: Amount
@@ -682,6 +696,7 @@ en:
682
696
  date_range: Date Range
683
697
  default: Default
684
698
  default_country_cannot_be_deleted: Default country cannot be deleted
699
+ default_currency: Default currency
685
700
  default_refund_amount: Default Refund Amount
686
701
  default_tax: Default Tax
687
702
  default_tax_zone: Default Tax Zone
@@ -5,5 +5,6 @@ unless Spree::Store.where(code: 'spree').exists?
5
5
  s.name = 'Spree Demo Site'
6
6
  s.url = 'example.com'
7
7
  s.mail_from_address = 'spree@example.com'
8
+ s.default_currency = 'USD'
8
9
  end.save!
9
10
  end
@@ -1,5 +1,8 @@
1
1
  eu_vat = Spree::Zone.where(name: 'EU_VAT', description: 'Countries that make up the EU VAT zone.', kind: 'country').first_or_create!
2
2
  north_america = Spree::Zone.where(name: 'North America', description: 'USA + Canada', kind: 'country').first_or_create!
3
+ south_america = Spree::Zone.where(name: 'South America', description: 'South America', kind: 'country').first_or_create!
4
+ middle_east = Spree::Zone.where(name: 'Middle East', description: 'Middle East', kind: 'country').first_or_create!
5
+ asia = Spree::Zone.where(name: 'Asia', description: 'Asia', kind: 'country').first_or_create!
3
6
 
4
7
  %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 HR CZ GR).each do |name|
5
8
  eu_vat.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
@@ -8,3 +11,16 @@ end
8
11
  %w(US CA).each do |name|
9
12
  north_america.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
10
13
  end
14
+
15
+ %w(BH CY EG IR IQ IL JO KW LB OM QA SA SY TR AE YE).each do |name|
16
+ middle_east.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
17
+ end
18
+
19
+ %w(AF AM AZ BH BD BT BN KH CN CX CC IO GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NP
20
+ KP OM PK PS PH QA SA SG KR LK SY TW TJ TH TR TM AE UZ VN YE).each do |name|
21
+ asia.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
22
+ end
23
+
24
+ %w(AR BO BR CL CO EC FK GF GY PY PE SR UY VE).each do |name|
25
+ south_america.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
26
+ end
@@ -4,6 +4,6 @@ class AddTypeToReimbursementType < ActiveRecord::Migration[4.2]
4
4
  add_index :spree_reimbursement_types, :type
5
5
 
6
6
  Spree::ReimbursementType.reset_column_information
7
- Spree::ReimbursementType.find_by(name: Spree::ReimbursementType::ORIGINAL).update_attributes!(type: 'Spree::ReimbursementType::OriginalPayment')
7
+ Spree::ReimbursementType.find_by(name: Spree::ReimbursementType::ORIGINAL).update!(type: 'Spree::ReimbursementType::OriginalPayment')
8
8
  end
9
9
  end
@@ -4,9 +4,9 @@ class FixAdjustmentOrderPresence < ActiveRecord::Migration[4.2]
4
4
  Spree::Adjustment.where(order: nil).find_each do |adjustment|
5
5
  adjustable = adjustment.adjustable
6
6
  if adjustable.is_a? Spree::Order
7
- adjustment.update_attributes!(order_id: adjustable.id)
7
+ adjustment.update!(order_id: adjustable.id)
8
8
  else
9
- adjustment.update_attributes!(adjustable: adjustable.order)
9
+ adjustment.update!(adjustable: adjustable.order)
10
10
  end
11
11
  end
12
12
  end
@@ -26,7 +26,7 @@ class AddMissingUniqueIndexesForUniqueAttributes < ActiveRecord::Migration[5.0]
26
26
 
27
27
  remove_index table_name, column if index_exists?(table_name, column)
28
28
  if supports_expression_index?
29
- add_index table_name, "lower(#{column})", unique: true
29
+ add_index table_name, "(lower(#{column}))", unique: true
30
30
  else
31
31
  add_index table_name, column, unique: true
32
32
  end
@@ -0,0 +1,18 @@
1
+ class AddIsoAndIso3ValidationOnPresenceAndUniqueness < ActiveRecord::Migration[5.2]
2
+ def up
3
+ Spree::Country.where.not(id: Spree::Country.group(:iso).select("min(id)")).destroy_all
4
+ Spree::Country.where.not(id: Spree::Country.group(:iso3).select("min(id)")).destroy_all
5
+
6
+ change_column_null(:spree_countries, :iso, false)
7
+ change_column_null(:spree_countries, :iso3, false)
8
+ add_index :spree_countries, :iso, unique: true
9
+ add_index :spree_countries, :iso3, unique: true
10
+ end
11
+
12
+ def down
13
+ change_column_null(:spree_countries, :iso, true)
14
+ change_column_null(:spree_countries, :iso3, true)
15
+ remove_index :spree_countries, :iso, unique: true
16
+ remove_index :spree_countries, :iso3, unique: true
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # this migration does the same as this two from SpreeAddressBook
2
+ # https://github.com/spree-contrib/spree_address_book/blob/master/db/migrate/20110302102208_add_user_id_and_deleted_at_to_addresses.rb
3
+ # https://github.com/spree-contrib/spree_address_book/blob/master/db/migrate/20170405133031_add_missing_indexes.rb
4
+ class AddUserIdAndDeletedAtToSpreeAddresses < ActiveRecord::Migration[5.2]
5
+ def change
6
+ add_column :spree_addresses, :user_id, :integer unless column_exists?(:spree_addresses, :user_id)
7
+ add_index :spree_addresses, :user_id unless index_exists?(:spree_addresses, :user_id)
8
+
9
+ add_column :spree_addresses, :deleted_at, :datetime unless column_exists?(:spree_addresses, :deleted_at)
10
+ add_index :spree_addresses, :deleted_at unless index_exists?(:spree_addresses, :deleted_at)
11
+ end
12
+ end
@@ -38,6 +38,8 @@ module Spree
38
38
  opts[:skip_spring] = true
39
39
  opts[:skip_test] = true
40
40
  opts[:skip_yarn] = true
41
+ opts[:skip_javascript] = true
42
+ opts[:skip_bootsnap] = true
41
43
 
42
44
  puts 'Generating dummy Rails application...'
43
45
  invoke Rails::Generators::AppGenerator,
@@ -7,7 +7,6 @@ require 'friendly_id'
7
7
  require 'kaminari'
8
8
  require 'mail'
9
9
  require 'monetize'
10
- require 'paperclip'
11
10
  require 'paranoia'
12
11
  require 'mini_magick'
13
12
  require 'premailer/rails'
@@ -101,7 +100,6 @@ require 'spree/core/product_duplicator'
101
100
  require 'spree/core/controller_helpers/auth'
102
101
  require 'spree/core/controller_helpers/common'
103
102
  require 'spree/core/controller_helpers/order'
104
- require 'spree/core/controller_helpers/respond_with'
105
103
  require 'spree/core/controller_helpers/search'
106
104
  require 'spree/core/controller_helpers/store'
107
105
  require 'spree/core/controller_helpers/strong_parameters'
@@ -26,7 +26,7 @@ module Spree
26
26
 
27
27
  params.delete(:user_id) unless user.try(:has_spree_role?, 'admin') && params.key?(:user_id)
28
28
 
29
- order.update_attributes!(params)
29
+ order.update!(params)
30
30
 
31
31
  order.create_proposed_shipments unless shipments_attrs.present?
32
32
 
@@ -47,41 +47,41 @@ module Spree
47
47
  return [] unless shipments_hash
48
48
 
49
49
  shipments_hash.each do |s|
50
- begin
51
- shipment = order.shipments.build
52
- shipment.tracking = s[:tracking]
53
- shipment.stock_location = Spree::StockLocation.find_by(admin_name: s[:stock_location]) || Spree::StockLocation.find_by!(name: s[:stock_location])
54
- inventory_units = create_inventory_units_from_order_and_params(order, s[:inventory_units])
50
+ shipment = order.shipments.build
51
+ shipment.tracking = s[:tracking]
52
+ shipment.stock_location = Spree::StockLocation.find_by(admin_name: s[:stock_location]) ||
53
+ Spree::StockLocation.find_by!(name: s[:stock_location])
54
+ inventory_units = create_inventory_units_from_order_and_params(order, s[:inventory_units])
55
55
 
56
- inventory_units.each do |inventory_unit|
57
- inventory_unit.shipment = shipment
58
-
59
- if s[:shipped_at].present?
60
- inventory_unit.pending = false
61
- inventory_unit.state = 'shipped'
62
- end
63
-
64
- inventory_unit.save!
65
- end
56
+ inventory_units.each do |inventory_unit|
57
+ inventory_unit.shipment = shipment
66
58
 
67
59
  if s[:shipped_at].present?
68
- shipment.shipped_at = s[:shipped_at]
69
- shipment.state = 'shipped'
60
+ inventory_unit.pending = false
61
+ inventory_unit.state = 'shipped'
70
62
  end
71
63
 
72
- shipment.save!
64
+ inventory_unit.save!
65
+ end
66
+
67
+ if s[:shipped_at].present?
68
+ shipment.shipped_at = s[:shipped_at]
69
+ shipment.state = 'shipped'
70
+ end
71
+
72
+ shipment.save!
73
73
 
74
- shipping_method = Spree::ShippingMethod.find_by(name: s[:shipping_method]) || Spree::ShippingMethod.find_by!(admin_name: s[:shipping_method])
75
- rate = shipment.shipping_rates.create!(shipping_method: shipping_method, cost: s[:cost])
74
+ shipping_method = Spree::ShippingMethod.find_by(name: s[:shipping_method]) ||
75
+ Spree::ShippingMethod.find_by!(admin_name: s[:shipping_method])
76
+ rate = shipment.shipping_rates.create!(shipping_method: shipping_method, cost: s[:cost])
76
77
 
77
- shipment.selected_shipping_rate_id = rate.id
78
- shipment.update_amounts
78
+ shipment.selected_shipping_rate_id = rate.id
79
+ shipment.update_amounts
79
80
 
80
- adjustments = s.delete(:adjustments_attributes)
81
- create_adjustments_from_params(adjustments, order, shipment)
82
- rescue Exception => e
83
- raise "Order import shipments: #{e.message} #{s}"
84
- end
81
+ adjustments = s.delete(:adjustments_attributes)
82
+ create_adjustments_from_params(adjustments, order, shipment)
83
+ rescue Exception => e
84
+ raise "Order import shipments: #{e.message} #{s}"
85
85
  end
86
86
  end
87
87
 
@@ -101,57 +101,22 @@ module Spree
101
101
  def self.create_line_items_from_params(line_items, order)
102
102
  return {} unless line_items
103
103
 
104
- iterator = case line_items
105
- when Hash
106
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
107
- Passing a hash is now deprecated and will be removed in Spree 4.0.
108
- It is recommended that you pass it as an array instead.
109
-
110
- New Syntax:
111
-
112
- {
113
- "order": {
114
- "line_items": [
115
- { "variant_id": 123, "quantity": 1 },
116
- { "variant_id": 456, "quantity": 1 }
117
- ]
118
- }
119
- }
120
-
121
- Old Syntax:
122
-
123
- {
124
- "order": {
125
- "line_items": {
126
- "1": { "variant_id": 123, "quantity": 1 },
127
- "2": { "variant_id": 123, "quantity": 1 }
128
- }
129
- }
130
- }
131
- DEPRECATION
132
- :each_value
133
- when Array
134
- :each
135
- end
136
-
137
- line_items.send(iterator) do |line_item|
138
- begin
139
- adjustments = line_item.delete(:adjustments_attributes)
140
- extra_params = line_item.except(:variant_id, :quantity, :sku)
141
- line_item = ensure_variant_id_from_params(line_item)
142
- variant = Spree::Variant.find(line_item[:variant_id])
143
- line_item = Cart::AddItem.call(order: order, variant: variant, quantity: line_item[:quantity]).value
144
- # Raise any errors with saving to prevent import succeeding with line items
145
- # failing silently.
146
- if extra_params.present?
147
- line_item.update_attributes!(extra_params)
148
- else
149
- line_item.save!
150
- end
151
- create_adjustments_from_params(adjustments, order, line_item)
152
- rescue Exception => e
153
- raise "Order import line items: #{e.message} #{line_item}"
104
+ line_items.each do |line_item|
105
+ adjustments = line_item.delete(:adjustments_attributes)
106
+ extra_params = line_item.except(:variant_id, :quantity, :sku)
107
+ line_item = ensure_variant_id_from_params(line_item)
108
+ variant = Spree::Variant.find(line_item[:variant_id])
109
+ line_item = Cart::AddItem.call(order: order, variant: variant, quantity: line_item[:quantity]).value
110
+ # Raise any errors with saving to prevent import succeeding with line items
111
+ # failing silently.
112
+ if extra_params.present?
113
+ line_item.update!(extra_params)
114
+ else
115
+ line_item.save!
154
116
  end
117
+ create_adjustments_from_params(adjustments, order, line_item)
118
+ rescue Exception => e
119
+ raise "Order import line items: #{e.message} #{line_item}"
155
120
  end
156
121
  end
157
122
 
@@ -159,18 +124,16 @@ module Spree
159
124
  return [] unless adjustments
160
125
 
161
126
  adjustments.each do |a|
162
- begin
163
- adjustment = (adjustable || order).adjustments.build(
164
- order: order,
165
- amount: a[:amount].to_f,
166
- label: a[:label],
167
- source_type: source_type_from_adjustment(a)
168
- )
169
- adjustment.save!
170
- adjustment.close!
171
- rescue Exception => e
172
- raise "Order import adjustments: #{e.message} #{a}"
173
- end
127
+ adjustment = (adjustable || order).adjustments.build(
128
+ order: order,
129
+ amount: a[:amount].to_f,
130
+ label: a[:label],
131
+ source_type: source_type_from_adjustment(a)
132
+ )
133
+ adjustment.save!
134
+ adjustment.close!
135
+ rescue Exception => e
136
+ raise "Order import adjustments: #{e.message} #{a}"
174
137
  end
175
138
  end
176
139
 
@@ -178,19 +141,17 @@ module Spree
178
141
  return [] unless payments_hash
179
142
 
180
143
  payments_hash.each do |p|
181
- begin
182
- payment = order.payments.build order: order
183
- payment.amount = p[:amount].to_f
184
- # Order API should be using state as that's the normal payment field.
185
- # spree_wombat serializes payment state as status so imported orders should fall back to status field.
186
- payment.state = p[:state] || p[:status] || 'completed'
187
- payment.created_at = p[:created_at] if p[:created_at]
188
- payment.payment_method = Spree::PaymentMethod.find_by!(name: p[:payment_method])
189
- payment.source = create_source_payment_from_params(p[:source], payment) if p[:source]
190
- payment.save!
191
- rescue Exception => e
192
- raise "Order import payments: #{e.message} #{p}"
193
- end
144
+ payment = order.payments.build order: order
145
+ payment.amount = p[:amount].to_f
146
+ # Order API should be using state as that's the normal payment field.
147
+ # spree_wombat serializes payment state as status so imported orders should fall back to status field.
148
+ payment.state = p[:state] || p[:status] || 'completed'
149
+ payment.created_at = p[:created_at] if p[:created_at]
150
+ payment.payment_method = Spree::PaymentMethod.find_by!(name: p[:payment_method])
151
+ payment.source = create_source_payment_from_params(p[:source], payment) if p[:source]
152
+ payment.save!
153
+ rescue Exception => e
154
+ raise "Order import payments: #{e.message} #{p}"
194
155
  end
195
156
  end
196
157