solidus_core 3.4.2 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/spree/base_controller.rb +0 -2
  4. data/app/helpers/spree/products_helper.rb +1 -1
  5. data/app/models/concerns/spree/active_storage_adapter.rb +0 -17
  6. data/app/models/concerns/spree/default_price.rb +0 -15
  7. data/app/models/concerns/spree/ransackable_attributes.rb +0 -21
  8. data/app/models/spree/adjustment.rb +0 -13
  9. data/app/models/spree/carton.rb +1 -1
  10. data/app/models/spree/fulfilment_changer.rb +2 -14
  11. data/app/models/spree/option_value.rb +2 -11
  12. data/app/models/spree/order.rb +23 -39
  13. data/app/models/spree/order_contents.rb +2 -2
  14. data/app/models/spree/order_merger.rb +2 -4
  15. data/app/models/spree/order_updater.rb +3 -30
  16. data/app/models/spree/payment.rb +5 -37
  17. data/app/models/spree/product/scopes.rb +0 -5
  18. data/app/models/spree/product.rb +3 -10
  19. data/app/models/spree/promotion/rules/item_total.rb +0 -11
  20. data/app/models/spree/promotion.rb +7 -30
  21. data/app/models/spree/promotion_rule.rb +0 -5
  22. data/app/models/spree/refund.rb +1 -1
  23. data/app/models/spree/taxon/paperclip_attachment.rb +1 -1
  24. data/app/models/spree/taxon.rb +2 -2
  25. data/app/models/spree/taxonomy.rb +1 -1
  26. data/app/models/spree/variant/price_selector.rb +1 -14
  27. data/app/models/spree/variant.rb +1 -17
  28. data/bin/rails +13 -0
  29. data/config/locales/en.yml +0 -1
  30. data/db/migrate/20210815004823_add_unique_index_to_option_values_variants.rb +16 -0
  31. data/db/migrate/20230321161854_change_column_null_option_values_option_type_id.rb +5 -0
  32. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +5 -0
  33. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +6 -0
  34. data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +13 -0
  35. data/db/migrate/20230425103509_remove_taxon_position.rb +5 -0
  36. data/db/migrate/20230427095534_drop_deprecated_address_id_from_shipments.rb +11 -0
  37. data/lib/generators/solidus/install/app_templates/frontend/none.rb +1 -2
  38. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -3
  39. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +2 -14
  40. data/lib/generators/solidus/install/app_templates/payment_method/stripe.rb +5 -0
  41. data/lib/generators/solidus/install/install_generator.rb +59 -153
  42. data/lib/spree/app_configuration.rb +10 -82
  43. data/lib/spree/bus.rb +2 -11
  44. data/lib/spree/core/controller_helpers/auth.rb +0 -16
  45. data/lib/spree/core/engine.rb +11 -31
  46. data/lib/spree/core/importer/order.rb +1 -1
  47. data/lib/spree/core/validators/email.rb +0 -4
  48. data/lib/spree/core/version.rb +2 -2
  49. data/lib/spree/core.rb +0 -2
  50. data/lib/spree/migration_helpers.rb +3 -3
  51. data/lib/spree/permission_sets/configuration_display.rb +19 -1
  52. data/lib/spree/permission_sets/configuration_management.rb +18 -1
  53. data/lib/spree/permission_sets/dashboard_display.rb +5 -0
  54. data/lib/spree/permission_sets/default_customer.rb +29 -0
  55. data/lib/spree/permission_sets/order_display.rb +19 -0
  56. data/lib/spree/permission_sets/order_management.rb +18 -0
  57. data/lib/spree/permission_sets/product_display.rb +14 -0
  58. data/lib/spree/permission_sets/product_management.rb +16 -0
  59. data/lib/spree/permission_sets/promotion_display.rb +10 -0
  60. data/lib/spree/permission_sets/promotion_management.rb +10 -0
  61. data/lib/spree/permission_sets/restricted_stock_display.rb +5 -0
  62. data/lib/spree/permission_sets/restricted_stock_management.rb +5 -0
  63. data/lib/spree/permission_sets/stock_display.rb +4 -0
  64. data/lib/spree/permission_sets/stock_management.rb +4 -0
  65. data/lib/spree/permission_sets/super_user.rb +5 -0
  66. data/lib/spree/permission_sets/user_display.rb +4 -0
  67. data/lib/spree/permission_sets/user_management.rb +9 -0
  68. data/lib/spree/preferences/preferable_class_methods.rb +1 -25
  69. data/lib/spree/testing_support/common_rake.rb +5 -1
  70. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +4 -8
  71. data/lib/spree/testing_support/dummy_app.rb +1 -7
  72. data/lib/spree/testing_support/factories/address_factory.rb +0 -7
  73. data/lib/spree/testing_support/factories/adjustment_factory.rb +0 -11
  74. data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +0 -5
  75. data/lib/spree/testing_support/factories/calculator_factory.rb +0 -5
  76. data/lib/spree/testing_support/factories/carton_factory.rb +0 -8
  77. data/lib/spree/testing_support/factories/country_factory.rb +0 -5
  78. data/lib/spree/testing_support/factories/credit_card_factory.rb +0 -5
  79. data/lib/spree/testing_support/factories/customer_return_factory.rb +0 -9
  80. data/lib/spree/testing_support/factories/image_factory.rb +0 -5
  81. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +0 -10
  82. data/lib/spree/testing_support/factories/line_item_factory.rb +0 -8
  83. data/lib/spree/testing_support/factories/option_type_factory.rb +0 -8
  84. data/lib/spree/testing_support/factories/option_value_factory.rb +0 -5
  85. data/lib/spree/testing_support/factories/order_factory.rb +0 -12
  86. data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
  87. data/lib/spree/testing_support/factories/payment_factory.rb +0 -10
  88. data/lib/spree/testing_support/factories/payment_method_factory.rb +0 -5
  89. data/lib/spree/testing_support/factories/price_factory.rb +0 -7
  90. data/lib/spree/testing_support/factories/product_factory.rb +0 -11
  91. data/lib/spree/testing_support/factories/product_option_type_factory.rb +0 -8
  92. data/lib/spree/testing_support/factories/product_property_factory.rb +0 -8
  93. data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -5
  94. data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
  95. data/lib/spree/testing_support/factories/promotion_factory.rb +0 -8
  96. data/lib/spree/testing_support/factories/property_factory.rb +0 -5
  97. data/lib/spree/testing_support/factories/refund_factory.rb +0 -8
  98. data/lib/spree/testing_support/factories/refund_reason_factory.rb +0 -5
  99. data/lib/spree/testing_support/factories/reimbursement_factory.rb +0 -7
  100. data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +0 -5
  101. data/lib/spree/testing_support/factories/return_authorization_factory.rb +0 -9
  102. data/lib/spree/testing_support/factories/return_item_factory.rb +0 -9
  103. data/lib/spree/testing_support/factories/return_reason_factory.rb +0 -5
  104. data/lib/spree/testing_support/factories/role_factory.rb +0 -5
  105. data/lib/spree/testing_support/factories/shipment_factory.rb +0 -10
  106. data/lib/spree/testing_support/factories/shipping_category_factory.rb +0 -5
  107. data/lib/spree/testing_support/factories/shipping_method_factory.rb +0 -9
  108. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +0 -8
  109. data/lib/spree/testing_support/factories/state_factory.rb +0 -8
  110. data/lib/spree/testing_support/factories/stock_item_factory.rb +0 -8
  111. data/lib/spree/testing_support/factories/stock_location_factory.rb +0 -9
  112. data/lib/spree/testing_support/factories/stock_movement_factory.rb +0 -7
  113. data/lib/spree/testing_support/factories/stock_package_factory.rb +0 -8
  114. data/lib/spree/testing_support/factories/store_credit_category_factory.rb +0 -5
  115. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +0 -8
  116. data/lib/spree/testing_support/factories/store_credit_factory.rb +0 -9
  117. data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +0 -5
  118. data/lib/spree/testing_support/factories/store_credit_type_factory.rb +0 -5
  119. data/lib/spree/testing_support/factories/store_factory.rb +0 -5
  120. data/lib/spree/testing_support/factories/tax_category_factory.rb +0 -8
  121. data/lib/spree/testing_support/factories/tax_rate_factory.rb +0 -9
  122. data/lib/spree/testing_support/factories/taxon_factory.rb +0 -7
  123. data/lib/spree/testing_support/factories/taxonomy_factory.rb +0 -5
  124. data/lib/spree/testing_support/factories/user_factory.rb +0 -9
  125. data/lib/spree/testing_support/factories/variant_factory.rb +0 -10
  126. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +0 -8
  127. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +0 -9
  128. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +0 -8
  129. data/lib/spree/testing_support/factories/zone_factory.rb +0 -8
  130. data/lib/spree/testing_support/factory_bot.rb +4 -28
  131. data/lib/spree/testing_support/sequences.rb +0 -5
  132. data/solidus_core.gemspec +3 -3
  133. metadata +48 -58
  134. data/app/subscribers/spree/mailer_subscriber.rb +0 -29
  135. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +0 -54
  136. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +0 -16
  137. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +0 -13
  138. data/lib/spree/core/controller_helpers/current_host.rb +0 -19
  139. data/lib/spree/event/adapters/active_support_notifications.rb +0 -67
  140. data/lib/spree/event/configuration.rb +0 -25
  141. data/lib/spree/event/subscriber.rb +0 -86
  142. data/lib/spree/event/subscriber_registry.rb +0 -92
  143. data/lib/spree/event.rb +0 -119
  144. data/lib/spree/promotion/match_policies.rb +0 -2
  145. data/lib/spree/rails_compatibility.rb +0 -106
  146. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +0 -10
  147. data/lib/spree/testing_support/dummy_app/assets/stylesheets/spree/frontend/all.css +0 -9
  148. data/lib/spree/testing_support/dummy_app/views/layouts/application.html.erb +0 -1
  149. data/lib/spree/testing_support/factories.rb +0 -11
  150. data/lib/spree/testing_support.rb +0 -36
  151. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +0 -18
  152. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27a6dc7426532656dc872561abdbd2d10b0f6695e5020024302ce9c8a720ef8c
