Sha256: a8a27d7f2707d63503c9f9a6631b4d771f6c70e1854c58806bb6dc35aabd9799

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

module Workarea
  module Storefront
    class SearchViewModel < ApplicationViewModel
      include Pagination
      include ProductBrowsing
      include SearchContent
      include SearchCustomizationContent

      def search_query
        query
      end

      def products
        @products ||=
          begin
            view_models = query.results.map do |result|
              ProductViewModel.wrap(
                result[:model],
                result.merge(options).merge(product_breadcrumb_params).merge(params)
              )
            end

            PagedArray.from(view_models, page, per_page, total)
          end
      end

      def product_breadcrumb_params
        { via: Navigation::SearchResults.new(search_query.params).to_gid_param }
      end

      def query_suggestions
        @query_suggestions ||=
          begin
            all = Recommendation::Searches.find(options[:q]) +
              model.query_suggestions

            all.take(3)
          end
      end

      def sort
        query.class.available_sorts.find(options[:sort])
      end

      def sorts
        query.class.available_sorts.map { |s| [s.name, s.slug] }
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
workarea-storefront-3.5.5 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.27 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.4 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.26 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.3 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.25 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.2 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.24 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.1 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.23 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.22 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.0 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.21 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.0.beta.1 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.20 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.19 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.18 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.17 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.16 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.15 app/view_models/workarea/storefront/search_view_model.rb