Class: Spree::Products::Find

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree/products/find.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope:, params:, current_currency:) ⇒ Find

Returns a new instance of Find.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/finders/spree/products/find.rb', line 4

def initialize(scope:, params:, current_currency:)
  @scope = scope

  @ids          = String(params.dig(:filter, :ids)).split(',')
  @skus         = String(params.dig(:filter, :skus)).split(',')
  @price        = String(params.dig(:filter, :price)).split(',')
  @currency     = params[:currency] || current_currency
  @taxons       = String(params.dig(:filter, :taxons)).split(',')
  @name         = params.dig(:filter, :name)
  @options      = params.dig(:filter, :options).try(:to_unsafe_hash)
  @deleted      = params.dig(:filter, :show_deleted)
  @discontinued = params.dig(:filter, :show_discontinued)
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/finders/spree/products/find.rb', line 18

def execute
  products = by_ids(scope)
  products = by_skus(products)
  products = by_price(products)
  products = by_taxons(products)
  products = by_name(products)
  products = by_options(products)
  products = include_deleted(products)
  products = include_discontinued(products)

  products
end