Sha256: bd222e248c421abf05ac421cf92068a38372bdcb8026b45a0fa990c773474a50

Contents?: true

Size: 1.07 KB

Versions: 62

Compression:

Stored size: 1.07 KB

Contents

module Workarea
  module Search
    module LoadProductResults
      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

      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

      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
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.26 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.45 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.25 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.23 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.44 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.22 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.43 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.21 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.42 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.20 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.41 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.19 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.40 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.18 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.39 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.17 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.38 app/queries/workarea/search/load_product_results.rb
workarea-core-3.5.16 app/queries/workarea/search/load_product_results.rb
workarea-core-3.4.37 app/queries/workarea/search/load_product_results.rb