solidus_core 2.10.0.beta1 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +4 -4
  3. data/app/helpers/spree/products_helper.rb +2 -1
  4. data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
  5. data/app/models/concerns/spree/user_methods.rb +2 -2
  6. data/app/models/spree/address.rb +11 -15
  7. data/app/models/spree/adjustment.rb +11 -0
  8. data/app/models/spree/calculator/price_sack.rb +1 -1
  9. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
  10. data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
  11. data/app/models/spree/calculator/tiered_percent.rb +6 -6
  12. data/app/models/spree/carton.rb +1 -1
  13. data/app/models/spree/credit_card.rb +2 -2
  14. data/app/models/spree/inventory_unit.rb +1 -19
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/order.rb +3 -2
  17. data/app/models/spree/order/checkout.rb +1 -1
  18. data/app/models/spree/order/payments.rb +2 -2
  19. data/app/models/spree/order_capturing.rb +2 -2
  20. data/app/models/spree/order_taxation.rb +2 -2
  21. data/app/models/spree/payment.rb +4 -41
  22. data/app/models/spree/payment/processing.rb +2 -2
  23. data/app/models/spree/payment_method.rb +2 -2
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product/scopes.rb +8 -7
  26. data/app/models/spree/promotion.rb +27 -12
  27. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
  28. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  29. data/app/models/spree/promotion/rules/option_value.rb +2 -2
  30. data/app/models/spree/promotion/rules/product.rb +3 -3
  31. data/app/models/spree/promotion_action.rb +1 -1
  32. data/app/models/spree/promotion_chooser.rb +2 -2
  33. data/app/models/spree/promotion_code.rb +9 -8
  34. data/app/models/spree/promotion_code/batch_builder.rb +3 -3
  35. data/app/models/spree/promotion_rule.rb +1 -1
  36. data/app/models/spree/refund.rb +2 -2
  37. data/app/models/spree/reimbursement.rb +3 -11
  38. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
  39. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
  40. data/app/models/spree/return_authorization.rb +1 -7
  41. data/app/models/spree/return_item.rb +3 -42
  42. data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
  43. data/app/models/spree/shipment.rb +4 -38
  44. data/app/models/spree/shipping_calculator.rb +0 -4
  45. data/app/models/spree/shipping_method.rb +1 -1
  46. data/app/models/spree/state.rb +1 -1
  47. data/app/models/spree/stock/differentiator.rb +1 -1
  48. data/app/models/spree/stock/package.rb +1 -1
  49. data/app/models/spree/stock_item.rb +1 -1
  50. data/app/models/spree/stock_quantities.rb +13 -12
  51. data/app/models/spree/tax_calculator/default.rb +0 -4
  52. data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
  53. data/app/models/spree/tax_rate.rb +4 -0
  54. data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
  55. data/app/models/spree/user_last_url_storer.rb +46 -0
  56. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
  57. data/app/models/spree/variant.rb +9 -9
  58. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  59. data/app/models/spree/zone.rb +1 -1
  60. data/config/initializers/money.rb +2 -0
  61. data/config/locales/en.yml +12 -0
  62. data/lib/generators/spree/install/install_generator.rb +3 -0
  63. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
  64. data/lib/spree/app_configuration.rb +18 -3
  65. data/lib/spree/core.rb +12 -0
  66. data/lib/spree/core/controller_helpers/auth.rb +1 -13
  67. data/lib/spree/core/engine.rb +2 -2
  68. data/lib/spree/core/environment_extension.rb +9 -0
  69. data/lib/spree/core/importer/order.rb +26 -26
  70. data/lib/spree/core/product_filters.rb +15 -15
  71. data/lib/spree/core/role_configuration.rb +2 -2
  72. data/lib/spree/core/search/variant.rb +1 -1
  73. data/lib/spree/core/state_machines.rb +78 -0
  74. data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
  75. data/lib/spree/core/state_machines/payment.rb +61 -0
  76. data/lib/spree/core/state_machines/reimbursement.rb +33 -0
  77. data/lib/spree/core/state_machines/return_authorization.rb +32 -0
  78. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  79. data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
  80. data/lib/spree/core/state_machines/shipment.rb +58 -0
  81. data/lib/spree/core/stock_configuration.rb +1 -0
  82. data/lib/spree/core/validators/email.rb +1 -8
  83. data/lib/spree/core/version.rb +1 -1
  84. data/lib/spree/money.rb +2 -2
  85. data/lib/spree/permission_sets/user_management.rb +3 -0
  86. data/lib/spree/permitted_attributes.rb +3 -3
  87. data/lib/spree/preferences/static_model_preferences.rb +2 -2
  88. data/lib/spree/testing_support/dummy_app.rb +4 -1
  89. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
  90. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
  91. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  92. data/solidus_core.gemspec +2 -2
  93. data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
  94. data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
  95. data/spec/lib/spree/core/validators/email_spec.rb +18 -18
  96. data/spec/models/spree/address_spec.rb +23 -0
  97. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
  98. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
  99. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
  100. data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
  101. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
  102. data/spec/models/spree/carton_spec.rb +8 -0
  103. data/spec/models/spree/classification_spec.rb +21 -9
  104. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  105. data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
  106. data/spec/models/spree/order_merger_spec.rb +3 -3
  107. data/spec/models/spree/order_spec.rb +8 -15
  108. data/spec/models/spree/order_updater_spec.rb +4 -3
  109. data/spec/models/spree/payment_create_spec.rb +4 -14
  110. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  111. data/spec/models/spree/preference_spec.rb +4 -4
  112. data/spec/models/spree/preferences/preferable_spec.rb +3 -3
  113. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
  114. data/spec/models/spree/promotion_rule_spec.rb +6 -6
  115. data/spec/models/spree/promotion_spec.rb +73 -52
  116. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
  117. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
  118. data/spec/models/spree/returns_calculator_spec.rb +2 -2
  119. data/spec/models/spree/shipping_calculator_spec.rb +1 -13
  120. data/spec/models/spree/shipping_method_spec.rb +32 -0
  121. data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
  122. data/spec/models/spree/stock/differentiator_spec.rb +2 -2
  123. data/spec/models/spree/stock/estimator_spec.rb +3 -3
  124. data/spec/models/spree/stock/package_spec.rb +28 -28
  125. data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
  126. data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
  127. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
  128. data/spec/models/spree/stock_quantities_spec.rb +1 -1
  129. data/spec/models/spree/store_credit_spec.rb +1 -1
  130. data/spec/models/spree/tax_rate_spec.rb +1 -0
  131. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
  132. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
  133. data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
  134. metadata +17 -12
  135. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
  136. data/spec/models/spree/order/updating_spec.rb +0 -18
