Sha256: 63546aa88a2ee27dfce24e79c76f0a409a8142b311f301ccda1b1200a470f59b

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Workarea
  module Storefront
    module ContentBlocks
      class TaxonomyWithCategoryViewModel < ContentBlockViewModel
        include TaxonLookup

        def category
          return @category if defined?(@category)
          @category = Catalog::Category.where(id: data["category"]).first
        end

        def products
          return [] unless category.present?
          @products ||= search.results.take(product_count).map do |result|
            ProductViewModel.wrap(result[:model])
          end
        end

        def product_count
          Workarea.config.navigation_category_summary_product_count
        end

        def product_width_class
          "grid__cell--#{100 / products.count}-at-medium"
        end

        private

          def search
            @search ||= Search::CategoryBrowse.new(
              category_ids: [category.id],
              rules: category.product_rules,
              page: 1,
              sort: sorts
            )
          end

          def sorts
            @current_sorts ||=
              if category.featured_products?
                [:featured, category.default_sort]
              else
                [category.default_sort]
              end
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-one_theme-1.3.1 app/view_models/workarea/storefront/content_blocks/taxonomy_with_category_view_model.rb
workarea-one_theme-1.3.0 app/view_models/workarea/storefront/content_blocks/taxonomy_with_category_view_model.rb