4
- data.tar.gz: c9352bdf10b7a7131fe5a1e9535a9a6dc585d4bd60084b8ca116cac2925faec7
3
+ metadata.gz: c3e2c6952c5346f716b691621d06c35fa50cdd42a1071b449495be31f2358c15
4
+ data.tar.gz: cf282e7b402f07c2a33f300fbe61aef661fbb31f5b1a6889887149d2bfcadca1
5
5
  SHA512:
6
- metadata.gz: 0ad38fa6806399e63992c8e0455f9baa443a85fef435c71fe07e2b2da1f7269254c0e6403d5a009a61cfa550c9c8702ec7ef155d8dc7e9f88cdb0c1f5ac5cd20
7
- data.tar.gz: 0ebe32086e2e138edd27721b3fa5536db1de7255bb6d30d8cdc223eebb7e795b369bd26fae4c96b8de7269bf03f2afdb09ddfef8a797470d41b42e3016956a89
6
+ metadata.gz: 8240824eb568d985249690d9a49382a6b25d2d4f7f5c6d8d17d30bfa2fd0cb9af579e5ee01b16828cbacdadad3b9b4524d804ce42aaab08e94b211ce08f8d439
7
+ data.tar.gz: 20b8afa05c9068af3635aadb658302f0ecee745a50bbb0b6230db6fbec758de6cb594a22ddc147e8c655e9cd1ac8babb827701979bc912836b091273f7d2e1af
data/README.md CHANGED
@@ -5,7 +5,7 @@ Solidus system depends.
5
5
 
