class AboutYou::SDK::Model::Category
This class represents a category model
Constants
- ACTIVE_ONLY
only active categories
- ALL
all categories
Attributes
Array containing all active subcategories
Array containing all subcategories
id of the category
boolean determining whether the category is active
name of the category
id of the parent category
position of the category
count of products in category
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 -
cat_manager
-> instance ofAboutYou::SDK::Model::CategoryManager::DefaultCategoryManager
-
-
Returns :
-
Instance of
AboutYou::SDK::Model::Category
-
# File lib/AboutYou/Model/category.rb, line 55 def self.create_from_json(json_object, cat_manager) category = new category.parent_id = json_object['parent'] category.id = json_object['id'] category.name = json_object['name'] category.is_active = json_object['active'] category.position = json_object['position'] category.category_manager = cat_manager category end
Constructor for the AboutYou::SDK::Model::Category
class
-
Returns :
-
an instance of
AboutYou::SDK::Model::Category
-
# File lib/AboutYou/Model/category.rb, line 38 def initialize self.all_subcategories = [] self.active_subcategories = [] self end
Public Instance Methods
This method returns the parent category
-
Returns :
-
Either instance of
AboutYou::SDK::Model::Category
or nil if no parent category is set
-
# File lib/AboutYou/Model/category.rb, line 85 def parent return nil unless parent_id category_manager.category(parent_id) end
This method checks if the complete category path up to this category is active
-
Returns :
-
Boolean determining whether the complete path up to this category is active or not
-
# File lib/AboutYou/Model/category.rb, line 75 def path_active? is_active && (parent.nil? || parent.path_active?) end
This method is used for getting all subcategories
-
Args :
-
active_only
-> boolean controlling whether the result should only contain active categories or not
-
-
Returns :
-
Hash containing pairs of category_id => instance of
AboutYou::SDK::Model::Category
-
# File lib/AboutYou/Model/category.rb, line 100 def subcategories(active_only = ACTIVE_ONLY) subcategories = category_manager.subcategories(id, active_only) return subcategories if active_only == ALL result = {} subcategories.each do |key, subcat| result[key] = subcat if subcat.is_active end result end