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

_findCategoryByAlias

How to Use _findCategoryByAlias Method#

The _findCategoryByAlias method allows you to retrieve a category by its alias. It uses caching and local storage to optimize performance, reducing the need for repeated API calls. This method is useful when you need to find a specific category using its alias, such as for navigation, display, or filtering purposes.

Usage Steps:#

1.
Provide the alias:
The first parameter is the alias, which is a unique identifier (or slug) associated with the category. You can pass this alias as a string to find the corresponding category.
2.
Define a Callback Function:
The second parameter is a callback function. This function will be executed once the category is retrieved. The retrieved category object will be passed as an argument to this function.
3.
Handle Retrieved Category:
Inside your callback function, you can process the retrieved category. This might involve displaying the category details on the UI, using it for navigation, or performing other category-related actions.

Example:#

In this example:
The categoryAlias is "electronics". Replace this with the actual alias of the category you want to retrieve.
The handleCategory function will be executed once the category is retrieved, allowing you to process the category data as needed.

Common Use Cases:#

1.
Category Navigation:
Use this method to navigate users to a specific category page based on its alias, such as when a user clicks on a category link.
2.
Category Display:
This method is helpful for displaying category details on a page where the category alias is used to identify which category should be shown.
3.
Optimized Data Retrieval:
By leveraging caching and local storage, this method ensures that category data is fetched efficiently, making it ideal for scenarios where category information is frequently accessed.

Notes:#

Caching: The method caches the categories in memory (_cache_categories) 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 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 practical tool for finding and using category data based on aliases, providing flexibility in handling category-related operations in your application.
Previous
_findCategoriesByIds
Next
_findCategoryTreeByAlias
Built with