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.15 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.36 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.14 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.35 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.13 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.34 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.12 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.33 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.11 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.10 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.32 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.9 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.31 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.8 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.30 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.7 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.29 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.5.6 app/view_models/workarea/storefront/search_view_model.rb
workarea-storefront-3.4.28 app/view_models/workarea/storefront/search_view_model.rb