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

_findCategoryTreeByAlias

How to Use _findCategoryTreeByAlias Method#

The _findCategoryTreeByAlias method retrieves the category tree based on the current URL path or alias. This method is particularly useful for dynamically loading category trees in a web application where the URL structure corresponds to different categories. It handles complex scenarios like subdomain paths and utilizes other category-related methods to fetch the relevant data.

Usage Steps:#

1.
Trigger the Method:
This method automatically extracts the category alias from the URL path. You do not need to provide any parameters. Simply call the method when you need to retrieve the category tree based on the current URL.
2.
Define a Callback Function:
The callback function is passed as a parameter. This function will be executed once the category tree is retrieved. The retrieved category tree data will be passed as an argument to this function.
3.
Handle Retrieved Category Tree:
Inside your callback function, you can process the retrieved category tree. This might involve displaying the category structure on the UI, using it for navigation, or performing other actions based on the category hierarchy.

Example:#

In this example:
The handleCategoryTree function will be executed once the category tree is retrieved, allowing you to process the data as needed.

Common Use Cases:#

1.
Dynamic Category Pages:
Use this method to load and display the correct category tree on dynamic category pages based on the current URL structure.
2.
SEO-Friendly URLs:
In applications where the category structure is embedded in the URL, this method allows you to dynamically fetch and display categories without hardcoding the category tree.
3.
Optimized Data Retrieval:
The method makes use of caching and existing category retrieval methods, ensuring efficient data fetching while adapting to complex URL structures.

Notes:#

URL Path Extraction: The method automatically extracts the category alias from the URL path. It accounts for potential subdomain paths, filtering out any unnecessary parts of the URL.
Handles Missing Aliases: If the URL does not contain a valid category alias, the method will fetch the entire category tree instead of a specific category.
Asynchronous Process: Since the method involves fetching category data based on the alias, the callback function will be executed asynchronously once the data is retrieved.
This method provides a powerful way to dynamically load and manage category trees based on the current URL, making it ideal for applications with complex routing or SEO-friendly URL structures.
Previous
_findCategoryByAlias
Next
_getCategoryContent
Built with