6
6
  Core models
7
7
  -----------
8
- Solidus implements over 200 [models](https://github.com/solidusio/solidus/tree/master/core/app/models/spree),
8
+ Solidus implements over 200 [models](https://github.com/solidusio/solidus/tree/main/core/app/models/spree),
9
9
  and thus a deep inspection of each in this README would be overkill. Instead,
10
10
  let's take a quick look at the fundamental models upon which all else depend.
11
11
  Currently, these models remain in the Spree namespace as part of the legacy of
@@ -11,6 +11,4 @@ class Spree::BaseController < ApplicationController
11
11
  include Spree::Core::ControllerHelpers::Search
12
12
  include Spree::Core::ControllerHelpers::Store
13
13
  include Spree::Core::ControllerHelpers::StrongParameters
14
-
15
- respond_to :html
16
14
  end
@@ -68,7 +68,7 @@ module Spree
68
68
  # @return [String] a cache invalidation key for products
69
69
  def cache_key_for_products
70
70
  count = @products.count
71
- max_updated_at = Spree::RailsCompatibility.to_fs((@products.maximum(:updated_at) || Date.today), :number)
71
+ max_updated_at = (@products.maximum(:updated_at) || Date.today).to_fs(:number)
72
72
  "#{I18n.locale}/#{current_pricing_options.cache_key}/spree/products/all-#{params[:page]}-#{max_updated_at}-#{count}"
73
73
  end
74
74
  end
@@ -7,23 +7,6 @@ module Spree
7
7
  extend ActiveSupport::Concern
8
8
  include Spree::ActiveStorageAdapter::Normalization
9
9
 
10
- included do
11
- next if Rails.gem_version >= Gem::Version.new('6.1.0.alpha')
12
-
13
- raise <<~MESSAGE
14
- Configuration Error: Solidus ActiveStorage attachment adpater requires Rails >= 6.1.0.
15
-
16
- Spree::Config.image_attachment_module preference is set to #{Spree::Config.image_attachment_module}
17
- Spree::Config.taxon_attachment_module preference is set to #{Spree::Config.taxon_attachment_module}
18
- Rails version is #{Rails.gem_version}
19
-
20
- To solve the problem you can upgrade to a Rails version greater than or equal to 6.1.0
21
- or use legacy Paperclip attachment adapter by editing `config/initialiers/spree/rb`:
22
- config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
23
- config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
24
- MESSAGE
25
- end
26
-
27
10
  class_methods do
28
11
  attr_reader :attachment_name
29
12
  attr_reader :attachment_definition
@@ -14,15 +14,6 @@ module Spree
14
14
  end
15
15
  end
16
16
 
17
- # Returns `#prices` prioritized for being considered as default price
18
- #
19
- # @deprecated
20
- # @return [ActiveRecord::Relation<Spree::Price>]
21
- def currently_valid_prices
22
- prices.currently_valid
23
- end
24
- deprecate :currently_valid_prices, deprecator: Spree::Deprecation
25
-
26
17
  # Returns {#default_price} or builds it from {Spree::Variant.default_price_attributes}
27
18
  #
28
19
  # @return [Spree::Price, nil]
@@ -32,12 +23,6 @@ module Spree
32
23
  prices.build(self.class.default_price_attributes)
33
24
  end
34
25
 
35
- # @deprecated Use {#default_price_or_build} instead.
36
- def find_or_build_default_price
37
- default_price_or_build
38
- end
39
- deprecate find_or_build_default_price: :default_price_or_build, deprecator: Spree::Deprecation
40
-
41
26
  # Select from {#prices} the one to be considered as the default
42
27
  #
43
28
  # This method works with the in-memory association, so non-persisted prices
@@ -6,27 +6,6 @@ module Spree::RansackableAttributes
6
6
  class_attribute :allowed_ransackable_associations, default: []
7
7
  class_attribute :allowed_ransackable_attributes, default: []
8
8
  class_attribute :allowed_ransackable_scopes, default: []
9
-
10
- def self.whitelisted_ransackable_associations
11
- Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_associations, 'use allowed_ransackable_associations instead')
12
- allowed_ransackable_associations
13
- end
14
-
15
- def self.whitelisted_ransackable_associations=(new_value)
16
- Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_associations=, 'use allowed_ransackable_associations= instead')
17
- self.allowed_ransackable_associations = new_value
18
- end
19
-
20
- def self.whitelisted_ransackable_attributes
21
- Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_attributes, 'use allowed_ransackable_attributes instead')
22
- allowed_ransackable_attributes
23
- end
24
-
25
- def self.whitelisted_ransackable_attributes=(new_value)
26
- Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_attributes=, 'use allowed_ransackable_attributes= instead')
27
- self.allowed_ransackable_attributes = new_value
28
- end
29
-
30
9
  class_attribute :default_ransackable_attributes
