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

_findCategoriesByIds

How to Use _findCategoriesByIds Method#

The _findCategoriesByIds method is designed to retrieve a list of categories based on their IDs. It efficiently manages category data by leveraging caching and local storage, reducing the need for repeated API requests. You can use this method to get specific categories by their IDs and then perform further actions with the retrieved data.

Usage Steps:#

1.
Provide the ids:
The first parameter is an array of category IDs (ids). These IDs represent the categories you want to retrieve. If you want to fetch multiple categories, simply include all the relevant IDs in the array.
2.
Define a Callback Function:
The second parameter is a callback function. This function will be executed once the categories are retrieved. The retrieved categories will be passed as an argument to this function.
3.
Handle Retrieved Categories:
Inside your callback function, you can process the retrieved categories. This might involve displaying them on the UI, using them for filtering or searching, or performing other category-related actions.

Example:#

In this example:
The categoryIds array contains the IDs "101", "202", and "303". Replace these with the actual IDs of the categories you want to retrieve.
The handleCategories function will be executed once the categories are retrieved, allowing you to process the data as needed.

Common Use Cases:#

1.
Category Display:
Use this method when you need to display specific categories, such as in a product listing or category overview page.
2.
Category Filtering:
This method is helpful when you need to filter or search for items based on their categories. Retrieve the categories by their IDs and then apply the necessary filters.
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 needed frequently.

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 convenient way to fetch specific categories by their IDs and provides flexibility in handling the retrieved data for various application needs.
Previous
_findCategoryTreeById
Next
_findCategoryByAlias
Built with