Class: Workarea::Search::StorefrontSearch::Response

Inherits:
Object
  • Object
show all
Defined in:
app/queries/workarea/search/storefront_search/response.rb

Defined Under Namespace

Classes: Trace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/queries/workarea/search/storefront_search/response.rb', line 10

def initialize(options = {})
  @template = options.fetch(:template, 'show')
  @message = options[:message]
  @redirect = options[:redirect]

  @params = options.fetch(:params, {})
  @params[:terms_facets] = terms_facets
  @params[:range_facets] = Settings.current.range_facets
  @original_params = @params.deep_dup

  @customization = options[:customization]
  @trace = []

  reset!(@params)
end

Instance Attribute Details

#customizationObject

Returns the value of attribute customization.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def customization
  @customization
end

#messageObject

Returns the value of attribute message.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def message
  @message
end

#paramsObject

Returns the value of attribute params.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def params
  @params
end

#queryObject

Returns the value of attribute query.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def query
  @query
end

#redirectObject

Returns the value of attribute redirect.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def redirect
  @redirect
end

#templateObject

Returns the value of attribute template.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def template
  @template
end

#traceObject

Returns the value of attribute trace.



7
8
9
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7

def trace
  @trace
end

Instance Method Details

#autoselected_filter?(name) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/queries/workarea/search/storefront_search/response.rb', line 49

def autoselected_filter?(name)
  params[name].present? && @original_params[name].blank?
end

#has_filters?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/queries/workarea/search/storefront_search/response.rb', line 45

def has_filters?
  query.facets.any?(&:selected?)
end

#product_rulesObject



61
62
63
64
# File 'app/queries/workarea/search/storefront_search/response.rb', line 61

def product_rules
  return [] if customization.blank?
  customization.product_rules.usable
end

#query_stringObject



41
42
43
# File 'app/queries/workarea/search/storefront_search/response.rb', line 41

def query_string
  params[:q].strip
end

#query_suggestionsObject



57
58
59
# File 'app/queries/workarea/search/storefront_search/response.rb', line 57

def query_suggestions
  @query.query_suggestions
end

#redirect?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/queries/workarea/search/storefront_search/response.rb', line 26

def redirect?
  @redirect.present?
end

#reset!(params, by: nil) ⇒ Object

Reset the parameters and resulting query to match the new parameters passed in. Used when correcting spelling, or auto filtering results.

Parameters:

  • (Hash)


35
36
37
38
39
# File 'app/queries/workarea/search/storefront_search/response.rb', line 35

def reset!(params, by: nil)
  @params = params
  @query = Search::ProductSearch.new(params.merge(rules: product_rules))
  @trace << Trace.new(@params, @query, by)
end

#totalObject



53
54
55
# File 'app/queries/workarea/search/storefront_search/response.rb', line 53

def total
  query.total
end