Sha256: bc940c30f650f584601454380e2c16d6df7dd19e45a20054e61c5f683b1ca5d0

Contents?: true

Size: 1.17 KB

Versions: 39

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.uniq.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

39 entries across 39 versions & 1 rubygems

Version Path
workarea-storefront-3.5.27 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.26 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.45 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.25 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.23 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.44 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.22 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.43 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.21 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.42 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.20 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.41 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.19 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.40 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.18 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.39 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.17 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.38 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.16 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.37 app/view_models/workarea/storefront/search_view_model.rb