Sha256: b63b092c4f918bcb6f667a80956bb1e6a28dd88dc160b5bcbd827065cfae0a76

Contents?: true

Size: 970 Bytes

Versions: 28

Compression:

Stored size: 970 Bytes

Contents

module Workarea
  module Storefront
    class SearchesController < Storefront::ApplicationController
      before_action :cache_page

      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

      private

      def search_query
        QueryString.new(params[:q]).sanitized
      end

      def handle_search_response(response)
        redirect_to response.redirect and return if response.redirect?

        set_search(response)
        status = response.template == 'no_results' ? :not_found : :ok
        render response.template, status: status
      end

      def set_search(response)
        @search = SearchViewModel.new(response, view_model_options)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-storefront-3.5.27 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.26 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.25 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.23 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.22 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.21 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.20 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.19 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.18 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.17 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.16 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.15 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.14 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.13 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.12 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.11 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.10 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.9 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.8 app/controllers/workarea/storefront/searches_controller.rb
workarea-storefront-3.5.7 app/controllers/workarea/storefront/searches_controller.rb