Class: Workarea::Storefront::SearchViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
Pagination, ProductBrowsing, SearchContent, SearchCustomizationContent
Defined in:
app/view_models/workarea/storefront/search_view_model.rb

Instance Method Summary collapse

Methods included from SearchCustomizationContent

#customization, #customization_content_blocks_for

Methods included from SearchContent

#content_lookup, #no_results_content, #results_content

Methods included from DisplayContent

#browser_title, #content, #content_blocks, #content_blocks_for, #meta_description, #open_graph_asset

Methods included from ProductBrowsing

#facets, #filters, #has_filters?, #product_browse_cache_key

Methods included from Pagination

#first_page?, #last_page?, #next_page, #prev_page, #second_page?, #total_pages

Instance Method Details

#product_breadcrumb_paramsObject



27
28
29
# File 'app/view_models/workarea/storefront/search_view_model.rb', line 27

def product_breadcrumb_params
  { via: Navigation::SearchResults.new(search_query.params).to_gid_param }
end

#productsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/view_models/workarea/storefront/search_view_model.rb', line 13

def products
  @products ||=
    begin
      view_models = query.results.map do |result|
        ProductViewModel.wrap(
          result[:model],
          result.merge(options).merge(product_breadcrumb_params).merge(params)
        )
      end

      PagedArray.from(view_models, page, per_page, total)
    end
end

#query_suggestionsObject



31
32
33
34
35
36
37
38
39
# File 'app/view_models/workarea/storefront/search_view_model.rb', line 31

def query_suggestions
  @query_suggestions ||=
    begin
      all = Recommendation::Searches.find(options[:q]) +
        model.query_suggestions

      all.uniq.take(3)
    end
end

#search_queryObject



9
10
11
# File 'app/view_models/workarea/storefront/search_view_model.rb', line 9

def search_query
  query
end

#sortObject



41
42
43
# File 'app/view_models/workarea/storefront/search_view_model.rb', line 41

def sort
  query.class.available_sorts.find(options[:sort])
end

#sortsObject



45
46
47
# File 'app/view_models/workarea/storefront/search_view_model.rb', line 45

def sorts
  query.class.available_sorts.map { |s| [s.name, s.slug] }
end