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.27 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.26 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.25 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.23 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.22 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.21 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.20 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.19 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.18 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.17 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.16 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.15 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.14 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.13 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.12 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.11 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.10 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.9 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.8 app/queries/workarea/search/storefront_search/response.rb
workarea-core-3.5.7 app/queries/workarea/search/storefront_search/response.rb