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.

Added Spree::BaseFinder class

Damian Legawiec1cfa09476fc2
diff --git a/core/app/finders/spree/addresses/find.rb b/core/app/finders/spree/addresses/find.rb
index 32befaacf5..44c2f57710 100644
--- a/core/app/finders/spree/addresses/find.rb
+++ b/core/app/finders/spree/addresses/find.rb
@@ -1,17 +1,6 @@
module Spree
module Addresses
- class Find
- def initialize(scope:, params:)
- @scope = scope
- end
-
- def execute
- scope
- end
-
- private
-
- attr_reader :scope
+ class Find < ::Spree::BaseFinder
end
end
end
diff --git a/core/app/finders/spree/base_finder.rb b/core/app/finders/spree/base_finder.rb
new file mode 100644
index 0000000000..6f5239e31f
--- /dev/null
+++ b/core/app/finders/spree/base_finder.rb
@@ -0,0 +1,14 @@
+module Spree
+ class BaseFinder
+ def initialize(scope:, params:)
+ @scope = scope
+ @params = params
+ end
+
+ attr_reader :scope, :params
+
+ def execute
+ scope
+ end
+ end
+end
diff --git a/core/app/finders/spree/countries/find.rb b/core/app/finders/spree/countries/find.rb
index e06a7f67e9..bf6c1048f8 100644
--- a/core/app/finders/spree/countries/find.rb
+++ b/core/app/finders/spree/countries/find.rb
@@ -1,13 +1,21 @@
module Spree
module Countries
- class Find
- def initialize(scope, params)
+ class Find < ::Spree::BaseFinder
+ def initialize(scope:, params:)
@scope = scope
@shippable = String(params[:filter][:shippable]) unless params[:filter].nil?
end
def call
+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
+ Spree::Countries::Find.new.call is deprecated and will be removed in Spree 5.0.
+ Please use Spree::Countries::Find.new.execute instead
+ DEPRECATION
+ execute
+ end
+
+ def execute
countries = by_shippability(scope)
countries
@@ -15,7 +23,7 @@ module Spree
private
- attr_reader :shippable, :scope
+ attr_reader :shippable
def shippable?
shippable.present?
diff --git a/core/app/finders/spree/credit_cards/find.rb b/core/app/finders/spree/credit_cards/find.rb
index fea478750c..2fe37c405b 100644
--- a/core/app/finders/spree/credit_cards/find.rb
+++ b/core/app/finders/spree/credit_cards/find.rb
@@ -1,7 +1,7 @@
module Spree
module CreditCards
- class Find
- def execute(scope:, params:)
+ class Find < ::Spree::BaseFinder
+ def execute
return scope.default.take if params[:id].eql?('default')
return scope.where(payment_method_id: params[:filter]['payment_method_id']) if params[:filter].present?