Class: Workarea::Storefront::SearchesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/workarea/storefront/searches_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_layout, #current_user_info, #health_check, #layout_content

Methods included from OrderLookup

#lookup_order, #lookup_order=

Methods included from UserActivity

#current_user_activity_id, #user_activity

Methods included from CurrentCheckout

#clear_current_order, #completed_order, #completed_order=, #current_checkout, #current_order, #current_order=, #current_shipping, #current_shippings

Methods included from HttpCaching

#cache_page, #http_caching?

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/workarea/storefront/searches_controller.rb', line 6

def index
  render nothing: true and return if search_query.blank?
  autocomplete_params = params.permit(:q)

  search = Search::SearchSuggestions.new(autocomplete_params)

  @results = search.results.map do |result|
    SearchSuggestionViewModel.new(result).to_h
  end
end

#showObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/workarea/storefront/searches_controller.rb', line 17

def show
  if search_query.blank?
    flash[:error] = t('workarea.storefront.flash_messages.no_search_query')
    redirect_back fallback_location: root_path
    return
  end

  response = Search::StorefrontSearch.new(params.to_unsafe_h).response
  handle_search_response(response)
end