Class: Workarea::Storefront::RecommendationsViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
Enumerable
Defined in:
app/view_models/workarea/storefront/recommendations_view_model.rb

Instance Method Summary collapse

Instance Method Details



22
23
24
25
26
27
28
# File 'app/view_models/workarea/storefront/recommendations_view_model.rb', line 22

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

#product_idsObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'app/view_models/workarea/storefront/recommendations_view_model.rb', line 30

def product_ids
  raise NotImplementedError
end

#productsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/view_models/workarea/storefront/recommendations_view_model.rb', line 7

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

#result_countObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'app/view_models/workarea/storefront/recommendations_view_model.rb', line 34

def result_count
  raise NotImplementedError
end