Skip to content

Commit

Permalink
Merge pull request #4991 from nebulab/kennyadsl/deprecate-promotion-m…
Browse files Browse the repository at this point in the history
…atch-any

Add a deprecation warning for allow_promotions_any_match_policy = true
  • Loading branch information
kennyadsl committed Mar 29, 2023
2 parents 61a1893 + bc82ebd commit 1c5adde
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/app/models/spree/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
16 changes: 16 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions core/lib/spree/promotion/match_policies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Spree::Promotion::MATCH_POLICIES = %w(all any)
Spree::Deprecation.warn('Spree::Promotion::MATCH_POLICIES is deprecated')
7 changes: 7 additions & 0 deletions core/spec/models/spree/promotion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1c5adde

Please sign in to comment.