Category Tree & Hierarchy
Understanding the category hierarchy in Omnium, including tree operations, sorting, and navigation building.
Categories in Omnium form a hierarchical tree structure through parent-child relationships. This page explains how the hierarchy works and how to work with category trees.
How Hierarchy Works
Parent-Child Relationships
Categories are linked through the parentId property:
- Categories with
parentId: nullare root-level categories - The
rootCategoryIdtenant setting defines the primary catalog root - There is no limit on nesting depth
Root Category
The rootCategoryId setting in tenant configuration identifies the top of your catalog hierarchy:
Categories outside this hierarchy may not appear in standard navigation but are still accessible via API.
Sorting Categories
Categories within the same parent are sorted by the sortIndex property:
| sortIndex | Category |
|---|---|
| 0 | Featured |
| 100 | Clothing |
| 200 | Electronics |
| 300 | Home & Garden |
Best practices:
- Use increments of 10 or 100 to allow inserting categories later
- Lower values appear first
- Categories with the same
sortIndexare sorted alphabetically by name
Multi-Language Considerations
Category trees exist per language. Each language has its own set of category documents with localized content.
Example: Requesting the tree in English returns:
The same tree in Norwegian:
All tree operations accept a language parameter to specify which language version to retrieve.
The hierarchy structure (parent-child relationships) is the same across all languages - only the names and descriptions differ.
Tree Operations
Getting the Full Tree
Retrieve the complete category hierarchy with product counts:
Response structure:
Getting Subcategories
Retrieve direct children of a specific category:
This returns only immediate children, not the full subtree.
Filtered Tree by Search
Get a tree filtered by product search criteria:
This returns only categories containing products matching the search, with accurate product counts for the filtered results.
Building Navigation
Basic Category Menu
- Fetch the category tree starting from
rootCategoryId - Render top-level children as main menu items
- Render grandchildren as dropdown/submenu items
Breadcrumb Navigation
Build breadcrumbs by traversing from a category up to the root:
- Start with the current category
- Follow
parentIdto get the parent category - Repeat until
parentIdis null or matchesrootCategoryId - Reverse the array for display
Category with Product Counts
The tree response includes productCount for displaying alongside category names:
Orphaned Categories
Orphaned categories occur when a category's parentId references a category that doesn't exist. This can happen after deleting a parent category without updating its children.
Detecting Orphans
Orphaned categories will not appear in tree responses because they cannot be linked to the hierarchy. They remain accessible via direct API queries.
Fixing Orphans
To fix orphaned categories:
- Query categories where
parentIddoesn't match any existing category - Update the
parentIdto a valid category or set to null (making it a root) - Or delete the orphaned categories if no longer needed
Moving Categories
To move a category to a different parent, update its parentId:
When moving categories, remember to update all language versions. The hierarchy should be consistent across languages.
Moving a category automatically moves all its descendants - the subtree structure is preserved.
Performance Considerations
Caching
Category tree operations are cached by Omnium for improved performance. Cache is automatically invalidated when categories are modified.
Deep Hierarchies
Very deep hierarchies (10+ levels) may impact:
- Tree fetch performance
- UI rendering complexity
- Parent category addition processing
For most e-commerce use cases, 3-5 levels of hierarchy are sufficient.
Large Category Counts
For catalogs with thousands of categories:
- Use pagination via the ScrollSearch API
- Fetch subtrees on-demand rather than the complete tree
