class AboutYou::SDK::Model::ProductSearchResult
This class represents a product search result model
Attributes
Array containing instances of AboutYou::SDK::Model::Category
Array containing instances of AboutYou::SDK::Model::Facet
String page hash
Array containing instances of AboutYou::SDK::Model::PriceRange
Integer count of products
Array of instances of AboutYou::SDK::Model::Product
raw facets
Integer count of products in sale
Public Class Methods
This method is used for creating an instance of this class by a json_object.
-
Args :
-
json_object
-> the json_object received from the api -
factory
-> instance ofAboutYou::SDK::Factory::DefaultModelFactory
-
-
Returns :
-
Instance of
AboutYou::SDK::Model::ProductSearchResult
-
# File lib/AboutYou/Model/product_search_result.rb, line 47 def self.create_from_json(json_object, factory) product_search_result = new product_search_result.page_hash = json_object['page_hash'] product_search_result.product_count = json_object['product_count'] product_search_result.raw_facets = json_object['facets'] json_object['products'].each do |json_product| product = factory.create_product(json_product) product_search_result.products[product.id] = product end product_search_result.parse_facets(json_object['facets'], factory) # free memory json_object['categories'] = nil json_object['prices'] = nil json_object['sale'] = nil product_search_result.facets = factory.create_facets_counts( json_object ) product_search_result end
Constructor for the AboutYou::SDK::Model::ProductSearchResult
class
-
Returns :
-
an instance of
AboutYou::SDK::Model::ProductSearchResult
-
# File lib/AboutYou/Model/product_search_result.rb, line 31 def initialize self.products = {} self end
Public Instance Methods
Getter for the category tree
-
Returns :
-
/ Array containing instances of
AboutYou::SDK::Model::Category
# File lib/AboutYou/Model/product_search_result.rb, line 133 def category_tree top_level_categories = [] categories.each do |category| top_level_categories.push(category) if category.parent.nil? end top_level_categories end
Getter for the max price
-
Returns :
-
nil / Integer
-
# File lib/AboutYou/Model/product_search_result.rb, line 116 def max_price return nil if price_ranges.empty? price_ranges.reverse_each do |price_range| next if price_range.product_count == 0 return price_range.max end price_ranges[-1].max end
Getter for the min price
-
Returns :
-
nil / Integer
-
# File lib/AboutYou/Model/product_search_result.rb, line 99 def min_price return nil if price_ranges.empty? price_ranges.each do |price_range| next if price_range.product_count == 0 return price_range.min end price_ranges[0].min end
This method is used for parsing the facets of the search result
-
Args :
-
json_object
-> the json_object received from the api -
factory
-> instance ofAboutYou::SDK::Factory::DefaultModelFactory
-
# File lib/AboutYou/Model/product_search_result.rb, line 79 def parse_facets(json_object, factory) self.categories = factory.create_categories_facets( json_object['categories'] ) if json_object['categories'] self.price_ranges = factory.create_price_ranges( json_object['prices'] ) if json_object['prices'] self.sale_counts = factory.create_sale_facet( json_object['sale'] ) if json_object['sale'] end