Class: Workarea::Search::Storefront

Inherits:
Object
  • Object
show all
Includes:
Elasticsearch::Document
Defined in:
app/models/workarea/search/storefront.rb,
app/models/workarea/search/storefront/page.rb,
app/models/workarea/search/storefront/search.rb,
app/models/workarea/search/storefront/product.rb,
app/models/workarea/search/storefront/category.rb,
app/models/workarea/search/storefront/product/text.rb,
app/models/workarea/search/storefront/product/facets.rb,
app/models/workarea/search/storefront/product/pricing.rb,
app/models/workarea/search/storefront/product/sorting.rb,
app/models/workarea/search/storefront/product/analytics.rb,
app/models/workarea/search/storefront/product/inventory.rb,
app/models/workarea/search/storefront/product/categories.rb

Direct Known Subclasses

Category, Page, Product, Search

Defined Under Namespace

Classes: Category, Page, Product, Search

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Elasticsearch::Document

all, #as_bulk_document, current_index_prefix, #destroy, #initialize, #save

Class Method Details

.ensure_dynamic_mappingsObject



6
7
8
9
10
11
12
13
# File 'app/models/workarea/search/storefront.rb', line 6

def self.ensure_dynamic_mappings
  # This ensures a bare-bones product mapping in Elasticsearch, which is
  # required for some functionality (e.g. categories in percolator).
  #
  # If there haven't been any products created, the mappings required for a
  # query or percolator may not be there.
  ensure_product_mappings
end

.ensure_product_mappingsObject



15
16
17
18
19
20
21
# File 'app/models/workarea/search/storefront.rb', line 15

def self.ensure_product_mappings
  product = Workarea::Search::Storefront::Product.new(
    Workarea::Catalog::Product.new(id: 'null_product')
  )
  product.save
  Storefront.delete(product.id)
end

Instance Method Details

#activeObject

Whether the product is active for a given release state. Storing active per-release allows accurate previewing of products in releases on the storefront.

return [Hash]



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/workarea/search/storefront.rb', line 41

def active
  model.changesets.inject(now: model.active?) do |memo, changeset|
    active = if changeset.changeset['active'].respond_to?(:[])
      changeset.changeset['active'][I18n.locale]
    else
      !!changeset.changeset['active']
    end

    memo[changeset.release_id.to_s] = active
    memo
  end
end

#as_documentObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/workarea/search/storefront.rb', line 82

def as_document
  {
    id: id,
    type: type,
    slug: slug,
    active: active,
    suggestion_content: suggestion_content,
    created_at: model.created_at,
    updated_at: model.updated_at,
    facets: facets,
    numeric: numeric,
    keywords: keywords,
    sorts: sorts,
    content: content,
    cache: cache
  }
end

#cacheObject



74
75
76
# File 'app/models/workarea/search/storefront.rb', line 74

def cache
  {}
end

#contentObject



70
71
72
# File 'app/models/workarea/search/storefront.rb', line 70

def content
  {}
end

#facetsObject



54
55
56
# File 'app/models/workarea/search/storefront.rb', line 54

def facets
  {}
end

#idObject



23
24
25
# File 'app/models/workarea/search/storefront.rb', line 23

def id
  CGI.escape("#{type}-#{model.id}")
end

#keywordsObject



62
63
64
# File 'app/models/workarea/search/storefront.rb', line 62

def keywords
  {}
end

#numericObject



58
59
60
# File 'app/models/workarea/search/storefront.rb', line 58

def numeric
  {}
end

#slugObject



31
32
33
# File 'app/models/workarea/search/storefront.rb', line 31

def slug
  model.slug
end

#sortsObject



66
67
68
# File 'app/models/workarea/search/storefront.rb', line 66

def sorts
  {}
end

#suggestion_contentObject



78
79
80
# File 'app/models/workarea/search/storefront.rb', line 78

def suggestion_content
  nil
end

#typeObject



27
28
29
# File 'app/models/workarea/search/storefront.rb', line 27

def type
  model.class.name.demodulize.underscore
end