Home
Wiki
Home
Wiki
  1. Collections
  • Back to home
  • 1. Themes
  • Vs Code
    • Getting Started
  • Kitchenware
    • 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
  • Noir
  1. Collections

_findCollectionsByIds

Example Usage of _findCollectionsByIds Method#

The _findCollectionsByIds method is designed to retrieve collections based on their IDs. It also has the option to include associated products in the response.

Method Signature#

Parameters#

collectionIds (Array): An array of collection IDs that you want to retrieve.
showProducts (Boolean): A flag to indicate whether to include associated products in the response.
callback (Function): A callback function to handle the retrieved collections.

How It Works#

1.
Check Collection IDs: The method first checks if collectionIds is provided. If it's null, the method exits early without making an API request.
2.
Build Query String: Constructs a query string to pass to the API. This query string includes:
A list of collection IDs joined by &collectionIds=.
An expanded flag to indicate whether products should be included in the response (showProducts).
3.
Make API Request: Sends a GET request to the /api/collection endpoint with the constructed query string. The request payload includes the collectionIds and showProducts parameters.
4.
Handle Response: On a successful response, the method retrieves the collection data from the response and passes it to the provided callback function.

Example Usage#

Here's an example of how to use the _findCollectionsByIds method:
In this example:
collectionIds contains the IDs of the collections to be fetched.
showProducts is set to true, indicating that associated products should be included in the response.
handleCollections is a callback function that logs the retrieved collections.

Notes#

API Endpoint: Ensure the /api/collection endpoint is properly implemented to handle the query parameters and return the expected data.
Error Handling: Consider adding error handling within the callback function to manage cases where the API request fails or returns an error.
Performance: Be aware of performance implications when requesting a large number of collections or including a large number of products.
By following this guide, you can effectively use the _findCollectionsByIds method to retrieve collections and their associated products as needed.
Modified at 2024-08-20 13:48:13
Previous
_getCollectionContent
Next
_findCollectionsByIdsThenCalculate
Built with