Sha256: f87f9c0f906bac0b77a360742237f8e9d908185f9034f12b0f6cb523dd81d7ae

Contents?: true

Size: 927 Bytes

Versions: 34

Compression:

Stored size: 927 Bytes

Contents

module Workarea
  module Storefront
    class RecommendationsViewModel < ApplicationViewModel
      include Enumerable
      delegate :each, :size, :length, to: :products

      def products
        @products ||=
          begin
            results = Catalog::Product.active.purchasable.find_ordered(product_ids)

            if results.size < result_count
              results.push(
                *Catalog::Product.active.purchasable.find_ordered(popular_product_ids)
              )
            end

            ProductViewModel.wrap(results.uniq).take(result_count)
          end
      end

      def popular_product_ids
        Insights::TopProducts
          .current
          .results
          .map { |r| r['product_id'] }
          .take(result_count)
      end

      def product_ids
        raise NotImplementedError
      end

      def result_count
        raise NotImplementedError
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-storefront-3.4.25 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.24 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.23 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.22 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.21 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.20 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.19 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.18 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.17 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.16 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.15 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.14 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.13 app/view_models/workarea/storefront/recommendations_view_model.rb
workarea-storefront-3.4.12 app/view_models/workarea/storefront/recommendations_view_model.rb