Class: Workarea::Search::Storefront::ProductOption

Inherits:
Product
  • Object
show all
Defined in:
app/models/workarea/search/storefront/product_option.rb

Instance Method Summary collapse

Instance Method Details

#as_documentObject



42
43
44
45
46
47
# File 'app/models/workarea/search/storefront/product_option.rb', line 42

def as_document
  result = super
  result[:keywords][:option] = value
  result[:facets][option] = [value]
  result
end

#category_positionsObject



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

def category_positions
  Catalog::ProductPositions.find(
    BrowseOptionIds.for(model, value),
    categories: categorization.to_models
  )
end

#idObject



5
6
7
# File 'app/models/workarea/search/storefront/product_option.rb', line 5

def id
  "#{super}-#{value.optionize}"
end

#optionObject



17
18
19
# File 'app/models/workarea/search/storefront/product_option.rb', line 17

def option
  options[:option]
end

#primary_imageString

URL to the primary image for display in autocomplete results.

Returns:

  • (String)


13
14
15
# File 'app/models/workarea/search/storefront/product_option.rb', line 13

def primary_image
  ProductOptionImageUrl.new(model, option: value).url
end

#skusObject



38
39
40
# File 'app/models/workarea/search/storefront/product_option.rb', line 38

def skus
  variants.map(&:sku)
end

#valueObject



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

def value
  options[:value].to_s
end

#variantsObject



32
33
34
35
36
# File 'app/models/workarea/search/storefront/product_option.rb', line 32

def variants
  @variants ||= model.variants.select do |variant|
    variant.matches_detail?(option, value)
  end
end