Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a deprecation warning for allow_promotions_any_match_policy = true #4991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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