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

_calculateCart

How to Use _calculateCart Method#

The _calculateCart method fetches the calculated data for the shopping cart. This includes any computations related to cart totals, discounts, or other relevant calculations. The method also handles cancellation of ongoing requests and invokes appropriate callbacks based on the success or failure of the request.

Usage Steps:#

1.
Define Callbacks:
Create onSuccess and onError callback functions to handle the response or error from the API request.
2.
Call the Method:
Invoke the _calculateCart method, passing your onSuccess and onError callbacks as arguments.
3.
Handle the Response:
The onSuccess callback will be triggered if the request is successful, receiving the cart data.
The onError callback will be triggered if an error occurs, receiving the error status and data.

Example:#

In this example:
handleCartSuccess is called with the calculated cart data if the request is successful.
handleCartError is called with the error status and data if an error occurs.

Common Use Cases:#

1.
Calculating Cart Totals:
Use this method to calculate and update the total cost of items in the cart, including taxes, discounts, and other fees.
2.
Updating Cart UI:
The success callback allows you to update the UI with the latest cart calculations, such as refreshing the cart summary or totals.
3.
Handling Calculation Errors:
The error callback lets you handle any issues that occur during the calculation process, such as network errors or server issues.

Notes:#

Cancellation Token: The method supports request cancellation using axios.CancelToken. If a previous calculation request is still pending, it will be canceled before initiating a new request.
Event Emission: Upon successful calculation, the method emits a "calculated-cart" event with the cart data, allowing other parts of the application to react to the updated cart state.
This method provides a robust way to handle cart calculations, ensuring that users receive accurate and up-to-date information about their shopping cart. It also provides mechanisms for handling errors and updating the UI based on the calculation results.
Previous
_removeFromCart
Next
_startCheckout
Built with