Class: Spree::Api::V3::FiltersAggregator

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree/api/v3/filters_aggregator.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope:, currency:, category: nil, option_value_ids: [], scope_before_options: nil) ⇒ FiltersAggregator

Returns a new instance of FiltersAggregator.

Parameters:

  • scope (ActiveRecord::Relation)

    Base product scope (fully filtered, including option values)

  • currency (String)

    Currency for price range

  • category (Spree::Category, nil) (defaults to: nil)

    Optional category for default_sort and category filtering context

  • option_value_ids (Array<String>) (defaults to: [])

    Currently selected option value prefixed IDs (for disjunctive facet counts)

  • scope_before_options (ActiveRecord::Relation) (defaults to: nil)

    Scope before option value filters (for disjunctive counts)



10
11
12
13
14
15
16
# File 'app/services/spree/api/v3/filters_aggregator.rb', line 10

def initialize(scope:, currency:, category: nil, option_value_ids: [], scope_before_options: nil)
  @scope = scope
  @currency = currency
  @category = category
  @option_value_ids = option_value_ids
  @scope_before_options = scope_before_options || scope
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
# File 'app/services/spree/api/v3/filters_aggregator.rb', line 18

def call
  {
    filters: build_filters,
    sort_options: sort_options,
    default_sort: to_api_sort(@category&.sort_order || 'manual'),
    total_count: @scope.distinct.count
  }
end