class AboutYou::SDK::Model::Category

This class represents a category model

Constants

ACTIVE_ONLY

only active categories

ALL

all categories

Attributes

active_subcategories[RW]

Array containing all active subcategories

all_subcategories[RW]

Array containing all subcategories

id[RW]

id of the category

is_active[RW]

boolean determining whether the category is active

name[RW]

name of the category

parent_id[RW]

id of the parent category

position[RW]

position of the category

product_count[RW]

count of products in category

Public Class Methods

create_from_json(json_object, cat_manager) click to toggle source

This method is used for creating an instance of this class by a json_object.

# 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
new() click to toggle source

Constructor for the AboutYou::SDK::Model::Category class

# File lib/AboutYou/Model/category.rb, line 38
def initialize
  self.all_subcategories = []
  self.active_subcategories = []

  self
end

Public Instance Methods

breadcrumb() click to toggle source

This method is used for getting the breadcrumb up to this category

parent() click to toggle source

This method returns the parent category

# File lib/AboutYou/Model/category.rb, line 85
def parent
  return nil unless parent_id

  category_manager.category(parent_id)
end
path_active?() click to toggle source

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
subcategories(active_only = ACTIVE_ONLY) click to toggle source

This method is used for getting all subcategories

  • Args :

    • active_only -> boolean controlling whether the result should only contain active categories or not

  • Returns :

# 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