Class: Workarea::Storefront::ContentBlocks::CategorySummaryViewModel

Inherits:
Workarea::Storefront::ContentBlockViewModel show all
Includes:
ProductBrowsing
Defined in:
app/view_models/workarea/storefront/content_blocks/category_summary_view_model.rb

Instance Method Summary collapse

Methods included from ProductBrowsing

#facets, #filters, #has_filters?, #product_browse_cache_key

Methods included from Pagination

#first_page?, #last_page?, #next_page, #prev_page, #search_query, #second_page?, #total_pages

Methods inherited from Workarea::Storefront::ContentBlockViewModel

#asset_alt_text, #assets, #find_asset, #partial, #series, wrap

Instance Method Details

#categoryObject



14
15
16
17
# File 'app/view_models/workarea/storefront/content_blocks/category_summary_view_model.rb', line 14

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

#localsObject



7
8
9
10
11
12
# File 'app/view_models/workarea/storefront/content_blocks/category_summary_view_model.rb', line 7

def locals
  super.merge(
    category: category,
    products: products
  )
end

#product_countObject



26
27
28
# File 'app/view_models/workarea/storefront/content_blocks/category_summary_view_model.rb', line 26

def product_count
  Workarea.config.category_summary_product_count
end

#productsObject



19
20
21
22
23
24
# File 'app/view_models/workarea/storefront/content_blocks/category_summary_view_model.rb', line 19

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