Module: Workarea::Search::LoadProductResults

Included in:
CategoryBrowse, ProductSearch, RelatedProducts
Defined in:
app/queries/workarea/search/load_product_results.rb

Instance Method Summary collapse

Instance Method Details

#load_inventory_from(source) ⇒ Object



27
28
29
30
31
32
33
# File 'app/queries/workarea/search/load_product_results.rb', line 27

def load_inventory_from(source)
  inventory = (source['cache']['inventory'] || []).map do |serialized|
    Elasticsearch::Serializer.deserialize(serialized)
  end

  Workarea::Inventory::Collection.new(inventory.map(&:id), inventory)
end

#load_model_from(document) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/queries/workarea/search/load_product_results.rb', line 4

def load_model_from(document)
  source = document['_source']
  product = Elasticsearch::Serializer.deserialize(source)

  {
    id: source['id'],
    catalog_id: product.id, # TODO v4 retire this, use result[:model].id instead
    model: product,
    option: source['keywords']['option'],
    pricing: load_pricing_from(source),
    inventory: load_inventory_from(source),
    raw: document
  }
end

#load_pricing_from(source) ⇒ Object



19
20
21
22
23
24
25
# File 'app/queries/workarea/search/load_product_results.rb', line 19

def load_pricing_from(source)
  pricing = (source['cache']['pricing'] || []).map do |serialized|
    Elasticsearch::Serializer.deserialize(serialized)
  end

  Workarea::Pricing::Collection.new(pricing.map(&:id), pricing)
end