31
10
  self.default_ransackable_attributes = %w[id]
32
11
  end
@@ -51,19 +51,6 @@ module Spree
51
51
  extend DisplayMoney
52
52
  money_methods :amount
53
53
 
54
- # Returns Adjustments of completed Orders.
55
- #
56
- # @param excluded_orders [Array<Spree::Order>] Orders to exclude from query
57
- # @return [ActiveRecord::Relation] Scoped Adjustments
58
- def self.in_completed_orders(excluded_orders: [], exclude_canceled: false)
59
- result = joins(:order)
60
- .merge(Spree::Order.complete)
61
- .where.not(spree_orders: { id: excluded_orders })
62
- .distinct
63
- exclude_canceled ? result.merge(Spree::Order.not_canceled) : result
64
- end
65
- deprecate :in_completed_orders, "Please don't use this and rather go through Spree::Promotion#discounted_orders"
66
-
67
54
  def finalize!
68
55
  update!(finalized: true)
69
56
  end
@@ -42,7 +42,7 @@ class Spree::Carton < Spree::Base
42
42
  end
43
43
 
44
44
  def display_shipped_at
45
- Spree::RailsCompatibility.to_fs(shipped_at, :rfc822)
45
+ shipped_at.to_fs(:rfc822)
46
46
  end
47
47
 
48
48
  def manifest
@@ -17,31 +17,19 @@ module Spree
17
17
  # @attr [Integer] quantity How many units we want to move
18
18
  #
19
19
  class FulfilmentChanger
20
- # @note This private constant is only used to deprecate not passing the `track_inventory` argument
21
- # on initialization. It will be removed in Solidus 4.0, please do not use it.
22
- TRACK_INVENTORY_NOT_PROVIDED = Object.new.freeze
23
- private_constant :TRACK_INVENTORY_NOT_PROVIDED
24
-
25
20
  include ActiveModel::Validations
26
21
 
27
22
  attr_accessor :current_shipment, :desired_shipment
28
23
  attr_reader :variant, :quantity, :current_stock_location, :desired_stock_location, :track_inventory
29
24
 
30
- def initialize(current_shipment:, desired_shipment:, variant:, quantity:, track_inventory: TRACK_INVENTORY_NOT_PROVIDED)
25
+ def initialize(current_shipment:, desired_shipment:, variant:, quantity:, track_inventory:)
31
26
  @current_shipment = current_shipment
