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

_findProductsByCategory

How to Use _findProductsByCategory Method#

The _findProductsByCategory method is designed to retrieve products within a specific category, utilizing pagination and optional calculations. It provides a convenient way to fetch and display products based on category and other filters.

Usage Steps:#

1.
Define Parameters:
page: The page number for pagination.
pagesize: The number of products per page.
categoryId: The ID of the category to filter products.
calc: A boolean indicating whether to perform calculations.
callback: A function to handle the results.
2.
Call the Method:
Invoke the _findProductsByCategory method with the required parameters.
3.
Handle Results:
The callback function will receive the products and total count as parameters, allowing you to handle or display the results as needed.

Example:#

In this example:
The _findProductsByCategory method is called with specified parameters.
The handleResults function will process the products and total count received from the callback.

Common Use Cases:#

1.
Product Listings by Category:
Use this method to display products within a specific category on product listing pages, category filters, or navigation elements.
2.
Pagination and Sorting:
The method supports pagination and sorting, making it suitable for handling large product catalogs and providing a smooth user experience.
3.
Dynamic Calculations:
If calculations (e.g., for promotions, stock levels, or pricing adjustments) are needed, set the calc parameter to true to include them in the API request.

Notes:#

Filter and Sort:
The filter parameter includes the category ID and any additional filters specified by forceFilters.
The sort parameter defaults to sorting by -SortDate but can be adjusted as needed.
Initialization:
The _initializeProductProperties function is used to prepare the product data for display. Ensure this function is implemented to properly format or enrich the product data.
Event Emission:
The method emits a "search-results" event with the retrieved products and total count, which can be used for further processing or UI updates.
By following these guidelines, you can effectively use the _findProductsByCategory method to fetch and display products within a specified category, enhancing the functionality and user experience of your application.
Previous
Getting Started
Next
_findProductsByIds
Built with