Class: Workarea::Search::Admin::CatalogCategory
Instance Method Summary
collapse
Methods included from Releasable
#status
#created_at, find_for_model, for, #id, jump_to, #jump_to_param, #jump_to_route_helper, #jump_to_search_text, #keywords, #name, #releasable?, #sanitized_keywords, #should_be_indexed?, #status, #type, #updated_at
all, #as_bulk_document, current_index_prefix, #destroy, #initialize, #save
Instance Method Details
#as_document ⇒ Object
57
58
59
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 57
def as_document
super.merge(breadcrumbs: breadcrumbs)
end
|
#displayable_products ⇒ Object
23
24
25
26
27
28
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 23
def displayable_products
view_model = Workarea::Storefront::CategoryViewModel.wrap(model)
return [] unless view_model.respond_to?(:products)
view_model.products
end
|
#facets ⇒ Object
19
20
21
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 19
def facets
super.merge(issues: issues)
end
|
#has_products? ⇒ Boolean
This funny business exists because displayable_products depends on product browse indexing, which will be delayed (async).
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 33
def has_products?
if displayable_products.blank? && model.product_ids.present?
products = Catalog::Product.any_in(id: model.product_ids.take(100))
products.any? do |product|
search_model = Storefront::Product.new(product)
product.active? &&
search_model.variant_count > 0 &&
search_model.inventory.available_to_sell > 0
end
else
displayable_products.present?
end
end
|
#issues ⇒ Object
50
51
52
53
54
55
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 50
def issues
result = []
result << I18n.t('workarea.alerts.issues.no_displayable_products') unless has_products?
result << I18n.t('workarea.alerts.issues.not_in_taxonomy') unless model.taxon.present?
result
end
|
#jump_to_position ⇒ Object
15
16
17
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 15
def jump_to_position
4
end
|
#jump_to_text ⇒ Object
11
12
13
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 11
def jump_to_text
model.name
end
|
#search_text ⇒ Object
7
8
9
|
# File 'app/models/workarea/search/admin/catalog_category.rb', line 7
def search_text
"category #{model.name}"
end
|