32
27
  @desired_shipment = desired_shipment
33
28
  @current_stock_location = current_shipment.stock_location
34
29
  @desired_stock_location = desired_shipment.stock_location
35
30
  @variant = variant
36
31
  @quantity = quantity
37
- @track_inventory = if track_inventory == TRACK_INVENTORY_NOT_PROVIDED
38
- Spree::Deprecation.warn(
39
- "Not passing `track_inventory` to `Spree::FulfilmentChanger` is deprecated." \
40
- )
41
- true
42
- else
43
- track_inventory
44
- end
32
+ @track_inventory = track_inventory
45
33
  end
46
34
 
47
35
  validates :quantity, numericality: { greater_than: 0 }
@@ -2,9 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class OptionValue < Spree::Base
5
- # TODO: Remove optional on Solidus v4.0. Don't forget adding a migration to
6
- # enforce at the database layer
7
- belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :option_values, optional: true
5
+ belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :option_values
8
6
  acts_as_list scope: :option_type
9
7
 
10
8
  has_many :option_values_variants, dependent: :destroy
@@ -15,15 +13,8 @@ module Spree
15
13
 
16
14
  after_save :touch, if: :saved_changes?
17
15
  after_touch :touch_all_variants
18
- after_save do
19
- Spree::Deprecation.warn <<~MSG if option_type.nil?
20
- Having an option_value with no associated option_type will be deprecated
21
- on Solidus v4.0
22
- MSG
23
- end
24
16
 
25
- # TODO: Remove allow_nil once option_type is required on Solidus v4.0
26
- delegate :name, :presentation, to: :option_type, prefix: :option_type, allow_nil: true
17
+ delegate :name, :presentation, to: :option_type, prefix: :option_type
27
18
 
28
19
  self.allowed_ransackable_attributes = %w[name presentation]
29
20
 
@@ -154,6 +154,8 @@ module Spree
154
154
  find_by! number: value
155
155
  end
156
156
 
157
+ delegate :recalculate, to: :recalculator
158
+
157
159
  delegate :name, to: :bill_address, prefix: true, allow_nil: true
158
160
  alias_method :billing_name, :bill_address_name
159
161
 
@@ -258,13 +260,11 @@ module Spree
258
260
  end || store&.default_cart_tax_location
259
261
  end
260
262
 
261
- def updater
262
- @updater ||= Spree::OrderUpdater.new(self)
263
- end
264
-
265
- def recalculate
266
- updater.update
263
+ def recalculator
264
+ @recalculator ||= Spree::Config.order_recalculator_class.new(self)
267
265
  end
266
+ alias_method :updater, :recalculator
267
+ deprecate updater: :recalculator, deprecator: Spree::Deprecation
268
268
 
269
269
  def assign_billing_to_shipping_address
270
270
  self.ship_address = bill_address if bill_address
@@ -395,21 +395,9 @@ module Spree
395
395
  Spree::CreditCard.where(id: credit_card_ids)
396
396
  end
397
397
 
398
- # TODO: Remove on Solidus 4.0
399
- # @api private
400
- def finalize!
401
- Spree::Deprecation.warn <<~MSG
402
- Calling `Spree::Order#finalize!` is discouraged. Instead, use
403
- `Spree::Order#complete!`, which goes through all the needed safety
404
- checks before finalizing an order. This method will be removed
405
- altogether on Solidus 4.0.
406
- MSG
407
- finalize
408
- end
409
-
410
398
  def fulfill!
411
399
  shipments.each { |shipment| shipment.update_state if shipment.persisted? }
412
- updater.update_shipment_state
400
+ recalculator.update_shipment_state
413
401
  save!
414
402
  end
415
403
 
@@ -514,12 +502,9 @@ module Spree
514
502
  recalculate
515
503
  end
516
504
 
517
- # Clean shipments and make order back to address state
518
- #
519
- # At some point the might need to force the order to transition from address
520
- # to delivery again so that proper updated shipments are created.
521
- # e.g. customer goes back from payment step and changes order items
522
- def ensure_updated_shipments
505
+ # Clean shipments and make order back to address state (or to whatever state
506
+ # is set by restart_checkout_flow in case of state machine modifications)
507
+ def check_shipments_and_restart_checkout
523
508
  if !completed? && shipments.all?(&:pending?)
524
509
  shipments.destroy_all
525
510
  update_column(:shipment_total, 0)
@@ -527,6 +512,9 @@ module Spree
527
512
  end
528
513
  end
529
514
 
