The category module

class magento.models.category.Category(data, client)[source]View on GitHub

Bases: Model

Wrapper for the categories endpoint

DOCUMENTATION: str = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/categories'

Link to the Official Magento 2 API documentation for the endpoint wrapped by the Model

IDENTIFIER: str = 'id'

The API response field that the endpoint’s uid comes from

__init__(data, client)[source]View on GitHub

Initialize a Category object using an API response from the categories endpoint

Parameters

data (dict) – raw API response

property excluded_keys

API response keys that shouldn’t be set as object attributes by set_attrs()

Returns

list of API response keys that shouldn’t be set as attributes

property custom_attributes: Dict[str, str]
property subcategories: List[Category]

The child categories, returned as a list of Category objects

Note

Only the direct child categories are returned. For a list of all descendants, use all_subcategories

property subcategory_ids: List[int]

The category_ids of the subcategories

property subcategory_names: List[str]

The names of the category’s subcategories

property all_subcategories: Optional[List[Category]]

Recursively retrieves all descendants of the category

property all_subcategory_ids: List[int]

The category_ids of all_subcategories

property products: List[Product]

The Product s in the category

Alias for get_products()

property product_ids: List[int]

The product_ids of the category’s products

property skus: List[str]

The skus of the category’s products

property all_products: List[Product]

The Product s in the category and in all_subcategories

Alias for get_products() with search_subcategories=True

property all_product_ids: Set[int]

The product_ids of the products in the category and in all_subcategories

property all_skus: Set[str]

The skus of the products in the category and in all_subcategories

get_products(search_subcategories=False)[source]View on GitHub

Retrieves the category’s products

Parameters

search_subcategories (bool) – if True, also retrieves products from all_subcategories

Return type

Optional[Product | List[Product]]

get_orders(search_subcategories=False)[source]View on GitHub

Retrieve any Order that contains one of the category’s products

Parameters

search_subcategories (bool) – if True, also searches for orders from all_subcategories

Return type

Optional[Order | List[Order]]

get_order_items(search_subcategories=False)[source]View on GitHub

Retrieve any OrderItem that contains one of the category’s products

Parameters

search_subcategories (bool) – if True, also searches for order items from all_subcategories

Return type

Optional[OrderItem | List[OrderItem]]

get_invoices(search_subcategories=False)[source]View on GitHub

Retrieve any Invoice that contains one of the category’s products

Parameters

search_subcategories (bool) – if True, also searches for invoices from all_subcategories

Return type

Optional[Invoice | List[Invoice]]