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

_findProductsThenCalculate

How to Use _findProductsThenCalculate Method#

The _findProductsThenCalculate method is a two-step process that first retrieves products based on search criteria and then calculates their pricing. This is useful when you need to search for products and subsequently compute their prices, especially if the pricing is dynamic or varies based on customer-specific factors.

Usage Steps:#

1.
Define Search Criteria:
Create an object with search parameters to filter products. This could include page number, page size, category ID, price range, etc.
2.
Define Callback Functions:
callbackProducts: Function to handle the retrieved product list and total count.
callbackPricing: Function to handle the products with updated pricing.
3.
Call the Method:
Invoke _findProductsThenCalculate with the search criteria and the callback functions.
4.
Handle Results:
The callbackProducts function will process the retrieved products and total count.
The callbackPricing function will process the products with their updated pricing.

Example:#

In this example:
The _findProductsThenCalculate method is called with searchCriteria to fetch products.
handleProducts processes and logs the retrieved products and total count.
handlePricing processes and logs the products with updated pricing.

Detailed Breakdown:#

1.
Search Products:
_findProductsThenCalculate constructs a URL using _buildProductSearchUrl based on the provided searchCriteria.
_fetchData sends a request to fetch the products and passes them to callbackProducts along with the total count.
2.
Calculate Pricing:
After receiving the products, _calculatePricing is called to calculate pricing.
A POST request is sent to /api/pricing/calculate with the products to get updated pricing data.
The pricing data is then merged with the products based on product and variant IDs.
Updated products are passed to callbackPricing.
3.
Handle Errors:
Any errors during the pricing calculation are logged to the console for troubleshooting.

Common Use Cases:#

1.
Dynamic Pricing:
Ideal for scenarios where product prices need to be computed dynamically based on user-specific conditions or promotions.
2.
Complex Search and Pricing:
Useful in applications requiring a combination of product search and price calculation, such as e-commerce platforms.
3.
Custom Pricing Logic:
Suitable for cases where pricing involves custom logic or calculations beyond simple static pricing.

Notes:#

URL Construction:
Ensure _buildProductSearchUrl correctly formats the URL based on search criteria. Adjust baseUrl if necessary.
Fetching Data:
_fetchData should handle API requests and responses efficiently. Ensure it correctly processes the product data.
API Integration:
Ensure the /api/products and /api/pricing/calculate endpoints are properly implemented on the server side to handle product retrieval and pricing calculations.
Error Handling:
Consider implementing more robust error handling and user notifications for production environments to improve user experience and system reliability.
By following these steps and guidelines, you can effectively use the _findProductsThenCalculate method to integrate product searching with dynamic pricing in your application.
Previous
_findProductsAndCalculate
Next
_getProductAttributeSet
Built with