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.

Removed unused finders

Damian Legawiecd666cd402e74
diff --git a/spree/core/app/finders/concerns/spree/product_filterable.rb b/spree/core/app/finders/concerns/spree/product_filterable.rb
deleted file mode 100644
index 729b7d5789..0000000000
--- a/spree/core/app/finders/concerns/spree/product_filterable.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-module Spree
- module ProductFilterable
- private
-
- def find_available(scope, products_scope)
- scope.filterable.for_products(products_scope)
- end
- end
-end
diff --git a/spree/core/app/finders/spree/addresses/find.rb b/spree/core/app/finders/spree/addresses/find.rb
deleted file mode 100644
index 42508163f0..0000000000
--- a/spree/core/app/finders/spree/addresses/find.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-module Spree
- module Addresses
- class Find < ::Spree::BaseFinder
- def initialize(scope:, params:)
- super
- @exclude_quick_checkout = params.dig(:filter, :exclude_quick_checkout)
- end
-
- def execute
- addresses = scope
- exclude_quick_checkout(addresses)
- end
-
- private
-
- def exclude_quick_checkout?
- @exclude_quick_checkout.present?
- end
-
- def exclude_quick_checkout(addresses)
- return addresses unless exclude_quick_checkout?
-
- addresses.not_quick_checkout
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/base_finder.rb b/spree/core/app/finders/spree/base_finder.rb
deleted file mode 100644
index 6f5239e31f..0000000000
--- a/spree/core/app/finders/spree/base_finder.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-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/spree/core/app/finders/spree/countries/find.rb b/spree/core/app/finders/spree/countries/find.rb
deleted file mode 100644
index 932ccf23ea..0000000000
--- a/spree/core/app/finders/spree/countries/find.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-module Spree
- module Countries
- class Find < ::Spree::BaseFinder
- def initialize(scope:, params:)
- @scope = scope
-
- @shippable = String(params[:filter][:shippable]) unless params[:filter].nil?
- end
-
- def execute
- countries = by_shippability(scope)
-
- countries
- end
-
- private
-
- attr_reader :shippable
-
- def shippable?
- shippable.present?
- end
-
- def by_shippability(countries)
- return countries unless shippable?
-
- countries.joins(zones: :shipping_methods).distinct
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/credit_cards/find.rb b/spree/core/app/finders/spree/credit_cards/find.rb
deleted file mode 100644
index 2fe37c405b..0000000000
--- a/spree/core/app/finders/spree/credit_cards/find.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module Spree
- module CreditCards
- 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?
-
- scope
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/option_values/find_available.rb b/spree/core/app/finders/spree/option_values/find_available.rb
deleted file mode 100644
index 94aca09f85..0000000000
--- a/spree/core/app/finders/spree/option_values/find_available.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module Spree
- module OptionValues
- class FindAvailable
- include ProductFilterable
-
- def initialize(scope: OptionValue.spree_base_scopes, products_scope: Product.spree_base_scopes)
- @scope = scope
- @products_scope = products_scope
- end
-
- def execute
- find_available(scope, products_scope).includes(:translations).select(select_args).order(order_args)
- end
-
- private
-
- attr_reader :scope, :products_scope
-
- def select_args
- "#{OptionValue.table_name}.*, #{OptionType.table_name}.position AS option_type_position"
- end
-
- def order_args
- "option_type_position, #{OptionValue.table_name}.position"
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/orders/find_complete.rb b/spree/core/app/finders/spree/orders/find_complete.rb
deleted file mode 100644
index f895cc02d5..0000000000
--- a/spree/core/app/finders/spree/orders/find_complete.rb
+++ /dev/null
@@ -1,114 +0,0 @@
-module Spree
- module Orders
- class FindComplete
- include Spree::Orders::FinderHelper
-
- attr_reader :user, :number, :prefix_id, :param, :token, :store, :email
-
- def initialize(user: nil, number: nil, prefix_id: nil, param: nil, token: nil, store: nil, email: nil)
- @user = user
- @number = number
- @prefix_id = prefix_id
- @param = param
- @token = token
- @store = store
- @email = email
- end
-
- def execute
- orders = by_user(scope)
- orders = by_number(orders)
- orders = by_prefix_id(orders)
- orders = by_param(orders)
- orders = by_token(orders)
- orders = by_store(orders)
- orders = by_email(orders)
-
- orders
- end
-
- private
-
- def scope
- user? ? user.orders.complete.includes(order_includes) : Spree::Order.complete.includes(order_includes)
- end
-
- def user?
- user.present?
- end
-
- def number?
- number.present?
- end
-
- def prefix_id?
- prefix_id.present?
- end
-
- def param?
- param.present?
- end
-
- def token?
- token.present?
- end
-
- def store?
- store.present?
- end
-
- def email?
- email.present?
- end
-
- def by_user(orders)
- return orders unless user?
-
- orders
- end
-
- def by_number(orders)
- return orders unless number?
-
- orders.where(number: number)
- end
-
- def by_prefix_id(orders)
- return orders unless prefix_id?
-
- decoded = Spree::Order.decode_prefixed_id(prefix_id)
- orders.where(id: decoded)
- end
-
- # Find by param - tries prefixed ID first, then number for backwards compatibility
- def by_param(orders)
- return orders unless param?
-
- decoded = Spree::Order.decode_prefixed_id(param)
- if decoded
- orders.where(id: decoded)
- else
- orders.where(number: param)
- end
- end
-
- def by_token(orders)
- return orders unless token?
-
- orders.where(token: token)
- end
-
- def by_store(orders)
- return orders unless store?
-
- orders.where(store: store)
- end
-
- def by_email(orders)
- return orders unless email?
-
- orders.where(email: email.strip.downcase)
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/orders/find_current.rb b/spree/core/app/finders/spree/orders/find_current.rb
deleted file mode 100644
index 0e06ce2e58..0000000000
--- a/spree/core/app/finders/spree/orders/find_current.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-module Spree
- module Orders
- class FindCurrent
- include Spree::Orders::FinderHelper
-
- def execute(user:, store:, **params)
- params = params.merge(store_id: store.id)
-
- order = incomplete_orders.find_by(params)
-
- return order unless order.nil?
- return if user.nil?
-
- incomplete_orders.order(created_at: :desc).find_by(store: store, user: user, currency: params[:currency])
- end
-
- private
-
- def incomplete_orders
- Spree::Order.incomplete.not_canceled.includes(order_includes)
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/orders/finder_helper.rb b/spree/core/app/finders/spree/orders/finder_helper.rb
deleted file mode 100644
index 53e7e85225..0000000000
--- a/spree/core/app/finders/spree/orders/finder_helper.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-module Spree
- module Orders
- module FinderHelper
- def order_includes
- {
- line_items: [
- variant: [
- :product,
- :images,
- { option_values: :option_type }
- ]
- ]
- }
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/products/find.rb b/spree/core/app/finders/spree/products/find.rb
deleted file mode 100644
index 569a7a5760..0000000000
--- a/spree/core/app/finders/spree/products/find.rb
+++ /dev/null
@@ -1,328 +0,0 @@
-module Spree
- module Products
- class Find
- def initialize(scope:, params:)
- @scope = scope
- @query = params[:q].presence&.strip
- @ids = String(params.dig(:filter, :ids)).split(',')
- @skus = String(params.dig(:filter, :skus)).split(',')
- @store = params[:store] || Spree::Store.default
- @price = map_prices(String(params.dig(:filter, :price)).split(','))
- @currency = params.dig(:filter, :currency) || params[:currency] || Spree::Store.default.default_currency
- @taxons = taxon_ids(params.dig(:filter, :taxons))
- @concat_taxons = taxon_ids(params.dig(:filter, :concat_taxons))
- @taxonomies = params.dig(:filter, :taxonomy_ids).to_h
- @name = params.dig(:filter, :name)
- @slug = params.dig(:filter, :slug)
- @options = params.dig(:filter, :options).try(:to_unsafe_hash)
- @option_value_ids = params.dig(:filter, :option_value_ids)
- @sort_by = params.dig(:sort_by)
- @deleted = params.dig(:filter, :show_deleted)
- @discontinued = params.dig(:filter, :show_discontinued)
- @in_stock = params.dig(:filter, :in_stock)
- @backorderable = params.dig(:filter, :backorderable)
- @purchasable = params.dig(:filter, :purchasable)
- @tags = params.dig(:filter, :tags).to_s.split(',').compact_blank
- @vendor_ids = params.dig(:filter, :vendor_ids)&.split(',')&.compact_blank || []
- end
-
- def execute
- products = by_ids(scope)
- products = by_skus(products)
- products = by_query(products)
- products = include_discontinued(products)
- products = by_price(products)
- products = by_currency(products)
- products = by_taxons(products)
- products = by_concat_taxons(products)
- products = by_name(products)
- products = by_slug(products)
- products = by_options(products)
- products = by_option_value_ids(products)
- products = by_tags(products)
- products = include_deleted(products)
- products = show_only_stock(products)
- products = show_only_backorderable(products)
- products = show_only_purchasable(products)
- products = by_taxonomies(products)
- products = ordered(products)
- products = by_vendor_ids(products)
-
- products.distinct
- end
-
- private
-
- attr_reader :ids, :skus, :price, :currency, :taxons, :concat_taxons, :name, :options, :option_value_ids, :scope,
- :sort_by, :deleted, :discontinued, :store, :in_stock, :backorderable, :purchasable, :tags,
- :query, :vendor_ids, :slug, :taxonomies
-
- def query?
- query.present?
- end
-
- def ids?
- ids.present?
- end
-
- def skus?
- skus.present?
- end
-
- def price?
- price.present?
- end
-
- def currency?
- currency.present?
- end
-
- def taxons?
- taxons.present?
- end
-
- def concat_taxons?
- concat_taxons.present?
- end
-
- def name?
- name.present?
- end
-
- def slug?
- slug.present?
- end
-
- def options?
- options.present?
- end
-
- def option_value_ids?
- option_value_ids.present?
- end
-
- def sort_by?
- sort_by.present?
- end
-
- def vendor_ids?
- vendor_ids.present?
- end
-
- def by_query(products)
- return products unless query?
-
- products.search(query)
- end
-
- def by_ids(products)
- return products unless ids?
-
- products.where(id: ids)
- end
-
- def by_skus(products)
- return products unless skus?
-
- products.joins(:variants).where(spree_variants: { sku: skus })
- end
-
- def by_price(products)
- return products unless price?
-
- products.price_between(price.min, price.max)
- end
-
- def by_currency(products)
- return products unless currency?
-
- products.with_currency(currency)
- end
-
- def by_taxons(products)
- return products unless taxons?
-
- products.joins(:product_categories).where(Spree::ProductCategory.table_name => { category_id: taxons })
- end
-
- def by_concat_taxons(products)
- return products unless concat_taxons?
-
- product_ids = Spree::Product.
- joins(:product_categories).
- where(Spree::ProductCategory.table_name => { category_id: concat_taxons }).
- group("#{Spree::Product.table_name}.id").
- having("COUNT(#{Spree::Product.table_name}.id) = ?", concat_taxons.length).
- ids
-
- products.where(id: product_ids)
- end
-
- def by_taxonomies(products)
- return products if taxonomies.none?
-
- taxon_groups = taxonomies.values.map { |taxonomy| taxon_ids(taxonomy[:taxon_ids].join(',')) }.compact_blank
-
- return products if taxon_groups.empty?
-
- taxonomies_products = products.joins(:product_categories).where(Spree::ProductCategory.table_name => { category_id: taxon_groups.flatten.uniq })
-
- # No need to filter if there is only one taxonomy
- return taxonomies_products if taxonomies.size == 1
-
- products.where(id: products_matching_all_taxonomies_ids(taxonomies_products.ids, taxon_groups))
- end
-
- def by_name(products)
- return products unless name?
-
- product_name = name
-
- # i18n mobility scope doesn't automatically get set for query blocks (Mobility issue #599) - set it explicitly
- products.i18n { name.matches("%#{product_name}%") }
- end
-
- def by_slug(products)
- return products unless slug.present?
-
- products.i18n.where(slug: slug)
- end
-
- def by_options(products)
- return products unless options?
-
- products_for_options = query? ? products.unscope(:order) : products
-
- products_ids = options.map { |key, value| products_for_options.with_option_value(key, value)&.ids }.compact.uniq
- products.where(id: products_ids.reduce(&:intersection))
- end
-
- def by_option_value_ids(products)
- return products unless option_value_ids?
-
- product_ids = Spree::Product.
- joins(variants: :option_values).
- where(spree_option_values: { id: option_value_ids }).
- group("#{Spree::Product.table_name}.id, #{Spree::Variant.table_name}.id").
- having('COUNT(spree_option_values.option_type_id) = ?', option_types_count(option_value_ids)).
- distinct.
- ids
-
- products.where(id: product_ids)
- end
-
- def by_tags(products)
- return products if tags.empty?
-
- products.tagged_with(tags, any: true)
- end
-
- def by_vendor_ids(products)
- products
- end
-
- def option_types_count(option_value_ids)
- Spree::OptionValue.
- where(id: option_value_ids).
- distinct.
- count(:option_type_id)
- end
-
- def ordered(products)
- return products unless sort_by?
-
- case sort_by
- when 'default', 'manual'
- if taxons?
- products.ascend_by_taxons_min_position(taxons)
- else
- products
- end
- when 'name-a-z'
- # workaround for Mobility issue #596 - explicitly select fields to avoid error when selecting distinct
- products.i18n.
- select("#{Spree::Product.table_name}.*").select(:name).order(name: :asc)
- when 'name-z-a'
- # workaround for Mobility issue #596
- products.i18n.
- select("#{Spree::Product.table_name}.*").select(:name).order(name: :desc)
- when 'newest-first'
- products.order(available_on: :desc)
- when 'oldest-first'
- products.order(available_on: :asc)
- when 'price-high-to-low'
- order_by_price(products, :desc)
- when 'price-low-to-high'
- order_by_price(products, :asc)
- when 'best-selling'
- order_by_best_selling(products)
- else
- products
- end
- end
-
- def include_deleted(products)
- deleted ? products.with_deleted : products.not_deleted
- end
-
- def include_discontinued(products)
- discontinued ? products : products.active(currency)
- end
-
- def show_only_stock(products)
- return products unless in_stock.to_s == 'true'
-
- products.in_stock
- end
-
- def show_only_backorderable(products)
- return products unless backorderable.to_s == 'true'
-
- products.backorderable
- end
-
- def show_only_purchasable(products)
- return products unless purchasable.to_s == 'true'
-
- products.in_stock_or_backorderable
- end
-
- def map_prices(prices)
- prices.map do |price|
- price == 'Infinity' ? BigDecimal::INFINITY : price.to_f
- end
- end
-
- def taxon_ids(taxons_ids)
- return if taxons_ids.nil? || taxons_ids.to_s.blank?
-
- taxons = Spree::Category.for_store(store).where(id: taxons_ids.to_s.split(','))
- taxons.map(&:cached_self_and_descendants_ids).flatten.compact.uniq.map(&:to_s)
- end
-
- def order_by_price(scope, sort_order)
- scope.
- joins(variants: :prices).
- select("#{Spree::Product.table_name}.* , min(#{Spree::Price.table_name}.amount)").
- where(Spree::Price.table_name => { currency: currency }).
- where.not(Spree::Price.table_name => { amount: nil }).
- order("min(#{Spree::Price.table_name}.amount) #{sort_order}").
- group("#{Spree::Product.table_name}.id")
- end
-
- def order_by_best_selling(scope)
- scope.by_best_selling(:desc)
- end
-
- def products_matching_all_taxonomies_ids(products_ids, taxon_groups)
- classifications = Spree::ProductCategory.grouped_category_ids_for_products(products_ids, taxon_groups.flatten)
- classifications_hash = classifications.to_h.transform_values { |taxon_ids| taxon_ids.split(',') }
-
- # Find products ids that match all taxonomies to tighten filter results
- classifications_hash.filter_map do |product_id, product_taxon_ids|
- product_id if taxon_groups.all? { |group| group.intersect?(product_taxon_ids) }
- end
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/taxons/find.rb b/spree/core/app/finders/spree/taxons/find.rb
deleted file mode 100644
index 1c1c823190..0000000000
--- a/spree/core/app/finders/spree/taxons/find.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-module Spree
- module Taxons
- class Find
- def initialize(scope:, params:)
- @scope = scope
- @ids = String(params.dig(:filter, :ids)).split(',')
- @parent = params.dig(:filter, :parent_id)
- @parent_permalink = params.dig(:filter, :parent_permalink)
- @taxonomy = params.dig(:filter, :taxonomy_id)
- @name = params.dig(:filter, :name)
- @roots = params.dig(:filter, :roots)
- end
-
- def execute
- taxons = by_ids(scope)
- taxons = by_parent(taxons)
- taxons = by_parent_permalink(taxons)
- taxons = by_taxonomy(taxons)
- taxons = by_roots(taxons)
- taxons = by_name(taxons)
-
- taxons.distinct
- end
-
- private
-
- attr_reader :ids, :parent, :parent_permalink, :taxonomy, :roots, :name, :scope
-
- def ids?
- ids.present?
- end
-
- def parent?
- parent.present?
- end
-
- def parent_permalink?
- parent_permalink.present?
- end
-
- def taxonomy?
- taxonomy.present?
- end
-
- def roots?
- roots.present?
- end
-
- def name?
- name.present?
- end
-
- def by_ids(taxons)
- return taxons unless ids?
-
- taxons.where(id: ids)
- end
-
- def by_parent(taxons)
- return taxons unless parent?
-
- taxons.where(parent_id: parent)
- end
-
- def by_parent_permalink(taxons)
- return taxons unless parent_permalink?
-
- if Spree.use_translations?
- taxons.joins(:parent).
- join_translation_table(Taxon, 'parents_spree_taxons').
- where(Taxon.translation_table_alias => { permalink: parent_permalink })
- else
- taxons.joins(:parent).where(parent: { permalink: parent_permalink })
- end
- end
-
- def by_taxonomy(taxons)
- return taxons unless taxonomy?
-
- taxons.where(taxonomy_id: taxonomy)
- end
-
- def by_roots(taxons)
- return taxons unless roots?
-
- taxons.roots
- end
-
- def by_name(taxons)
- return taxons unless name?
-
- taxon_name = name
-
- # i18n mobility scope doesn't automatically get set for query blocks (Mobility issue #599) - set it explicitly
- taxons.i18n { name.matches("%#{taxon_name}%") }
- end
- end
- end
-end
diff --git a/spree/core/app/finders/spree/variants/find.rb b/spree/core/app/finders/spree/variants/find.rb
deleted file mode 100644
index 834520c25f..0000000000
--- a/spree/core/app/finders/spree/variants/find.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-module Spree
- module Variants
- class Find
- def initialize(scope:, params:)
- @scope = scope
- @options = params.dig(:filter, :options).try(:to_unsafe_hash)
- end
-
- def execute
- variants = by_options(scope)
- variants.distinct
- end
-
- private
-
- attr_reader :scope, :options
-
- def options?
- options.present?
- end
-
- def by_options(variants)
- return variants unless options?
-
- variants_ids = options.map { |key, value| variants.with_option_value(key, value)&.ids }.compact.uniq
- variants.where(id: variants_ids.reduce(&:intersection))
- end
- end
- end
-end
diff --git a/spree/core/spec/finders/spree/addresses/find_spec.rb b/spree/core/spec/finders/spree/addresses/find_spec.rb
deleted file mode 100644
index f9331905a9..0000000000
--- a/spree/core/spec/finders/spree/addresses/find_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'spec_helper'
-
-describe Spree::Addresses::Find do
- let!(:user) { create(:user) }
- let!(:address1) { create(:address, user: user) }
- let!(:address2) { create(:address, user: user) }
- let!(:address3) { create(:address, user: user, quick_checkout: true) }
- let!(:address4) { create(:address, user: user, quick_checkout: true) }
-
- describe '#execute' do
- let(:scope) { Spree::Address.where(user: user) }
-
- context 'without any filter parameters' do
- let(:params) { {} }
-
- it 'returns all addresses without filtering' do
- result = described_class.new(
- scope: scope,
- params: params
- ).execute
-
- expect(result).to include(address1)
- expect(result).to include(address2)
- expect(result).to include(address3)
- expect(result).to include(address4)
- end
- end
-
- context 'with exclude_quick_checkout filter set to truthy value' do
- let(:params) { { filter: { exclude_quick_checkout: '1' } } }
-
- it 'returns only non-quick-checkout addresses' do
- result = described_class.new(
- scope: scope,
- params: params
- ).execute
-
- expect(result).to include(address1)
- expect(result).to include(address2)
- expect(result).not_to include(address3)
- expect(result).not_to include(address4)
- end
- end
-
- context 'with exclude_quick_checkout filter set to falsey value' do
- let(:params) { { filter: { exclude_quick_checkout: nil } } }
-
- it 'returns all addresses without filtering' do
- result = described_class.new(
- scope: scope,
- params: params
- ).execute
-
- expect(result).to include(address1)
- expect(result).to include(address2)
- expect(result).to include(address3)
- expect(result).to include(address4)
- end
- end
- end
-end
diff --git a/spree/core/spec/finders/spree/option_values/find_available_spec.rb b/spree/core/spec/finders/spree/option_values/find_available_spec.rb
deleted file mode 100644
index 666186f6ca..0000000000
--- a/spree/core/spec/finders/spree/option_values/find_available_spec.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-require 'spec_helper'
-
-module Spree
- RSpec.describe OptionValues::FindAvailable do
- let(:finder) { described_class.new }
-
- let!(:size) { Spree::OptionType.find_by(name: 'size') || create(:option_type, :size) }
- let!(:s_size) { create(:option_value, option_type: size, name: 's') }
- let!(:m_size) { create(:option_value, option_type: size, name: 'm') }
- let!(:xl_size) { create(:option_value, option_type: size, name: 'xl') }
-
- let!(:color) { create(:option_type, :color) }
- let!(:red_color) { create(:option_value, option_type: color, name: 'red') }
- let!(:green_color) { create(:option_value, option_type: color, name: 'green') }
- let!(:blue_color) { create(:option_value, option_type: color, name: 'blue') }
-
- let!(:length) { create(:option_type, filterable: false) }
- let!(:mini_length) { create(:option_value, option_type: length) }
-
- before do
- product_1 = create(:product, option_types: [color, size])
- create(:variant, option_values: [s_size, green_color], product: product_1)
-
- product_2 = create(:product, option_types: [color, size])
- create(:variant, option_values: [red_color, m_size], product: product_2)
-
- product_3 = create(:product, option_types: [size, length])
- create(:variant, option_values: [s_size, mini_length], product: product_3)
- end
-
- describe '#execute' do
- subject(:available_options) { finder.execute }
-
- it 'finds available Option Values' do
- expect(available_options).to contain_exactly(
- s_size, m_size,
- red_color, green_color
- )
- end
-
- context 'when given a predefined scope' do
- let(:finder) { described_class.new(scope: scope) }
- let(:scope) { OptionValue.where(id: [s_size, green_color, mini_length]) }
-
- it 'finds available Option Values with respect to a predefined scope' do
- expect(available_options).to contain_exactly(s_size, green_color)
- end
- end
-
- context 'when given a predefined products scope' do
- let(:finder) { described_class.new(products_scope: products_scope) }
- let(:products_scope) { Product.where(id: [product_1, product_2, product_3]) }
-
- let(:product_1) { create(:product, option_types: [size]) }
- let(:product_2) { create(:product, option_types: [color]) }
- let(:product_3) { create(:product, option_types: [size, color, length]) }
-
- before do
- create(:variant, option_values: [xl_size], product: product_1)
- create(:variant, option_values: [red_color, blue_color], product: product_2)
- create(:variant, option_values: [m_size, red_color, mini_length], product: product_3)
- end
-
- it 'finds filterable Option Values with respect to a predefined Products scope' do
- expect(available_options).to contain_exactly(
- m_size, xl_size,
- red_color, blue_color
- )
- end
- end
-
- context 'ordering' do
- let!(:white_color) { create(:option_value, option_type: color, name: 'white') }
- let!(:black_color) { create(:option_value, option_type: color, name: 'black') }
- let!(:material) { create(:option_type, name: 'material', presentation: 'Material') }
- let!(:wool) { create(:option_value, option_type: material, name: 'wool') }
- let!(:silk) { create(:option_value, option_type: material, name: 'silk') }
-
- before do
- material.update_column(:position, 0)
- silk.update_column(:position, 1)
- wool.update_column(:position, 2)
-
- color.update_column(:position, 1)
- white_color.update_column(:position, 0)
- black_color.update_column(:position, 10)
- green_color.update_column(:position, 20)
-
- size.update_column(:position, 2)
-
- product_4 = create(:product, option_types: [color, material, size])
- create(:variant, option_values: [white_color, black_color, wool, silk], product: product_4)
- end
-
- it 'orders the option values by option type position and option value position' do
- positions = available_options.map { |ov| [ov.option_type.position, ov.position] }
- expect(positions).to eq(positions.sort_by { |e| [e.first, e.second] })
- end
- end
- end
- end
-end
diff --git a/spree/core/spec/finders/spree/products/find_spec.rb b/spree/core/spec/finders/spree/products/find_spec.rb
deleted file mode 100644
index f5050cac5b..0000000000
--- a/spree/core/spec/finders/spree/products/find_spec.rb
+++ /dev/null
@@ -1,514 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe Products::Find do
- let(:store) { @default_store }
- let!(:product) { create(:product, price: 15.99) }
- let!(:product_2) { create(:product, discontinue_on: Time.current + 1.day, price: 23.99) }
- let!(:product_3) { create(:product) }
- let!(:option_value) { create(:option_value) }
- let!(:deleted_product) { create(:product, deleted_at: Time.current - 1.day) }
- let!(:discontinued_product) { create(:product, status: 'archived') }
- let!(:in_stock_product) { create(:product_in_stock) }
- let!(:not_backorderable_product) { create(:product_in_stock, :without_backorder) }
-
- context 'include discontinued' do
- it 'returns products with discontinued' do
- params = {
- filter: {
- ids: '',
- skus: '',
- price: '',
- currency: 'USD',
- taxons: '',
- concat_taxons: '',
- name: false,
- options: false,
- show_deleted: false,
- show_discontinued: true,
- in_stock: false
- }
- }
-
- expect(
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- ).to contain_exactly(product, product_2, product_3, discontinued_product, in_stock_product, not_backorderable_product)
- end
- end
-
- context 'include deleted' do
- it 'returns products with deleted' do
- params = {
- filter: {
- ids: '',
- skus: '',
- price: '',
- taxons: '',
- currency: 'USD',
- concat_taxons: '',
- name: false,
- options: false,
- show_deleted: true,
- show_discontinued: false,
- in_stock: false
- }
- }
-
- expect(
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- ).to contain_exactly(product, product_2, product_3, deleted_product, in_stock_product, not_backorderable_product)
- end
- end
-
- context 'in stock' do
- it 'returns products with variants in stock or backorderable' do
- params = {
- filter: {
- ids: '',
- skus: '',
- price: '',
- taxons: '',
- currency: 'USD',
- concat_taxons: '',
- name: false,
- options: false,
- show_deleted: false,
- show_discontinued: false,
- in_stock: true
- }
- }
-
- expect(
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- ).to contain_exactly(product, product_2, product_3, in_stock_product, not_backorderable_product)
- end
- end
-
- context 'backorderable' do
- it 'returns products with backorderable variants' do
- params = {
- filter: {
- ids: '',
- skus: '',
- price: '',
- taxons: '',
- currency: 'USD',
- concat_taxons: '',
- name: false,
- options: false,
- show_deleted: false,
- show_discontinued: false,
- in_stock: false,
- backorderable: true
- }
- }
-
- expect(
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- ).to contain_exactly(product, product_2, product_3, in_stock_product) # No not_backorderable_product.
- end
- end
-
- context 'purchasable' do
- it 'returns products with purchasable variants' do
- params = {
- filter: {
- ids: '',
- skus: '',
- price: '',
- taxons: '',
- currency: 'USD',
- concat_taxons: '',
- name: false,
- options: false,
- show_deleted: false,
- show_discontinued: false,
- in_stock: false,
- backorderable: false,
- purchasable: true
- }
- }
-
- expect(
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- ).to contain_exactly(product, product_2, product_3, in_stock_product, not_backorderable_product)
- end
- end
-
- context 'exclude discontinued and deleted' do
- it 'returns not discontinued and not deleted products' do
- params = {
- filter: {
- ids: '',
- skus: '',
- price: '',
- currency: 'USD',
- taxons: '',
- concat_taxons: '',
- name: false,
- options: false,
- show_deleted: false,
- show_discontinued: false,
- in_stock: false
- }
- }
-
- expect(
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- ).to contain_exactly(product, product_2, product_3, in_stock_product, not_backorderable_product)
- end
- end
-
- describe 'filter by options and option values' do
- subject(:products) do
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- end
-
- let(:option_type_1) { create :option_type, name: 'size' }
- let(:option_type_2) { create :option_type, name: 'state' }
-
- let(:option_value_1_1) { create :option_value, option_type: option_type_1, name: 's', presentation: 'S' }
- let(:option_value_1_2) { create :option_value, option_type: option_type_1, name: 'm', presentation: 'M' }
- let(:option_value_2_1) { create :option_value, option_type: option_type_2, name: 'old', presentation: 'Old' }
- let(:option_value_2_2) { create :option_value, option_type: option_type_2, name: 'new', presentation: 'New' }
-
- let(:product_1) { create :product, option_types: [option_type_1, option_type_2] }
- let(:product_2) { create :product, option_types: [option_type_1, option_type_2] }
- let(:product_3) { create :product, option_types: [option_type_1, option_type_2] }
-
- let!(:variant_1) { create :variant, product: product_1, option_values: [option_value_1_1, option_value_2_1] }
- let!(:variant_2) { create :variant, product: product_2, option_values: [option_value_1_2, option_value_2_2] }
- let!(:variant_3) { create :variant, product: product_3, option_values: [option_value_1_1, option_value_2_2] }
-
- context 'for options' do
- let(:params) do
- {
- filter: {
- options: ActionController::Parameters.new(
- size: 's',
- state: 'old'
- )
- }
- }
- end
-
- it 'returns products matching all given options' do
- expect(products).to contain_exactly(product_1)
- end
- end
-
- context 'for option values' do
- let(:option_value_ids) { [] }
- let(:params) do
- {
- filter: {
- option_value_ids: option_value_ids
- }
- }
- end
-
- context 'filtering by one option' do
- let(:option_value_ids) { [option_value_1_1.id] }
-
- it 'returns products with proper option values' do
- expect(products).to match_array([product_1, product_3])
- end
- end
-
- context 'filtering by several options' do
- let(:option_value_ids) { [option_value_1_1.id, option_value_2_2.id] }
-
- it 'returns products that have both options' do
- expect(products).to match_array([product_3])
- end
- end
- end
- end
-
- describe 'filter by taxons' do
- subject(:products) do
- described_class.new(
- scope: scope,
- params: params
- ).execute
- end
-
- let!(:scope) { Spree::Product.all }
- let(:parent_taxon) { child_taxon.parent }
- let(:child_taxon) { create(:taxon) }
-
- context 'one taxon is requested in params' do
- let(:params) { { store: store, filter: { taxons: parent_taxon.id } } }
-
- shared_examples 'returns distinct products associated both to self and descendants' do
- it { expect(products).to match_array [product, product_2] }
- end
-
- before do
- parent_taxon.products << product
- child_taxon.products << product_2
- end
-
- it_behaves_like 'returns distinct products associated both to self and descendants'
-
- context 'when product is already related to both taxons' do
- before { parent_taxon.products << product_2 }
-
- it_behaves_like 'returns distinct products associated both to self and descendants'
- end
- end
-
- context 'multiple taxons are requested' do
- let(:params) { { store: store, filter: { taxons: "#{taxon.id},#{taxon_2.id}" } } }
- let(:taxon) { create(:taxon) }
- let(:taxon_2) { create(:taxon) }
-
- before do
- taxon.products << product
- taxon_2.products << product_2
- end
-
- it { expect(products).to match_array [product, product_2] }
- end
-
- context 'multiple taxons + 1 concat_taxons are requested' do
- let(:params) { { store: store, filter: { taxons: "#{taxon.id},#{taxon_2.id}", concat_taxons: taxon_3.id.to_s } } }
- let(:taxon) { create(:taxon) }
- let(:taxon_2) { create(:taxon) }
- let(:taxon_3) { create(:taxon) }
-
- before do
- taxon.products << product
- taxon_2.products << product_2
- taxon_3.products << product_2
- taxon_3.products << product_3
- end
-
- it { expect(products).to match_array [product_2] }
- end
-
- context 'only multiple concat_taxons are requested' do
- let(:params) { { store: store, filter: { concat_taxons: "#{taxon_2.id},#{taxon_3.id}" } } }
- let(:taxon) { create(:taxon) }
- let(:taxon_2) { create(:taxon) }
- let(:taxon_3) { create(:taxon) }
-
- before do
- taxon.products << product
- taxon_2.products << product_2
- taxon_3.products << product_2
- taxon_3.products << product_3
- end
-
- it { expect(products).to match_array [product_2] }
- end
-
- context 'only one concat_taxons is requested' do
- let(:params) { { store: store, filter: { concat_taxons: taxon_3.id.to_s } } }
- let(:taxon) { create(:taxon) }
- let(:taxon_2) { create(:taxon) }
- let(:taxon_3) { create(:taxon) }
-
- before do
- taxon.products << product
- taxon_2.products << product_2
- taxon_3.products << product_2
- taxon_3.products << product_3
- end
-
- it { expect(products).to match_array [product_2, product_3] }
- end
- end
-
- describe 'filter by prices' do
- subject(:products) do
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- end
-
- let(:params) { { filter: { price: price_param } } }
-
- context 'for a price less than 20' do
- let(:price_param) { '0,20' }
-
- it { is_expected.to contain_exactly(product, product_3, in_stock_product, not_backorderable_product) }
- end
-
- context 'for a price between 16 and 24' do
- let(:price_param) { '16,24' }
-
- it { is_expected.to contain_exactly(product_2, product_3, in_stock_product, not_backorderable_product) }
- end
-
- context 'for a price more than 23' do
- let(:price_param) { '23,Infinity' }
-
- it do
- is_expected.to contain_exactly(product_2)
- end
- end
- end
-
- context 'ordered' do
- context 'default' do
- subject(:products) do
- described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
- end
-
- context 'when not filtering by taxons' do
- let(:params) { { sort_by: 'default' } }
-
- it 'returns products in default order' do
- expect(products.ids).to match_array Spree::Product.available.ids
- end
- end
-
- context 'when filtering by taxons' do
- let(:params) do
- { store: store, sort_by: 'default', filter: { taxons: taxonomy.root.id } }
- end
-
- let(:taxonomy) { create(:taxonomy) }
- let(:child_taxon_1) { create(:taxon, taxonomy: taxonomy) }
- let(:child_taxon_2) { create(:taxon, taxonomy: taxonomy) }
-
- before do
- product.taxons << child_taxon_1
- product_2.taxons << child_taxon_1
- product_3.taxons << child_taxon_2
-
- # swap products positions
- product.classifications.find_by(category: child_taxon_1).update(position: 3)
- product_3.classifications.find_by(category: child_taxon_2).update(position: 2)
- product_2.classifications.find_by(category: child_taxon_1).update(position: 1)
- end
-
- it 'returns products ordered by associated taxon position' do
- expect(products).to eq [product_2, product_3, product]
- end
- end
- end
-
- it 'returns products in newest-first order' do
- params = {
- sort_by: 'newest-first'
- }
-
- product_ids = described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute.map(&:id)
-
- expect(product_ids).to eq Spree::Product.available.order(make_active_at: :desc).map(&:id)
- end
-
- it 'returns products in price-high-to-low order' do
- params = {
- sort_by: 'price-high-to-low'
- }
-
- products = described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute.to_a
-
- expect(products).to match_array([product_2, product_3, product, in_stock_product, not_backorderable_product])
- end
-
- it 'returns products in price-low-to-high order' do
- params = {
- sort_by: 'price-low-to-high'
- }
-
- products = described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
-
- expect(products).to match_array([product, product_3, product_2, in_stock_product, not_backorderable_product])
- end
-
- it 'returns products in name-a-z order' do
- params = {
- sort_by: 'name-a-z'
- }
-
- products = described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
-
- expect(products).to match_array([product, product_2, product_3, in_stock_product, not_backorderable_product])
- end
-
- it 'returns products in name-z-a order' do
- params = {
- sort_by: 'name-z-a'
- }
-
- products = described_class.new(
- scope: Spree::Product.all,
- params: params
- ).execute
-
- expect(products).to match_array([product_3, product_2, product, in_stock_product, not_backorderable_product])
- end
- end
-
- describe 'filter by slug' do
- subject(:products) { described_class.new(scope: Spree::Product.all, params: params).execute }
-
- let(:params) { { filter: { slug: 'slug-1' } } }
-
- before { product.update(slug: 'slug-1') }
-
- context 'when product with given slug is present' do
- it 'returns products with the given slug' do
- expect(products).to contain_exactly(product)
- end
- end
-
- context 'when product with given slug is not present' do
- let(:params) { { filter: { slug: 'slug-2' } } }
-
- it 'returns all products' do
- expect(products).to be_empty
- end
- end
-
- context 'when slug is not present' do
- let(:params) { { filter: { slug: '' } } }
-
- it 'returns all products' do
- expect(products).to contain_exactly(product, product_2, product_3, in_stock_product, not_backorderable_product)
- end
- end
- end
- end
-end
diff --git a/spree/core/spec/finders/spree/taxons/find_spec.rb b/spree/core/spec/finders/spree/taxons/find_spec.rb
deleted file mode 100644
index 69bd1df662..0000000000
--- a/spree/core/spec/finders/spree/taxons/find_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe Taxons::Find do
- let!(:taxon_shirts) { create(:taxon, name: 'Shirts') }
- let!(:taxon_shorts) { create(:taxon, name: 'Shorts') }
- let!(:taxon_shoes) { create(:taxon, name: 'Shoes') }
-
- describe 'filtering by taxon property' do
- subject do
- described_class.new(
- scope: Spree::Category.all,
- params: params
- ).execute
- end
-
- context 'when filtering by taxon name' do
- let(:params) { { filter: { 'name': 'Shirts' } } }
-
- it 'returns taxon with matching name' do
- expect(subject).to contain_exactly(taxon_shirts)
- end
- end
-
- end
-
- end
-end