@@ -53,6 +53,17 @@ module Spree
53
53
  end
54
54
  end
55
55
 
56
+ if Gem::Version.new(Rails.version) < Gem::Version.new('5.2')
57
+ warn <<~HEREDOC
58
+ Rails 5.1 (EOL) is deprecated and will not be supported anymore from the next Solidus version.
59
+ Please, upgrade to a more recent Rails version.
60
+
61
+ Read more on upgrading from Rails 5.1 to Rails 5.2 here:
62
+ https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-5-1-to-rails-5-2
63
+
64
+ HEREDOC
65
+ end
66
+
56
67
  require 'spree/core/version'
57
68
 
58
69
  require 'spree/core/active_merchant_dependencies'
@@ -85,6 +96,7 @@ require 'spree/core/controller_helpers/search'
85
96
  require 'spree/core/controller_helpers/store'
86
97
  require 'spree/core/controller_helpers/strong_parameters'
87
98
  require 'spree/core/role_configuration'
99
+ require 'spree/core/state_machines'
88
100
  require 'spree/core/stock_configuration'
89
101
  require 'spree/core/validators/email'
90
102
  require 'spree/permission_sets'
@@ -50,19 +50,7 @@ module Spree
50
50
  end
51
51
 
52
52
  def store_location
53
- # disallow return to login, logout, signup pages
54
- authentication_routes = [:spree_signup_path, :spree_login_path, :spree_logout_path]
55
- disallowed_urls = []
56
- authentication_routes.each do |route|
57
- if respond_to?(route)
58
- disallowed_urls << send(route)
59
- end
60
- end
61
-
62
- disallowed_urls.map!{ |url| url[/\/\w+$/] }
63
- unless disallowed_urls.include?(request.fullpath)
64
- session['spree_user_return_to'] = request.fullpath.gsub('//', '/')
65
- end
53
+ Spree::UserLastUrlStorer.new(self).store_location
66
54
  end
67
55
 
68
56
  # proxy method to *possible* spree_current_user method
@@ -11,8 +11,8 @@ module Spree
11
11
  isolate_namespace Spree
12
12
  engine_name 'spree'
13
13
 