515
+ alias_method :ensure_updated_shipments, :check_shipments_and_restart_checkout
516
+ deprecate ensure_updated_shipments: :check_shipments_and_restart_checkout, deprecator: Spree::Deprecation
517
+
530
518
  def restart_checkout_flow
531
519
  return if state == 'cart'
532
520
 
@@ -552,9 +540,7 @@ module Spree
552
540
  def canceled_by(user)
553
541
  transaction do
554
542
  cancel!
555
- # rubocop:disable Rails/SkipsModelValidations
556
543
  update_column(:canceler_id, user.id)
557
- # rubocop:enable Rails/SkipsModelValidations
558
544
  end
559
545
  end
560
546
 
@@ -571,8 +557,7 @@ module Spree
571
557
  end
572
558
 
573
559
  def has_non_reimbursement_related_refunds?
574
- refunds.non_reimbursement.exists? ||
575
- payments.where("source_type = 'Spree::Payment' AND amount < 0 AND state = 'completed'").exists? # how old versions of spree stored refunds
560
+ refunds.non_reimbursement.exists?
576
561
  end
577
562
 
578
563
  def tax_total
@@ -757,13 +742,13 @@ module Spree
757
742
  all_adjustments.each(&:finalize!)
758
743
 
759
744
  # update payment and shipment(s) states, and save
760
- updater.update_payment_state
745
+ recalculator.update_payment_state
761
746
  shipments.each do |shipment|
762
747
  shipment.update_state
763
748
  shipment.finalize!
764
749
  end
765
750
 
766
- updater.update_shipment_state
751
+ recalculator.update_shipment_state
767
752
  save!
768
753
 
769
754
  touch :completed_at
@@ -779,16 +764,17 @@ module Spree
779
764
  self.email = user.email if user
780
765
  end
781
766
 
782
- # Determine if email is required (we don't want validation errors before we hit the checkout)
767
+ # Determine if the email is required for this order
768
+ #
769
+ # We don't require email for orders in the cart state or address state because those states
770
+ # precede the entry of an email address.
771
+ #
772
+ # @return [Boolean] true if the email is required
773
+ # @note This method was called require_email before.
783
774
  def email_required?
784
775
  true unless new_record? || ['cart', 'address'].include?(state)
785
776
  end
786
777
 
787
- def require_email
788
- Spree::Deprecation.warn "Use email_required? instead", caller(1)
789
- email_required?
790
- end
791
-
792
778
  def ensure_inventory_units
793
779
  if has_checkout_step?("delivery")
794
780
  inventory_validator = Spree::Config.stock.inventory_validator_class.new
@@ -845,9 +831,7 @@ module Spree
845
831
  cancel_payments!
846
832
 
847
833
  send_cancel_email
848
- # rubocop:disable Rails/SkipsModelValidations
849
834
  update_column(:canceled_at, Time.current)
850
- # rubocop:enable Rails/SkipsModelValidations
851
835
  recalculate
852
836
  end
853
837
 
@@ -42,7 +42,7 @@ module Spree
42
42
  # If we do not update first, then the item total will be wrong and ItemTotal
43
43
  # promotion rules would not be triggered.
44
44
  reload_totals
45
- order.ensure_updated_shipments
45
+ order.check_shipments_and_restart_checkout
46
46
  PromotionHandler::Cart.new(order).activate
47
47
  end
48
48
  reload_totals
@@ -73,7 +73,7 @@ module Spree
73
73
  def after_add_or_remove(line_item, options = {})
74
74
  reload_totals
75
75
  shipment = options[:shipment]
76
- shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments
76
+ shipment.present? ? shipment.update_amounts : order.check_shipments_and_restart_checkout
77
77
  PromotionHandler::Cart.new(order, line_item).activate
78
78
  reload_totals
79
79
  line_item
@@ -13,8 +13,6 @@ module Spree
13
13
  # @return [Spree::Order] The order which items wll be merged into.
14
14
  attr_accessor :order
15
15
 
16
- delegate :updater, to: :order
17
-
18
16
  # Create the OrderMerger
19
17
  #
20
18
  # @api public
@@ -133,13 +131,13 @@ module Spree
133
131
 
134
132
  # Save the order totals after merge
135
133
  #
136
- # It triggers the order updater to ensure that item counts and totals are
134
+ # It triggers the order recalculator to ensure that item counts and totals are
137
135
  # up to date.
138
136
  #
139
137
  # @api private
140
138
  # @return [void]
141
139
  def persist_merge
142
- updater.update
140
+ order.recalculate
143
141
  end
144
142
  end
145
143
  end
@@ -16,7 +16,7 @@ module Spree
16
16
  # This method should never do anything to the Order that results in a save call on the
17
17
  # object with callbacks (otherwise you will end up in an infinite recursion as the
18
18
  # associations try to save and then in turn try to call +update!+ again.)
