HomeWiki
HomeWiki
  1. Utils
  • 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. Utils

_findUnitsByIds

How to Use _findUnitsByIds Method#

The _findUnitsByIds method is designed to retrieve unit information based on an array of unit IDs. It utilizes caching and local storage to improve performance and reduce unnecessary API requests. This method is useful for fetching specific unit details from a list of units, which can be used for various purposes in your application.

Usage Steps:#

1.
Provide the unitsIds:
The first parameter is an array of unit IDs (unitsIds). These IDs represent the units you want to retrieve. You should pass an array of IDs that you need information for.
2.
Define a Callback Function:
The second parameter is a callback function. This function will be executed once the units are retrieved. The filtered units based on the provided IDs will be passed as an argument to this function.
3.
Handle Retrieved Units:
Inside your callback function, you can process the retrieved units. This might involve displaying unit details in the UI, using the units for filtering or searching, or other related actions.

Example:#

In this example:
The unitIds array contains IDs "unit1", "unit2", and "unit3". Replace these with the actual IDs of the units you want to retrieve.
The handleUnits function will be executed once the units are retrieved, allowing you to process the data as needed.

Common Use Cases:#

1.
Unit Details Display:
Use this method to fetch and display specific unit details on a page, such as in a product or inventory management interface.
2.
Filtering and Searching:
This method can be used to filter or search for units based on their IDs, which is useful for scenarios where you need to work with specific subsets of unit data.
3.
Optimized Data Retrieval:
By leveraging caching and local storage, this method ensures efficient data retrieval, reducing the need for repeated API calls and improving performance.

Notes:#

Caching: The method caches the units in memory (_cache_units) and in local storage to enhance performance. If the cache is available, it will be used to provide the requested units instead of making a new API call.
Language-Specific Data: The method retrieves unit data based on the current language setting, ensuring that the units are appropriately localized.
Asynchronous Process: Since the method may involve an API call, the callback function will be executed asynchronously once the data is retrieved.
This method provides a streamlined approach to retrieve and manage unit data efficiently, making it a valuable tool for applications that work with unit information and require optimized data access.
Previous
_subscribeToNewsletter
Next
Getting Started
Built with