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

_updateCheckout

Example Usage of _updateCheckout Method#

The _updateCheckout method is designed to update an existing checkout session with new or modified data. This method is useful when you need to make changes to the checkout details, such as updating the shipping address or modifying items in the cart.

Scenario#

You need to update the checkout session with new shipping details and optionally adjust the cart items before finalizing the purchase.

Example Code#

Explanation#

1.
Define Callback Functions:
handleUpdateSuccess: This function is called when the checkout is successfully updated. It logs the response data to the console and shows an alert indicating that the checkout has been updated.
handleUpdateError: This function is called if there is an error during the checkout update. It logs the error status and data to the console and displays an alert with an error message.
2.
Define Checkout Data:
updatedCheckoutData: This object contains the updated details for the checkout session, including any new or modified information such as shipping address and cart items.
3.
Call the _updateCheckout Method:
The _updateCheckout method is invoked with the updatedCheckoutData object, along with the handleUpdateSuccess and handleUpdateError callback functions. This initiates a request to update the checkout session with the provided data.

Detailed Flow#

1.
Prepare Data:
Construct the updatedCheckoutData object with the necessary updates to the checkout session, such as shipping address or cart modifications.
2.
Send Update Request:
The method sends a POST request to the /api/checkout/update/{checkoutToken} endpoint with the updatedCheckoutData object in the request body. The checkoutToken is retrieved from localStorage.
3.
Handle Response:
On Success: The handleUpdateSuccess callback function is invoked with the response data, allowing you to update the UI or perform further actions based on the successful update.
On Error: The handleUpdateError callback function is invoked with the error status and data, allowing you to handle the error appropriately, such as by showing an error message to the user.

Notes#

Token Management: Ensure that localStorage.checkoutToken is correctly managed and not expired.
Data Validation: Verify that the updatedCheckoutData contains all necessary fields and is formatted correctly before making the API request.
Error Handling: Implement robust error handling to improve user experience and ensure that users are informed of any issues that occur during the update process.
By following this example, you can effectively use the _updateCheckout method to update an existing checkout session with new or modified information, providing a seamless experience for users who need to make changes to their checkout details.
Previous
_startCheckout
Next
_completeCheckout
Built with