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

Move line_item_comparison_hooks config to Spree::Config #6050

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ def self.find_by_param!(value)
delegate :name, to: :bill_address, prefix: true, allow_nil: true
alias_method :billing_name, :bill_address_name

class_attribute :line_item_comparison_hooks
self.line_item_comparison_hooks = Set.new
def line_item_comparison_hooks
Set.new(Spree::Config.line_item_comparison_hooks)
end

class << self
def line_item_comparison_hooks=(value)
Spree::Config.line_item_comparison_hooks = value.to_a
end
deprecate :line_item_comparison_hooks=, deprecator: Spree.deprecator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a deprecation message?

end

scope :created_between, ->(start_date, end_date) { where(created_at: start_date..end_date) }
scope :completed_between, ->(start_date, end_date) { where(completed_at: start_date..end_date) }
Expand Down
7 changes: 7 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ class AppConfiguration < Preferences::Configuration
# @return [String] template to use for layout on the frontend (default: +"spree/layouts/spree_application"+)
preference :layout, :string, default: 'spree/layouts/spree_application'

# !@attribute [rw] line_item_comparison_hooks
# @return [Array<Symbol>] An array of methods to call on {Spree::Order} to determine if a line item is equal to another
# (default: +[]+)
# @example
# config.line_item_comparison_hooks << :my_custom_method
preference :line_item_comparison_hooks, :array, default: []

# @!attribute [rw] logo
# @return [String] URL of logo used on frontend (default: +'logo/solidus.svg'+)
preference :logo, :string, default: 'logo/solidus.svg'
Expand Down
7 changes: 1 addition & 6 deletions core/spec/models/spree/order_merger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ module Spree

context "merging using extension-specific line_item_comparison_hooks" do
before do
Spree::Order.register_line_item_comparison_hook(:foos_match)
end

after do
# reset to avoid test pollution
Spree::Order.line_item_comparison_hooks = Set.new
stub_spree_preferences(line_item_comparison_hooks: [:foos_match])
end

context "2 equal line items" do
Expand Down
7 changes: 1 addition & 6 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,7 @@ def merge!(other_order, user = nil)

context "match line item with options", partial_double_verification: false do
before do
Spree::Order.register_line_item_comparison_hook(:foos_match)
end

after do
# reset to avoid test pollution
Spree::Order.line_item_comparison_hooks = Set.new
stub_spree_preferences(line_item_comparison_hooks: [:foos_match])
end

it "matches line item when options match" do
Expand Down
5 changes: 1 addition & 4 deletions promotions/lib/solidus_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class Engine < Rails::Engine

initializer "solidus_promotions.spree_config", after: "spree.load_config_initializers" do
Spree::Config.adjustment_promotion_source_types << "SolidusPromotions::Benefit"

Rails.application.config.to_prepare do
Spree::Order.line_item_comparison_hooks << :free_from_order_benefit?
end
Spree::Config.line_item_comparison_hooks << :free_from_order_benefit?
end

initializer "solidus_promotions.core.pub_sub", after: "spree.core.pub_sub" do |app|
Expand Down
Loading