14
- config.generators do |g|
15
- g.test_framework :rspec
14
+ config.generators do |generator|
15
+ generator.test_framework :rspec
16
16
  end
17
17
 
18
18
  initializer "spree.environment", before: :load_config_initializers do |app|
@@ -22,6 +22,15 @@ module Spree
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ def add_class(name)
27
+ Spree::Deprecation.warn(
28
+ 'This method is deprecated. ' \
29
+ "Please use `#{self.class}.add_class_set(#{name.inspect})` instead.",
30
+ caller,
31
+ )
32
+ singleton_class.send(:add_class_set, name)
33
+ end
25
34
  end
26
35
  end
27
36
  end
@@ -53,17 +53,17 @@ module Spree
53
53
  def self.create_shipments_from_params(shipments_hash, order)
54
54
  return [] unless shipments_hash
55
55
 
56
- shipments_hash.each do |s|
56
+ shipments_hash.each do |target|
57
57
  shipment = Shipment.new
58
- shipment.tracking = s[:tracking]
59
- shipment.stock_location = Spree::StockLocation.find_by(admin_name: s[:stock_location]) || Spree::StockLocation.find_by!(name: s[:stock_location])
58
+ shipment.tracking = target[:tracking]
59
+ shipment.stock_location = Spree::StockLocation.find_by(admin_name: target[:stock_location]) || Spree::StockLocation.find_by!(name: target[:stock_location])
60
60
 
61
- inventory_units = s[:inventory_units] || []
62
- inventory_units.each do |iu|
63
- ensure_variant_id_from_params(iu)
61
+ inventory_units = target[:inventory_units] || []
62
+ inventory_units.each do |inventory_unit|
63
+ ensure_variant_id_from_params(inventory_unit)
64
64
 
65
- unless line_item = order.line_items.find_by(variant_id: iu[:variant_id])
66
- line_item = order.contents.add(Spree::Variant.find(iu[:variant_id]), 1)
65
+ unless line_item = order.line_items.find_by(variant_id: inventory_unit[:variant_id])
66
+ line_item = order.contents.add(Spree::Variant.find(inventory_unit[:variant_id]), 1)
67
67
  end
68
68
 
69
69
  # Spree expects a Inventory Unit to always reference a line
@@ -71,14 +71,14 @@ module Spree
71
71
  # trying to view these units. Note the Importer might not be
72
72
  # able to find the line item if line_item.variant_id |= iu.variant_id
73
73
  shipment.inventory_units.new(
74
- variant_id: iu[:variant_id],
74
+ variant_id: inventory_unit[:variant_id],
75
75
  line_item: line_item
76
76
  )
77
77
  end
78
78
 
79
79
  # Mark shipped if it should be.
80
- if s[:shipped_at].present?
81
- shipment.shipped_at = s[:shipped_at]
80
+ if target[:shipped_at].present?
81
+ shipment.shipped_at = target[:shipped_at]
82
82
  shipment.state = 'shipped'
83
83
  shipment.inventory_units.each do |unit|
84
84
  unit.state = 'shipped'
@@ -88,9 +88,9 @@ module Spree
88
88
  order.shipments << shipment
89
89
  shipment.save!
90
90
 
91
- shipping_method = Spree::ShippingMethod.find_by(name: s[:shipping_method]) || Spree::ShippingMethod.find_by!(admin_name: s[:shipping_method])
91
+ shipping_method = Spree::ShippingMethod.find_by(name: target[:shipping_method]) || Spree::ShippingMethod.find_by!(admin_name: target[:shipping_method])
92
92
  rate = shipment.shipping_rates.create!(shipping_method: shipping_method,
93
- cost: s[:cost])
93
+ cost: target[:cost])
94
94
  shipment.selected_shipping_rate_id = rate.id
95
95
  shipment.update_amounts
96
96
  end
@@ -98,9 +98,9 @@ module Spree
98
98
 
99
99
  def self.create_line_items_from_params(line_items_hash, order)
100
100
  return {} unless line_items_hash
