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

_findProductsByCriteria

How to Use _findProductsByCriteria Method#

The _findProductsByCriteria method allows you to perform a product search based on a flexible set of search criteria. It constructs the search URL dynamically and fetches the data using the specified criteria.

Usage Steps:#

1.
Define Search Criteria:
Create an object where each key-value pair represents a search filter. The keys are filter parameters, and the values are the corresponding values to filter by.
2.
Define the Callback Function:
The callback function will handle the results returned from the search.
3.
Call the Method:
Invoke the _findProductsByCriteria method with the search criteria and callback function.
4.
Handle Results:
The callback function will receive the search results as its parameter.

Example:#

In this example:
The _findProductsByCriteria method is called with searchCriteria specifying filters like page, pageSize, categoryId, and priceRange.
The handleResults function processes the retrieved products.

Common Use Cases:#

1.
Advanced Product Search:
Use this method to implement a comprehensive search functionality where users can specify multiple search criteria to find products.
2.
Dynamic Search Filters:
The method allows dynamic construction of the search URL based on various criteria, making it suitable for applications with diverse and customizable search options.
3.
Flexible API Integration:
Easily integrate with APIs that support query parameters for filtering products, leveraging the dynamic URL construction.

Notes:#

URL Construction:
The _buildProductSearchUrl function constructs the URL by encoding search criteria into query parameters. Ensure that the baseUrl is set appropriately for your environment.
Handling Null Values:
Keys with null values are filtered out of the URL to avoid invalid query parameters. Ensure that your searchCriteria object is properly constructed.
Fetching Data:
The _fetchData function (assumed to be implemented elsewhere) is used to perform the actual data fetch from the constructed URL. Ensure this function is defined to handle the API request.
Base URL:
Update the baseUrl in _buildProductSearchUrl to point to the correct API endpoint. If your API is served from a different base URL, make sure to include it here.
By following these guidelines, you can effectively use the _findProductsByCriteria method to implement a flexible and powerful product search feature, accommodating a wide range of search filters and requirements.
Previous
_findProductsByFilter
Next
_findProductsAndCalculate
Built with