@plentymarkets/shop-api / categoryTreeGetters
Variable: categoryTreeGetters ​
constcategoryTreeGetters:object
Defined in: getters/categoryTreeGetters.ts:295
Type Declaration ​
findCategoriesPathByCategoryId ​
findCategoriesPathByCategoryId: (
categories,id,path) =>CategoryTreeItem[]
Returns the full ancestry path (from root to the target category) for the category with the given ID. Performs a depth-first recursive search and accumulates the path of ancestors.
Parameters ​
categories ​
The array of category tree items to search.
id ​
number
The numeric ID of the target category.
path? ​
CategoryTreeItem[] = []
The accumulated path of ancestors so far (used in recursion).
Returns ​
An array of CategoryTreeItem objects from root to the target, or an empty array if not found.
findCategoryById ​
findCategoryById: (
categories,categoryId) =>CategoryTreeItem|null
Searches the category tree for a category with the given numeric ID. Performs a depth-first recursive search through children.
Parameters ​
categories ​
The array of category tree items to search.
categoryId ​
number
The numeric ID of the category to find.
Returns ​
CategoryTreeItem | null
The matching CategoryTreeItem, or null if not found.
findCategoryBySlug ​
findCategoryBySlug: (
categories,slug) =>CategoryTreeItem|null
Searches the category tree for the first category whose nameUrl matches the given slug. Performs a depth-first recursive search through children.
Parameters ​
categories ​
The array of category tree items to search.
slug ​
string
The URL slug to match against each category's nameUrl.
Returns ​
CategoryTreeItem | null
The matching CategoryTreeItem, or null if not found.
findCategoryBySlugs ​
findCategoryBySlugs: (
categories,slugs) =>CategoryTreeItem|undefined
Finds a category by matching successive URL slugs through nested children. Each element in slugs corresponds to a level in the category hierarchy.
Parameters ​
categories ​
The array of category tree items to search at the current level.
slugs ​
string[]
An ordered array of URL slugs representing the category path.
Returns ​
CategoryTreeItem | undefined
The matching CategoryTreeItem, or undefined if not found.
generateBreadcrumbFromCategory ​
generateBreadcrumbFromCategory: (
tree,categoryId) =>Breadcrumb[]
Generates an array of breadcrumb entries from the root to the category with the given ID. Each breadcrumb contains the category name and its full URL link.
Parameters ​
tree ​
The full category tree.
categoryId ​
number
The numeric ID of the target category.
Returns ​
An array of Breadcrumb objects ordered from root to the target category.
generateCategoryLink ​
generateCategoryLink: (
tree,node,startStr) =>string
Generates the full URL path for a category node within a tree. Traverses the ancestry path and concatenates each category's slug.
Parameters ​
tree ​
The full category tree.
node ​
The target category tree item.
startStr? ​
string = ''
An optional prefix to prepend to the generated path (defaults to "").
Returns ​
string
The full URL path string for the category.
getCategoryDetails ​
getCategoryDetails: (
details) =>CategoryTreeItemDetails|null
Returns the first details entry of a category tree item.
Parameters ​
details ​
The array of CategoryTreeItemDetails objects.
Returns ​
CategoryTreeItemDetails | null
The first CategoryTreeItemDetails, or null if the array is empty or not provided.
getCategoryRight ​
getCategoryRight: (
category) =>string
Returns the access right of a category tree item (e.g. "all", "customer").
Parameters ​
category ​
The category tree item.
Returns ​
string
The right string, defaulting to "all" if not set.
getCount ​
getCount: (
category) =>number
Returns the item count for a category tree item.
Parameters ​
category ​
The category tree item.
Returns ​
number
The numeric item count, or 0 if not available.
getId ​
getId: (
categoryTreeItem) =>number
Returns the numeric ID of a category tree item.
Parameters ​
categoryTreeItem ​
The category tree item.
Returns ​
number
The category ID.
getItems ​
getItems: (
category) =>CategoryTreeItem[]
Returns the child categories of a category tree item.
Parameters ​
category ​
The category tree item.
Returns ​
An array of child CategoryTreeItem objects, or an empty array if none exist.
getMappedBreadcrumbs ​
getMappedBreadcrumbs: (
categories,categoryId,prefix) =>Breadcrumb[]
Returns an array of breadcrumbs for the given category ID, each with name and prefixed link.
Parameters ​
categories ​
The full category tree.
categoryId ​
number
The numeric ID of the target category.
prefix? ​
string = ''
An optional URL prefix to prepend to each breadcrumb link (defaults to "").
Returns ​
An array of Breadcrumb objects ordered from root to the target category.
getName ​
getName: (
category) =>string
Returns the display name of a category tree item from its first details entry.
Parameters ​
category ​
The category tree item.
Returns ​
string
The category name string, or an empty string if details are not available.
getSlug ​
getSlug: (
category) =>string
Returns the URL slug (nameUrl) of a category tree item from its first details entry.
Parameters ​
category ​
The category tree item.
Returns ​
string
The slug string, or an empty string if details are not available.
getTree ​
getTree: (
categories) =>CategoryTreeItem[]
Builds a filtered and normalised category tree from the raw category list. Only entries with valid details are included; children are processed recursively.
Parameters ​
categories ​
The flat or nested array of raw category tree items.
Returns ​
An array of CategoryTreeItem objects forming the visible tree.
getTreeItem ​
getTreeItem: (
category) =>CategoryTreeItem|null
Returns a normalised tree item for the given category, or null if the category has no valid details. Recursively processes children and updates the childCount property.
Parameters ​
category ​
The raw category tree item.
Returns ​
CategoryTreeItem | null
The normalised CategoryTreeItem, or null if details are missing.