101
- line_items_hash.each_key do |k|
102
- extra_params = line_items_hash[k].except(:variant_id, :quantity, :sku)
103
- line_item = ensure_variant_id_from_params(line_items_hash[k])
101
+ line_items_hash.each_key do |key|
102
+ extra_params = line_items_hash[key].except(:variant_id, :quantity, :sku)
103
+ line_item = ensure_variant_id_from_params(line_items_hash[key])
104
104
  line_item = order.contents.add(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
105
105
  # Raise any errors with saving to prevent import succeeding with line items failing silently.
106
106
  if extra_params.present?
@@ -113,11 +113,11 @@ module Spree
113
113
 
114
114
  def self.create_adjustments_from_params(adjustments, order)
115
115
  return [] unless adjustments
116
- adjustments.each do |a|
116
+ adjustments.each do |target|
117
117
  adjustment = order.adjustments.build(
118
118
  order: order,
119
- amount: a[:amount].to_d,
120
- label: a[:label]
119
+ amount: target[:amount].to_d,
120
+ label: target[:label]
121
121
  )
122
122
  adjustment.save!
123
123
  adjustment.finalize!
@@ -126,14 +126,14 @@ module Spree
126
126
 
127
127
  def self.create_payments_from_params(payments_hash, order)
128
128
  return [] unless payments_hash
129
- payments_hash.each do |p|
129
+ payments_hash.each do |target|
130
130
  payment = order.payments.build order: order
131
- payment.amount = p[:amount].to_f
131
+ payment.amount = target[:amount].to_f
132
132
  # Order API should be using state as that's the normal payment field.
133
133
  # spree_wombat serializes payment state as status so imported orders should fall back to status field.
134
- payment.state = p[:state] || p[:status] || 'completed'
135
- payment.payment_method = Spree::PaymentMethod.find_by!(name: p[:payment_method])
136
- payment.source = create_source_payment_from_params(p[:source], payment) if p[:source]
134
+ payment.state = target[:state] || target[:status] || 'completed'
135
+ payment.payment_method = Spree::PaymentMethod.find_by!(name: target[:payment_method])
136
+ payment.source = create_source_payment_from_params(target[:source], payment) if target[:source]
137
137
  payment.save!
138
138
  end
139
139
  end
@@ -170,8 +170,8 @@ module Spree
170
170
  search[:iso_name] = iso_name.upcase
171
171
  elsif iso = address[:country]['iso']
172
172
  search[:iso] = iso.upcase
173
- elsif iso3 = address[:country]['iso3']
174
- search[:iso3] = iso3.upcase
173
+ elsif iso_three = address[:country]['iso3']
174
+ search[:iso3] = iso_three.upcase
175
175
  end
176
176
 
177
177
  address.delete(:country)
@@ -55,7 +55,7 @@ module Spree
55
55
  # below scope would be something like ["$10 - $15", "$15 - $18", "$18 - $20"]
56
56
  #
57
57
  Spree::Product.add_search_scope :price_range_any do |*opts|
58
- conds = opts.map { |o| Spree::Core::ProductFilters.price_filter[:conds][o] }.reject(&:nil?)
58
+ conds = opts.map { |element| Spree::Core::ProductFilters.price_filter[:conds][element] }.reject(&:nil?)
59
59
  scope = conds.shift
60
60
  conds.each do |new_scope|
61
61
  scope = scope.or(new_scope)
@@ -68,17 +68,17 @@ module Spree
68
68
  end
69
69
 
70
70
  def self.price_filter
71
- v = Spree::Price.arel_table
72
- conds = [[I18n.t('spree.under_price', price: format_price(10)), v[:amount].lteq(10)],
73
- ["#{format_price(10)} - #{format_price(15)}", v[:amount].in(10..15)],
74
- ["#{format_price(15)} - #{format_price(18)}", v[:amount].in(15..18)],
75
- ["#{format_price(18)} - #{format_price(20)}", v[:amount].in(18..20)],
76
- [I18n.t('spree.or_over_price', price: format_price(20)), v[:amount].gteq(20)]]
71
+ value = Spree::Price.arel_table
72
+ conds = [[I18n.t('spree.under_price', price: format_price(10)), value[:amount].lteq(10)],
73
+ ["#{format_price(10)} - #{format_price(15)}", value[:amount].in(10..15)],
74
+ ["#{format_price(15)} - #{format_price(18)}", value[:amount].in(15..18)],
75
+ ["#{format_price(18)} - #{format_price(20)}", value[:amount].in(18..20)],
76
+ [I18n.t('spree.or_over_price', price: format_price(20)), value[:amount].gteq(20)]]
77
77
  {
78
78
  name: I18n.t('spree.price_range'),
79
79
  scope: :price_range_any,
80
80
  conds: Hash[*conds.flatten],
81
- labels: conds.map { |k, _v| [k, k] }
81
+ labels: conds.map { |key, _value| [key, key] }
82
82
  }
83
83
  end
84
84
 
@@ -95,7 +95,7 @@ module Spree
95
95
  # being blank: note that this relies on with_property doing a left outer join
96
96
  # rather than an inner join.
97
97
  Spree::Product.add_search_scope :brand_any do |*opts|
98
- conds = opts.map { |o| ProductFilters.brand_filter[:conds][o] }.reject(&:nil?)
98
+ conds = opts.map { |value| ProductFilters.brand_filter[:conds][value] }.reject(&:nil?)
99
99
  scope = conds.shift
100
100
  conds.each do |new_scope|
101
101
  scope = scope.or(new_scope)
@@ -107,12 +107,12 @@ module Spree
107
107
  brand_property = Spree::Property.find_by(name: 'brand')
108
108
  brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
109
109
  pp = Spree::ProductProperty.arel_table
110
- conds = Hash[*brands.map { |b| [b, pp[:value].eq(b)] }.flatten]
110
+ conds = Hash[*brands.map { |brand| [brand, pp[:value].eq(brand)] }.flatten]
111
111
  {
112
112
  name: 'Brands',
113
113
  scope: :brand_any,
114
114
  conds: conds,
115
- labels: brands.sort.map { |k| [k, k] }
115
+ labels: brands.sort.map { |key| [key, key] }
116
116
  }
117
117
  end
118
118
 
@@ -149,7 +149,7 @@ module Spree
149
149
  {
150
150
  name: 'Applicable Brands',
151
151
  scope: :selective_brand_any,
152
- labels: brands.sort.map { |k| [k, k] }
152
+ labels: brands.sort.map { |key| [key, key] }
153
153
  }
154
154
  end
155
155
 
@@ -171,7 +171,7 @@ module Spree
171
171
  {
172
172
  name: 'Taxons under ' + taxon.name,
173
173
  scope: :taxons_id_in_tree_any,
174
- labels: taxon.children.sort_by(&:position).map { |t| [t.name, t.id] },
174
+ labels: taxon.children.sort_by(&:position).map { |element| [element.name, element.id] },
175
175
  conds: nil
176
176
  }
177
177
  end
@@ -184,11 +184,11 @@ module Spree
184
184
  # idea: expand the format to allow nesting of labels?
185
185
  def self.all_taxons
186
186
  Spree::Deprecation.warn "all_taxons is deprecated in solidus_core. Please add it to your own application to continue using it."
187
- taxons = Spree::Taxonomy.all.map { |t| [t.root] + t.root.descendants }.flatten
187
+ taxons = Spree::Taxonomy.all.map { |element| [element.root] + element.root.descendants }.flatten
188
188
  {
189
189
  name: 'All taxons',
190
190
  scope: :taxons_id_equals_any,
191
- labels: taxons.sort_by(&:name).map { |t| [t.name, t.id] },
191
+ labels: taxons.sort_by(&:name).map { |element| [element.name, element.id] },
192
192
  conds: nil # not needed
193
193
  }
194
194
  end
@@ -69,8 +69,8 @@ module Spree
69
69
  # Not public due to the fact this class is a Singleton
70
70
  # @!visibility private
71
71
  def initialize
72
- @roles = Hash.new do |h, name|
73
- h[name] = Role.new(name, Set.new)
72
+ @roles = Hash.new do |hash, name|
73
+ hash[name] = Role.new(name, Set.new)
74
74
  end
75
75
  end
76
76
 
@@ -57,7 +57,7 @@ module Spree
57
57
  end
58
58
 
59
59
  def search_term_params(word)
60
- terms = Hash[search_terms(word).map { |t| [t, word] }]
60
+ terms = Hash[search_terms(word).map { |term| [term, word] }]
61
61
  terms.merge(m: 'or')
62
62
  end
63
63
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Core
5
+ class StateMachines
6
+ attr_writer :reimbursement,
7
+ :return_authorization,
8
+ :return_item_acceptance,
9
+ :return_item_reception,
10
+ :payment,
11
+ :inventory_unit,
12
+ :shipment
13
+
14
+ def return_authorization
15
+ @return_authorization ||= begin
16
+ require 'spree/core/state_machines/return_authorization'
17
+ 'Spree::Core::StateMachines::ReturnAuthorization'
18
+ end
19
+
20
+ @return_authorization.constantize
21
+ end
22
+
23
+ def return_item_reception
24
+ @return_item_reception_status ||= begin
25
+ require 'spree/core/state_machines/return_item/reception_status'
26
+ 'Spree::Core::StateMachines::ReturnItem::ReceptionStatus'
27
+ end
28
+
29
+ @return_item_reception_status.constantize
30
+ end
31
+
32
+ def return_item_acceptance
33
+ @return_item_acceptance_status ||= begin
34
+ require 'spree/core/state_machines/return_item/acceptance_status'
35
+ 'Spree::Core::StateMachines::ReturnItem::AcceptanceStatus'
36
+ end
37
+
38
+ @return_item_acceptance_status.constantize
39
+ end
40
+
41
+ def payment
42
+ @payment ||= begin
43
+ require 'spree/core/state_machines/payment'
44
+ 'Spree::Core::StateMachines::Payment'
45
+ end
46
+
47
+ @payment.constantize
48
+ end
49
+
50
+ def inventory_unit
51
+ @inventory_unit ||= begin
52
+ require 'spree/core/state_machines/inventory_unit'
53
+ 'Spree::Core::StateMachines::InventoryUnit'
54
+ end
55
+
56
+ @inventory_unit.constantize
57
+ end
58
+
59
+ def shipment
60
+ @shipment ||= begin
61
+ require 'spree/core/state_machines/shipment'
62
+ 'Spree::Core::StateMachines::Shipment'
63
+ end
64
+
65
+ @shipment.constantize
66
+ end
67
+
68
+ def reimbursement
69
+ @reimbursement ||= begin
70
+ require 'spree/core/state_machines/reimbursement'
71
+ 'Spree::Core::StateMachines::Reimbursement'
72
+ end
73
+
74
+ @reimbursement.constantize
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Core
5
+ class StateMachines
6
+ # Inventory Units' state machine
7
+ #
8
+ # for each event the following instance methods are dynamically implemented:
9
+ # #<event_name>
10
+ # #<event_name>!
11
+ # #can_<event_name>?
12
+ #
13
+ # for each state the following instance methods are implemented:
14
+ # #<state_name>?
15
+ #
16
+ module InventoryUnit
17
+ extend ActiveSupport::Concern
18
+
19
+ included do
20
+ state_machine initial: :on_hand do
21
+ event :fill_backorder do
22
+ transition to: :on_hand, from: :backordered
23
+ end
24
+ after_transition on: :fill_backorder, do: :fulfill_order
25
+
26
+ event :ship do
27
+ transition to: :shipped, if: :allow_ship?
28
+ end
29
+
30
+ event :return do
31
+ transition to: :returned, from: :shipped
32
+ end
33
+
34
+ event :cancel do
35
+ transition to: :canceled, from: ::Spree::InventoryUnit::CANCELABLE_STATES.map(&:to_sym)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Core
5
+ class StateMachines
6
+ # Payments' state machine
7
+ #
8
+ # for each event the following instance methods are dynamically implemented:
9
+ # #<event_name>
10
+ # #<event_name>!
11
+ # #can_<event_name>?
12
+ #
13
+ # for each state the following instance methods are implemented:
14
+ # #<state_name>?
15
+ #
16
+ module Payment
17
+ extend ActiveSupport::Concern
18
+
19
+ included do
20
+ state_machine initial: :checkout do
21
+ # With card payments, happens before purchase or authorization happens
22
+ #
23
+ # Setting it after creating a profile and authorizing a full amount will
24
+ # prevent the payment from being authorized again once Order transitions
25
+ # to complete
26
+ event :started_processing do
27
+ transition from: [:checkout, :pending, :completed, :processing], to: :processing
28
+ end
29
+ # When processing during checkout fails
30
+ event :failure do
31
+ transition from: [:pending, :processing], to: :failed
32
+ end
33
+ # With card payments this represents authorizing the payment
34
+ event :pend do
35
+ transition from: [:checkout, :processing], to: :pending
36
+ end
37
+ # With card payments this represents completing a purchase or capture transaction
38
+ event :complete do
39
+ transition from: [:processing, :pending, :checkout], to: :completed
40
+ end
41
+ event :void do
42
+ transition from: [:pending, :processing, :completed, :checkout], to: :void
43
+ end
44
+ # when the card brand isnt supported
45
+ event :invalidate do
46
+ transition from: [:checkout], to: :invalid
47
+ end
48
+
49
+ after_transition do |payment, transition|
50
+ payment.state_changes.create!(
51
+ previous_state: transition.from,
52
+ next_state: transition.to,
53
+ name: 'payment'
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end