19
- def update
19
+ def recalculate
20
20
  order.transaction do
21
21
  update_item_count
22
22
  update_shipment_amounts
@@ -30,6 +30,8 @@ module Spree
30
30
  persist_totals
31
31
  end
32
32
  end
33
+ alias_method :update, :recalculate
34
+ deprecate update: :recalculate, deprecator: Spree::Deprecation
33
35
 
34
36
  # Updates the +shipment_state+ attribute according to the following logic:
35
37
  #
@@ -162,9 +164,6 @@ module Spree
162
164
  order.included_tax_total = all_items.sum(&:included_tax_total) + order_tax_adjustments.select(&:included?).sum(&:amount)
163
165
  order.additional_tax_total = all_items.sum(&:additional_tax_total) + order_tax_adjustments.reject(&:included?).sum(&:amount)
164
166
 
165
- # TODO: Delete this line in Solidus 4.0, when it is run in `update_promotions`.
166
- order.promo_total = all_items.sum(&:promo_total) + adjustments.select(&:eligible?).select(&:promotion?).sum(&:amount)
167
-
168
167
  update_order_total
169
168
  end
170
169
 
@@ -200,32 +199,6 @@ module Spree
200
199
  Spree::Config.promotion_adjuster_class.new(order).call
201
200
  end
202
201
 
203
- # DEPRECATED; this functionality is handled in #update_promotions
204
- def update_item_promotions
205
- [*line_items, *shipments].each do |item|
206
- promotion_adjustments = item.adjustments.select(&:promotion?)
207
-
208
- promotion_adjustments.each(&:recalculate)
209
- Spree::Config.promotion_chooser_class.new(promotion_adjustments).update
210
-
211
- item.promo_total = promotion_adjustments.select(&:eligible?).sum(&:amount)
212
- end
213
- end
214
- deprecate update_item_promotions: :update_promotions, deprecator: Spree::Deprecation
215
-
216
- # Update and select the best promotion adjustment for the order.
217
- # We don't update the order.promo_total yet. Order totals are updated later
218
- # in #update_adjustment_total since they include the totals from the order's
219
- # line items and/or shipments.
220
- #
221
- # DEPRECATED; this functionality is handled in #update_promotions
222
- def update_order_promotions
223
- promotion_adjustments = order.adjustments.select(&:promotion?)
224
- promotion_adjustments.each(&:recalculate)
225
- Spree::Config.promotion_chooser_class.new(promotion_adjustments).update
226
- end
227
- deprecate update_order_promotions: :update_promotions, deprecator: Spree::Deprecation
228
-
229
202
  def update_taxes
230
203
  Spree::Config.tax_adjuster_class.new(order).adjust!
231
204
 
@@ -16,7 +16,6 @@ module Spree
16
16
  belongs_to :source, polymorphic: true, optional: true
17
17
  belongs_to :payment_method, -> { with_discarded }, class_name: 'Spree::PaymentMethod', inverse_of: :payments, optional: true
18
18
 
19
- has_many :offsets, -> { offset_payment }, class_name: "Spree::Payment", foreign_key: :source_id
20
19
  has_many :log_entries, as: :source
21
20
  has_many :state_changes, as: :stateful
22
21
  has_many :capture_events, class_name: 'Spree::PaymentCaptureEvent'
@@ -45,19 +44,6 @@ module Spree
45
44
 
46
45
  scope :from_credit_card, -> { where(source_type: 'Spree::CreditCard') }
47
46
  scope :with_state, ->(state) { where(state: state.to_s) }
48
- # "offset" is reserved by activerecord
49
- # TODO: When removing the method we can also:
50
- # - Remove the `.offsets` association
51
- # - Remove the `#offsets_total` method
52
- # - Remove offsets count from the `#credit_allowed` method
53
- # - Remove offsets check from `Spree::Order#has_non_reimbursement_related_refunds?
54
- def self.offset_payment
55
- Spree::Deprecation.warn <<~MSG
56
- `Spree::Payment offsets` are deprecated. Use the refund system (`Spree::Refund`) instead.
57
- MSG
58
-
59
- where("source_type = 'Spree::Payment' AND amount < 0 AND state = 'completed'")
60
- end
61
47
 
62
48
  scope :checkout, -> { with_state('checkout') }
63
49
  scope :completed, -> { with_state('completed') }
@@ -100,22 +86,11 @@ module Spree
100
86
  end || amount
101
87
  end
102
88
 
103
- # The total amount of the offsets (for old-style refunds) for this payment.
104
- #
105
- # @return [BigDecimal] the total amount of this payment's offsets
106
- def offsets_total
107
- offsets.pluck(:amount).sum
108
- end
109
-
110
89
  # The total amount this payment can be credited.
111
90
  #
