Class: Workarea::Search::Storefront::Product
- Inherits:
-
Workarea::Search::Storefront
- Object
- Workarea::Search::Storefront
- Workarea::Search::Storefront::Product
- Defined in:
- app/models/workarea/search/storefront/product.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
Defined Under Namespace
Modules: Analytics, Categories, Facets, Inventory, Pricing, Sorting, Text
Instance Method Summary collapse
- #cache ⇒ Object
-
#catalog_id ⇒ String
The ID of the corresponding Catalog::Product.
- #content ⇒ Object
- #facets ⇒ Object
-
#keywords ⇒ Object
Fields for exact matching.
- #numeric ⇒ Object
-
#primary_image ⇒ String
URL to the primary image for display in autocomplete results.
-
#sku ⇒ Array
SKUs to be added to the search index.
-
#skus ⇒ Array<String>
The SKUs to be used for gathering pricing, inventory, display data.
- #sorts ⇒ Object
-
#variant_count ⇒ Integer
Number of active variants the product has.
Methods included from Analytics
Methods included from Sorting
#category_positions, #search_positions
Methods included from Text
#catalog_content, #category_names, #details, #details_content, #facets_content, #suggestion_content, #variant_details_text
Methods included from Categories
Methods included from Inventory
#displayable_when_out_of_stock?, #inventory, #inventory_score, #skus_with_displayable_inventory
Methods included from Pricing
#on_sale?, #price, #pricing, #sort_price
Methods inherited from Workarea::Search::Storefront
#active, #active_segment_ids, #as_document, ensure_dynamic_mappings, ensure_product_mappings, #id, #release_id, #slug, #suggestion_content, #type
Methods included from Elasticsearch::Document
all, #as_bulk_document, #as_document, current_index_prefix, #destroy, #initialize, #save
Instance Method Details
#cache ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/workarea/search/storefront/product.rb', line 66 def cache { image: primary_image, pricing: pricing.records.map do |model| Elasticsearch::Serializer.serialize(model) end, inventory: inventory.records.map do |model| Elasticsearch::Serializer.serialize(model) end } end |
#catalog_id ⇒ String
The ID of the corresponding Catalog::Product. Used to determine what product to load for display details on browse pages.
113 114 115 |
# File 'app/models/workarea/search/storefront/product.rb', line 113 def catalog_id CGI.escape(model.id) end |
#content ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/models/workarea/search/storefront/product.rb', line 56 def content { name: model.name, category_names: category_names, description: catalog_content, details: details_content, facets: facets_content } end |
#facets ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/workarea/search/storefront/product.rb', line 13 def facets result = model.filters.reduce({}) do |memo, (key, value)| memo[key.to_s.systemize] = FacetValues.sanitize(value) memo end result[:category] = if .present? result.merge( category_id: category_id, on_sale: on_sale?, inventory_policies: inventory.policies ) end |
#keywords ⇒ Object
Fields for exact matching
37 38 39 40 41 42 43 |
# File 'app/models/workarea/search/storefront/product.rb', line 37 def keywords { catalog_id: clean_for_keywords(catalog_id), sku: sku.map { |s| clean_for_keywords(s) }, name: clean_for_keywords(model.name) } end |
#numeric ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/models/workarea/search/storefront/product.rb', line 28 def numeric { price: price, inventory: inventory.available_to_sell, variant_count: variant_count } end |
#primary_image ⇒ String
URL to the primary image for display in autocomplete results.
121 122 123 |
# File 'app/models/workarea/search/storefront/product.rb', line 121 def primary_image ProductPrimaryImageUrl.new(model).path end |
#sku ⇒ Array
SKUs to be added to the search index. Allows searching for a SKU that is setup under a product.
83 84 85 86 |
# File 'app/models/workarea/search/storefront/product.rb', line 83 def sku return [] unless skus.present? inventory.select(&:displayable?).map(&:id) end |
#skus ⇒ Array<String>
The SKUs to be used for gathering pricing, inventory, display data. Show be
93 94 95 |
# File 'app/models/workarea/search/storefront/product.rb', line 93 def skus model.variants.active.map(&:sku).uniq end |
#sorts ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/workarea/search/storefront/product.rb', line 45 def sorts category_positions .merge(search_positions) .merge( price: sort_price, orders_score: orders_score, views_score: views_score, inventory_score: inventory_score ) end |
#variant_count ⇒ Integer
Number of active variants the product has. Used to filter out products that have no variants from browse pages because they won’t have displayable data.
103 104 105 |
# File 'app/models/workarea/search/storefront/product.rb', line 103 def variant_count model.variants.active.length end |