diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rb index 6b4794b7a88..999e79b0db6 100644 --- a/core/app/models/spree/promotion.rb +++ b/core/app/models/spree/promotion.rb @@ -2,7 +2,8 @@ module Spree class Promotion < Spree::Base - MATCH_POLICIES = %w(all any) + + autoload(:MATCH_POLICIES, "spree/promotion/match_policies") UNACTIVATABLE_ORDER_STATES = ["complete", "awaiting_return", "returned"] diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index 75d7ed31d8b..05649689168 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -65,6 +65,22 @@ class AppConfiguration < Preferences::Configuration # @return [Boolean] When false, admins cannot create promotions with an "any" match policy (default: +false+) # Create individual, separate promotions for each of your rules instead. preference :allow_promotions_any_match_policy, :boolean, default: false + def allow_promotions_any_match_policy=(value) + if value == true + Spree::Deprecation.warn <<~MSG + Solidus 4.0 will remove support for combining promotion rules with the "any" match policy. + + Instead, it's suggested to create individual, separate promotions for each of your current + rules combined with the "any" policy. To automate this task, you can use the provided + task: + + bin/rake solidus:split_promotions_with_any_match_policy + MSG + end + + preferences[:allow_promotions_any_match_policy] = value + end + # @!attribute [rw] guest_token_cookie_options # @return [Hash] Add additional guest_token cookie options here (ie. domain or path) diff --git a/core/lib/spree/promotion/match_policies.rb b/core/lib/spree/promotion/match_policies.rb new file mode 100644 index 00000000000..712dbd029c9 --- /dev/null +++ b/core/lib/spree/promotion/match_policies.rb @@ -0,0 +1,2 @@ +Spree::Promotion::MATCH_POLICIES = %w(all any) +Spree::Deprecation.warn('Spree::Promotion::MATCH_POLICIES is deprecated') diff --git a/core/spec/models/spree/promotion_spec.rb b/core/spec/models/spree/promotion_spec.rb index 1dcdc483cae..ff848a65299 100644 --- a/core/spec/models/spree/promotion_spec.rb +++ b/core/spec/models/spree/promotion_spec.rb @@ -993,4 +993,11 @@ expect(order.adjustment_total).to eq(-10) end end + + describe "MATCH_POLICIES" do + it "prints a deprecation warning when used" do + expect(Spree::Deprecation).to receive(:warn).once.with(/Spree::Promotion::MATCH_POLICIES is deprecated/) + expect(Spree::Promotion::MATCH_POLICIES).to eq %w(all any) + end + end end