112
- # @return [BigDecimal] the amount of this payment minus the offsets
113
- # (old-style refunds) and refunds
91
+ # @return [BigDecimal] the amount of this payment minus refunds
114
92
  def credit_allowed
115
- amount - (
116
- (self.class.where("source_type = 'Spree::Payment' AND amount < 0 AND state = 'completed' AND source_id = ?", id).sum(:amount)).abs +
117
- refunds.sum(:amount)
118
- )
93
+ amount - refunds.sum(:amount)
119
94
  end
120
95
 
121
96
  # @return [Boolean] true when this payment can be credited
@@ -183,16 +158,9 @@ module Spree
183
158
 
184
159
  def validate_source
185
160
  if source && !source.valid?
186
- if Gem::Requirement.new(">= 6.1").satisfied_by?(Rails.gem_version)
187
- source.errors.each do |error|
188
- field_name = I18n.t("activerecord.attributes.#{source.class.to_s.underscore}.#{error.attribute}")
189
- errors.add(I18n.t(source.class.to_s.demodulize.underscore, scope: 'spree'), "#{field_name} #{error.message}")
190
- end
191
- else
192
- source.errors.each do |field, error|
193
- field_name = I18n.t("activerecord.attributes.#{source.class.to_s.underscore}.#{field}")
194
- errors.add(I18n.t(source.class.to_s.demodulize.underscore, scope: 'spree'), "#{field_name} #{error}")
195
- end
161
+ source.errors.each do |error|
162
+ field_name = I18n.t("activerecord.attributes.#{source.class.to_s.underscore}.#{error.attribute}")
163
+ errors.add(I18n.t(source.class.to_s.demodulize.underscore, scope: 'spree'), "#{field_name} #{error.message}")
196
164
  end
197
165
  end
198
166
  if errors.any?
@@ -214,11 +214,6 @@ module Spree
214
214
  where(subquery.arel.exists)
215
215
  end
216
216
 
217
- def self.with_variant_sku_cont(sku)
218
- Spree::Deprecation.warn("use .with_kept_variant_sku_cont instead")
219
- with_kept_variant_sku_cont(sku)
220
- end
221
-
222
217
  class << self
223
218
  private
224
219
 
@@ -96,7 +96,6 @@ module Spree
96
96
  :display_price,
97
97
  :has_default_price?,
98
98
  :images,
99
- :price_for,
100
99
  :price_for_options,
101
100
  :rebuild_vat_prices=,
102
101
  to: :find_or_build_master
@@ -134,7 +133,7 @@ module Spree
134
133
 
135
134
  self.allowed_ransackable_associations = %w[stores variants_including_master master variants]
136
135
  self.allowed_ransackable_attributes = %w[name slug]
137
- self.allowed_ransackable_scopes = %i[available with_discarded with_variant_sku_cont with_all_variant_sku_cont with_kept_variant_sku_cont]
136
+ self.allowed_ransackable_scopes = %i[available with_discarded with_all_variant_sku_cont with_kept_variant_sku_cont]
138
137
 
139
138
  # @return [Boolean] true if there are any variants
140
139
  def has_variants?
@@ -337,14 +336,8 @@ module Spree
337
336
  # If the master is invalid, the Product object will be assigned its errors
338
337
  def validate_master
339
338
  unless master.valid?
340
- if Gem::Requirement.new(">= 6.1").satisfied_by?(Rails.gem_version)
341
- master.errors.each do |error|
342
- errors.add(error.attribute, error.message)
343
- end
344
- else
345
- master.errors.each do |att, error|
346
- errors.add(att, error)
347
- end
339
+ master.errors.each do |error|
340
+ errors.add(error.attribute, error.message)
348
341
  end
349
342
  end
350
343
  end
@@ -9,8 +9,6 @@ module Spree
9
9
  # To add extra operators please override `self.operators_map` or any other helper method.
10
10
  # To customize the error message you can also override `ineligible_message`.
11
11
  class ItemTotal < PromotionRule
12
- include ActiveSupport::Deprecation::DeprecatedConstantAccessor
13
-
14
12
  preference :amount, :decimal, default: 100.00
15
13
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
16
14
  preference :operator, :string, default: 'gt'
@@ -29,15 +27,6 @@ module Spree
29
27
  end
30
28
  end
31
29
 
32
- # @deprecated
33
- OPERATORS = operators_map.keys.map(&:to_s)
34
- deprecate_constant(
35
- :OPERATORS,
36
- :operators_map,
37
- message: "OPERATORS is deprecated! Use `operators_map.keys.map(&:to_s)` instead.",
38
- deprecator: Spree::Deprecation,
39
- )
40
-
41
30
  def applicable?(promotable)
42
31
  promotable.is_a?(Spree::Order)
43
32
  end