Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Deprecate the returns settings that 6.0 stopped reading

Damian Legawiec31715a3c9f26
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 4b4af1d19e..14edb3882b 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -230,7 +230,13 @@ Spree::Return.add_status('inspecting', after: 'received')
Core ships exactly one policy rule — a return window read from `market.preferred_return_window_days` (default 30), per market because return windows are a regional legal matter. **Staff can override it**: when `created_by` is present the window is advisory, so a supervisor can accept a late return without a code change.
<Warning>
- `Spree::Config[:return_eligibility_number_of_days]` is **no longer read by anything**. The preference still exists so setting it won't crash, but it has no effect — move the value to your markets' `preferred_return_window_days`.
+ Four returns settings are **deprecated and read by nothing** — they still exist so applications don't crash at boot, but they have no effect and now emit a deprecation warning when read or written:
+
+ | Deprecated setting | Use instead |
+ |---|---|
+ | `return_eligibility_number_of_days` | `preferred_return_window_days` on `Spree::Market`, or a `returns.create.validate` hook |
+ | `restock_inventory` | `Spree::ReturnLineItem#resellable`, decided per line item at receiving |
+ | `expedited_exchanges`, `expedited_exchanges_days_window` | `Spree::Exchange` and the `Exchanges::Fulfill` workflow |
</Warning>
Replace it by swapping the handler:
diff --git a/spree/core/lib/spree/core/configuration.rb b/spree/core/lib/spree/core/configuration.rb
index a253b084fd..fc9ad6ac39 100644
--- a/spree/core/lib/spree/core/configuration.rb
+++ b/spree/core/lib/spree/core/configuration.rb
@@ -51,8 +51,8 @@ module Spree
preference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validation
preference :disable_store_presence_validation, :boolean, default: false, deprecated: true # when turned off disables Store presence validation for Products and Payment Methods
preference :events_log_enabled, :boolean, default: true # Log all Spree events to Rails logger
- preference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.
- preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being charged
+ preference :expedited_exchanges, :boolean, default: false, deprecated: 'Exchanges are their own record in Spree 6 — see Spree::Exchange and the Exchanges::Fulfill workflow'
+ preference :expedited_exchanges_days_window, :integer, default: 14, deprecated: 'Exchanges are their own record in Spree 6 — see Spree::Exchange and the Exchanges::Fulfill workflow'
preference :geocode_addresses, :boolean, default: true
preference :images_save_from_url_job_attempts, :integer, default: 5
preference :max_image_download_size, :integer, default: 20_971_520 # 20 MB in bytes
@@ -92,8 +92,8 @@ module Spree
preference :max_level_in_taxons_menu, :integer, deprecated: true
preference :non_expiring_credit_types, :array, default: []
preference :products_per_page, :integer, default: 12
- preference :restock_inventory, :boolean, default: true # Determines if a return item is restocked automatically once it has been received
- preference :return_eligibility_number_of_days, :integer, default: 365
+ preference :restock_inventory, :boolean, default: true, deprecated: 'Restocking is decided per line item by Spree::ReturnLineItem#resellable'
+ preference :return_eligibility_number_of_days, :integer, default: 365, deprecated: 'Use the return_window_days preference on Spree::Market, or a returns.create.validate hook'
preference :reserve_stock_on, :string, default: 'checkout' # 'checkout' (default) or 'cart' — landing in 6.0 alongside Cart/Order split
preference :stock_reservations_enabled, :boolean, default: true # Hold stock during checkout to prevent overselling
preference :default_stock_reservation_ttl_minutes, :integer, default: 10 # Fallback TTL when a Store doesn't override
diff --git a/spree/core/lib/spree/core/preferences/runtime_configuration.rb b/spree/core/lib/spree/core/preferences/runtime_configuration.rb
index f6e40001b1..3bee4b6c26 100644
--- a/spree/core/lib/spree/core/preferences/runtime_configuration.rb
+++ b/spree/core/lib/spree/core/preferences/runtime_configuration.rb
@@ -2,15 +2,11 @@ module Spree
module Preferences
class RuntimeConfiguration
def initialize
- self.class.defaults.each do |key, value|
- self[key] = value
- end
+ load_defaults
end
def reset
- self.class.defaults.each do |key, value|
- self[key] = value
- end
+ load_defaults
end
def configure
@@ -18,6 +14,7 @@ module Spree
end
def get(preference)
+ warn_if_deprecated(preference)
send(preference)
end
@@ -26,14 +23,36 @@ module Spree
def set(*args)
options = args.extract_options!
options.each do |name, value|
+ warn_if_deprecated(name)
send("#{name}=", value)
end
- send("#{args[0]}=", args[1]) if args.size == 2
+ if args.size == 2
+ warn_if_deprecated(args[0])
+ send("#{args[0]}=", args[1])
+ end
end
alias []= set
+ private
+
+ # Seeding defaults writes every preference, including the deprecated
+ # ones, so it goes straight to the accessor — warning on boot would fire
+ # for settings the application never touches.
+ def load_defaults
+ self.class.defaults.each { |key, value| send("#{key}=", value) }
+ end
+
+ def warn_if_deprecated(preference)
+ message = self.class.deprecations[preference.to_sym]
+ return if message.blank?
+
+ Spree::Deprecation.warn(
+ message.is_a?(String) ? "Spree::Config[:#{preference}] is deprecated. #{message}" : "Spree::Config[:#{preference}] is deprecated."
+ )
+ end
+
class << self
def preference(name, _type, default: nil, deprecated: false)
defaults[name] = default