Checkout functions
This topic provides the details and instructions you need to use the functions provided by the checkout drop-in component.
authenticateCustomer
The authenticateCustomer
function manages the authentication state of a customer, either by fetching customer data using the getCustomer
function when authenticated or resetting the customer data when not authenticated.
Returns
The function does not return any value explicitly; it performs side effects by fetching data and logging errors.
Usage
See the following example for usage details:
estimateShippingMethods
The estimateShippingMethods
function fetches and displays available shipping methods based on a customer’s address information. It can take a combination of fields as criteria
: country, region, region identifier, and postal code.
It uses a utility function to call an estimateShippingMethods
mutation.
Returns
Returns a promise that resolves to an array of ShippingMethod
objects (or undefined
if no shipping methods are available) fetched from the API.
Usage
See the following example for usage details:
getCart
The getCart
function fetches the cart details for either a guest user or an authenticated customer.
Returns
Returns a promise that resolves to the transformed cart data fetched from the API.
Usage
See the following example for usage details:
getCheckoutData
The getCheckoutData
function fetches and prepares the necessary data for the checkout process. It uses the getCart
and getCustomer
functions to fetch the cart and customer data.
Returns
The function does not return any value explicitly; it performs side effects by fetching data and logging errors.
Usage
See the following example for usage details:
getCustomer
The getCustomer
function fetches customer details for an authenticated user using the customer
query.
Returns
The function returns a promise that resolves to the transformed customer data fetched from the API or undefined
if the user is not authenticated.
The Customer
object is returned:
Usage
See the following example for usage details:
getStoreConfig
The getStoreConfig
function fetches information about a store’s configuration settings using the storeConfig
query.
You can query a non-default store by changing the header in your GraphQL request.
Returns
The function returns a promise that resolves to the transformed store configuration data fetched from the API.
If the API call fails, it returns the default store configuration settings (STORE_CONFIG_DEFAULTS
).
Usage
See the following example for usage details:
initializeCheckout
The initializeCheckout
function initializes the checkout process by fetching necessary configuration and data from various Adobe Commerce GraphQL APIs using the following functions:
fetchAddressFormFields
getCountries
getStoreConfig
Returns
The function returns a promise that resolves to an array containing the results of the three API calls.
Usage
See the following example for usage details:
isEmailAvailable
The isEmailAvailable
function checks whether the specified email has already been used to create a customer account using the isEmailAvailable
query.
A value of true
indicates that the email address is available and the customer can use the email address to create an account. As of Adobe commerce 2.4.7, the default value is true
.
Returns
A promise that resolves to an EmailAvailability
object indicating whether the email is available.
Usage
See the following example for usage details:
placeOrder
The placeOrder
function handles the process of placing an order in the checkout system using the placeOrder
mutation.
It publishes the place-order
Adobe Commerce Event within the order
and shoppingCart
contexts to the Adobe Client Data Layer (ACDL).
Returns
The transformed order data fetched from the API.
Usage
See the following example for usage details:
redirect
The redirect
function redirects the user to a specific URL. It takes a single parameter (url
) of type string
, which represents the URL to redirect to.
Usage
See the following example for usage details:
resetCheckout
The resetCheckout
function resets the checkout process to its initial state by clearing the cart data.
Usage
See the following example for usage details:
resetCustomer
The resetCustomer
function clears the current customer information and resets the customer state to its inital value in the checkout process.
Usage
See the following example for usage details:
setBillingAddress
The setBillingAddress
function sets the billing address for a specific cart using the setBillingAddressOnCart
Adobe Commerce GraphQL mutation.
It takes an input
parameter where BillingAddressInput
is an interface that contains the specific properties for the billing address:
Returns
The function returns a promise that resolves to the transformed cart data fetched from the API.
Usage
To set the billing address as the same as the shipping address:
To set a specific billing address:
setGuestEmailOnCart
The setGuestEmailOnCart
function sets the email address for a guest user on the cart using the setGuestEmailOnCart
mutation.
Returns
The function returns a promise that resolves to the transformed cart data fetched from the API.
Usage
See the following example for usage details:
setPaymentMethod
The setPaymentMethod
function sets the provided payment method for the current cart using the setPaymentMethodOnCart
mutation.
It takes the following parameter: paymentMethod
.
Returns
The function returns a promise that resolves to the transformed cart data fetched from the API.
Usage
See the following example for usage details:
setShippingAddress
The setShippingAddress
function sets the shipping address for a specific cart using the setShippingAddressesOnCart
mutation.
Returns
The function returns a promise that resolves to the transformed cart data fetched from the API.
Usage
See the following example for usage details:
setShippingMethodsOnCart
The setShippingMethodsOnCart
function sets the shipping methods for a specific cart using the setShippingMethodsOnCart
mutation.
Returns
The function returns a promise that resolves to the transformed cart data fetched from the API.
Usage
See the following example for usage details:
synchronizeCheckout
The synchronizeCheckout
function synchronizes the checkout state with the current cart information. It ensures that the checkout process is properly initialized, reset, or updated based on the cart data. It uses the getCart
function to fetch the necessary cart details.
Returns
The function does not return any value explicitly; it performs side effects by fetching data and logging errors.
Usage
See the following example for usage details: