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



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

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

#product_idsObject

Raises:

  • (NotImplementedError)


28
29
30
# File 'app/view_models/workarea/storefront/recommendations_view_model.rb', line 28

def product_ids
  raise NotImplementedError
end

#productsObject



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

def products
  @products ||=
    begin
      results = find_displayable_products(product_ids)

      if results.size < result_count
        results.push(*find_displayable_products(popular_product_ids))
      end

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

#result_countObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'app/view_models/workarea/storefront/recommendations_view_model.rb', line 32

def result_count
  raise NotImplementedError
end