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

_startCheckout

Example Usage of_startCheckout Method#

The _startCheckout method is a utility function designed to initiate the checkout process within an application. It handles the creation of a checkout session based on either a quote or a cart, and then triggers the appropriate events and callbacks. This method is essential for managing the transition from product selection to the checkout stage.

Purpose#

The _startCheckout method starts the checkout process by:
1.
Creating or using an existing checkout token.
2.
Determining whether to proceed with a quote or a cart based on URL parameters.
3.
Making an API request to start the checkout session.
4.
Emitting an event and invoking callbacks based on the success or failure of the checkout initiation.

Usage Steps#

1.
Define Callback Functions:
onSuccess: A function that will be called when the checkout initiation is successful. It receives the response data from the API.
onError: A function that will be called if there is an error during the checkout initiation. It receives the error status and data.
2.
Call the Method:
Invoke the _startCheckout method with the onSuccess and onError callback functions.

Detailed Breakdown#

1.
Token Management:
If localStorage.checkoutToken is not present, a new token is generated and stored in localStorage. This token is used to identify the checkout session.
2.
Determine Checkout Type:
Quote Checkout:
If the URL contains a quote parameter, a POST request is sent to the endpoint designed for quote-based checkouts.
This request uses both the checkoutToken and quoteToken to start the checkout session based on a saved quote.
Cart Checkout:
If no quote parameter is present, the method checks for localStorage.cartToken.
A POST request is made to the endpoint for cart-based checkouts using the checkoutToken and cartToken.
3.
Event Emission:
Upon successful initiation of the checkout process, an event proceed-to-checkout is emitted with the response data. This allows other parts of the application to react to the checkout initiation.
4.
Callback Invocation:
On Success: The onSuccess callback is called with the response data from the checkout initiation.
On Error: The onError callback is called with the error status and data if the checkout initiation fails.

Common Use Cases#

Initiating Checkout: Used to start the checkout process either from a saved quote or an active cart, enabling a smooth transition from shopping to completing a purchase.
Handling Different Checkout Scenarios: Supports scenarios where a checkout can be started either via a quote (e.g., saved quotations or offers) or a cart (e.g., items currently in the shopping cart).
Dynamic Checkout Token Management: Manages the creation and usage of unique checkout tokens to identify individual checkout sessions.

Notes#

URL Parameter Handling: Ensure that the URL parameters are correctly processed to determine the type of checkout (quote or cart).
Token Management: Make sure that tokens are securely handled and managed, and ensure proper handling of cases where tokens might expire or need to be regenerated.
API Integration: Ensure that the endpoints for starting checkouts (/api/checkout/start/quote/{checkoutToken}/{quoteToken} and /api/checkout/start/{checkoutToken}/{cartToken}) are properly implemented on the server side.
By following this documentation, you can effectively utilize the _startCheckout method to handle the initiation of checkout processes in your application, ensuring that users can transition smoothly from shopping to completing their purchase.
Previous
_calculateCart
Next
_updateCheckout
Built with