Sha256: 00caec50066be390f026a357cb9e87b4603c1cccc86ddc5edb7339726acda255

Contents?: true

Size: 1.83 KB

Versions: 28

Compression:

Stored size: 1.83 KB

Contents

module Workarea
  module Search
    class StorefrontSearch
      class Response
        Trace = Struct.new(:params, :query, :reset_by)

        attr_accessor :template, :message, :redirect, :params, :query,
          :customization, :trace

        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

        def redirect?
          @redirect.present?
        end

        # Reset the parameters and resulting query to match the new parameters
        # passed in. Used when correcting spelling, or auto filtering results.
        #
        # @param [Hash]
        #
        def reset!(params, by: nil)
          @params = params
          @query = Search::ProductSearch.new(params.merge(rules: product_rules))
          @trace << Trace.new(@params, @query, by)
        end

        def query_string
          params[:q].strip
        end

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

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

        def total
          query.total
        end

        def query_suggestions
          @query.query_suggestions
        end

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

        private

        def terms_facets
          Search::Storefront::Product.current_terms_facets
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.6 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.5 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.4 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.3 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.2 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.1 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.0 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/search/storefront_search/response.rb