HomeWiki
HomeWiki
  1. Categories
  • Back to home
  • 1. Themes
  • Layout
    • New Layout
    • Legacy Layout
  • Components
    • Announcement
    • Banner Carousel
    • Banner With Products Carousel
    • Blog Category List
    • Blog List
    • Brand List
    • Brands Carousel
    • Breadcrumb
    • Call To Action
    • Cart
    • Categories List
    • Change Password
    • Checkout
    • Cookie Manager
    • Filter list
    • Footer
    • Forgot Password
    • Form
    • Hero Carousel
    • Icon Block
    • Invitation
    • Last Visited Products
    • Layout
    • Login
    • Map
    • Nav Bar
    • Offer
    • Product Attachments
    • Product Attributes
    • Product Documentation
    • Product Expected
    • Product Modal
    • Products Block
    • Products Carousel
    • Product Single
    • Profile
    • Quote
    • Register
    • Related Products
    • Search
    • Stores
    • Subscribe Newsletter
    • Text with Image
    • Top Bar
    • Video
  • Reusables
    • Getting Started
  • Assets
    • Getting Started
  • SDK
    • Products
      • _findProductsByCategory
      • _findProductsByIds
      • _findProductsByTitle
      • _findProductsByFilter
      • _findProductsByCriteria
      • _findProductsAndCalculate
      • _findProductsThenCalculate
      • _getProductAttributeSet
      • _setLastVisited
    • Categories
      • _findCategoryTreeById
      • _findCategoriesByIds
      • _findCategoryByAlias
      • _findCategoryTreeByAlias
      • _getCategoryContent
    • Collections
      • _getCollectionContent
      • _findCollectionsByIds
      • _findCollectionsByIdsThenCalculate
    • Brands
      • _getBrandContent
      • _findBrandsByIds
    • Cart
      • _addToCartMulti
      • _addToCart
      • _setCart
      • _clearCart
      • _setCartListener
      • _removeFromCart
      • _calculateCart
    • Checkout
      • _startCheckout
      • _updateCheckout
      • _completeCheckout
    • Shopping Lists
      • _getShoppingLists
      • _updateShoppingList
      • _createShoppingList
      • _deleteShoppingList
      • _getShoppingListByAlias
    • Navigation
      • _getFooterMenu
      • _getHeaderMenu
    • Users
      • _getUserById
    • Utils
      • _calculateCurrency
      • _getCurrencySymbol
      • _getCulture
      • _subscribeToNewsletter
      • _findUnitsByIds
  • Vs Code
    • Getting Started
  1. Categories

_findCategoryTreeById

How to Use _findCategoryTreeById Method#

The _findCategoryTreeById method retrieves a category tree or a specific category within the tree by its ID. It utilizes caching and local storage to optimize performance, reducing the need for repeated API calls. You can use this method to get category data for various purposes, such as displaying a category structure or navigating through categories.

Usage Steps:#

1.
Provide the categoryId:
The first parameter is the categoryId, which is the unique identifier for the category you want to retrieve. If you pass null or omit this parameter, the method will return the entire category tree instead of a specific category.
2.
Define a Callback Function:
The second parameter is a callback function. This function will be executed once the category data is retrieved. The retrieved data (either the entire category tree or the specific category) will be passed as an argument to this function.
3.
Handle Retrieved Data:
Inside your callback function, you can process the retrieved category data. This might involve rendering the categories on the UI, navigating to a specific category, or performing other actions based on the category information.

Example:#

In this example:
The categoryId is "12345". Replace this with the actual ID of the category you want to retrieve. If you want to retrieve the entire category tree, pass null instead.
The handleCategoryData function will be executed once the category data is retrieved, allowing you to process the data as needed.

Common Use Cases:#

1.
Category Navigation:
Use this method when building category navigation menus, allowing you to fetch and display subcategories dynamically.
2.
Category Selection in Forms:
This method is useful for forms where users need to select a category. You can retrieve the entire category tree and display it in a dropdown or selection component.
3.
Optimized Loading:
By leveraging caching and local storage, this method reduces the need for repeated API calls, making it ideal for scenarios where category data is frequently accessed but doesn't change often.

Notes:#

Caching: The method caches the category tree in memory (_cache_category_tree) and in local storage to improve performance. If the cache is available, it will be used instead of making an API call.
Language-Specific Data: The method retrieves the category data based on the current language setting, ensuring that users see the correct language version of the categories.
Asynchronous Process: Since the method may involve an API call, the callback function will be executed asynchronously once the data is retrieved.
This method is a powerful tool for retrieving and working with category data, allowing you to efficiently manage category structures within your application.
Previous
_setLastVisited
Next
_findCategoriesByIds
Built with