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

_findProductsByIds

How to Use _findProductsByIds Method#

The _findProductsByIds method allows you to retrieve products based on a list of product IDs. This method supports optional calculations and uses pagination to handle large lists of product IDs efficiently.

Usage Steps:#

1.
Define Parameters:
productIds: An array of product IDs you want to retrieve.
calc: A boolean indicating whether to perform calculations on the products.
callback: A function to handle the results.
2.
Call the Method:
Invoke the _findProductsByIds method with the required parameters.
3.
Handle Results:
The callback function will receive the products and total count as parameters, allowing you to process or display the results.

Example:#

In this example:
The _findProductsByIds method is called with a list of product IDs and the calculate parameter set to true.
The handleResults function will process the products and total count received from the callback.

Common Use Cases:#

1.
Batch Product Retrieval:
Use this method to retrieve detailed information about a set of products based on their IDs, such as when showing a user's recently viewed items or fetching product details for a comparison page.
2.
Calculation Integration:
If you need to perform calculations (e.g., updating prices or stock levels), set the calc parameter to true to include them in the API request.
3.
Efficient Pagination:
The method uses pagination to handle potentially large sets of product IDs, ensuring efficient data retrieval and performance.

Notes:#

Filter Construction:
The filter parameter is constructed by joining the product IDs with the &ids= prefix. This formats the query string for the API request to fetch the specified products.
Pagination and Sorting:
The method uses pagination with a page size equal to the number of product IDs provided. The sort parameter defaults to -SortDate, but you can adjust this as needed.
Initialization:
The _findProducts function is used internally to handle the API request. Ensure that _initializeProductProperties is implemented to format or enrich the product data appropriately.
Handling Empty IDs:
If productIds is null or an empty array, the method does not make an API request and returns immediately. Ensure that you handle such cases as needed in your application.
By following these guidelines, you can effectively use the _findProductsByIds method to fetch and manage product data based on a list of product IDs, enhancing the functionality and performance of your application.
Previous
_findProductsByCategory
Next
_findProductsByTitle
Built with