Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Order functions

The Order drop-in component provides the following API endpoints, allowing developers to perform various account-related operations and create custom implementations:

cancelOrder

The cancelOrder function is a wrapper for the cancelOrder mutation. You must pass an order ID and reason,

export const cancelOrder = async (
orderId: string,
reason: string,
onSuccess: Function,
onError: Function
): Promise<void | null | undefined>
Parameter Type Req? Description
orderIdstringYes The ID of the order to cancel.
reasonstringYes The reason for canceling the order.
onSuccessFunctionNo The callback function to execute when the order is successfully canceled.
onErrorFunctionNo The callback function to execute when an error occurs.

Returns

Returns a promise that resolves to a void, null, or undefined value.

Usage

cancelOrder(
{
orderId: '12345',;
reason: 'I don't like the color;
}
)

confirmCancelOrder

The confirmCancelOrder function confirms the cancellation of an order after the guest user clicks on a URL provided in an order cancellation confirmation email. The confirmation key is generated when the guest requests to cancel an order.

confirmCancelOrder(
orderId: string,
confirmationKey: string
): Promise<OrderDataModel>;
Parameter Type Req? Description
orderIdstringYes The ID of the order to cancel.
confirmationKeystringYes A key generated when a guest requests to cancel an order.

Returns

Returns a promise that resolves to an OrderDataModel object.

type OrderDataModel = {
id: string;
orderStatusChangeDate?: string;
number: string;
email?: string;
token?: string;
status: string;
isVirtual: boolean;
totalQuantity: number;
shippingMethod?: string;
carrier?: string;
coupons: {
code: string;
}[];
payments: {
code: string;
name: string;
}[];
shipping?: { code: string; amount: number; currency: string };
shipments: ShipmentsModel[];
items: OrderItemModel[];
grandTotal: MoneyProps;
subtotal: MoneyProps;
totalTax: MoneyProps;
shippingAddress: OrderAddressModel;
billingAddress: OrderAddressModel;
availableActions: AvailableActionsProps[];
};

Usage

import { confirmCancelOrder } from './confirmCancelOrder';
const orderId = '12345';
const confirmationKey = 'abcde12345';
confirmCancelOrder(orderId, confirmationKey)
.then(response => {
console.log('Order cancellation confirmed:', response);
})
.catch(error => {
console.error('Error confirming order cancellation:', error);
});

getAttributesForm

The getAttributesForm function is a wrapper for the attributesForm query. You must pass an attribute code to retrieve the form.

export const getAttributesForm = async (
formCode: string
): Promise<AttributesFormModel[]>
Parameter Type Req? Description
formCodestringYes One of "customer_account_create", "customer_account_edit", "customer_address_create", "customer_address_edit".

Returns

Returns a promise that resolves to an array of AttributesFormModel objects.

export interface AttributesFormItemsProps {
code?: string;
name?: string;
id?: string;
required?: boolean;
label?: string;
options?: { is_default: boolean; label: string; value: string }[];
entityType?: string;
className?: string;
defaultValue?: string | boolean | number;
fieldType?: FieldEnumList;
multilineCount?: number;
isUnique?: boolean;
orderNumber: number;
isHidden?: boolean;
customUpperCode: string;
validateRules: Record<string, string>[];
}
export interface AttributesFormModel extends AttributesFormItemsProps {}

Usage

getAttributesForm(formCode: 'customer_address_edit');

getAttributesList

The getAttributesList function is a wrapper for the attributesList query. You must pass an attribute code to retrieve the list. The system default values are CUSTOMER, CUSTOMER_ADDRESS, CATALOG_PRODUCT and RMA_ITEM.

export const getAttributesList = async (
entityType: string
): Promise<AttributesFormModel[] | []>
Parameter Type Req? Description
entityTypestringYes The entity type for which to retrieve the list of attributes.

Returns

Returns a promise that resolves to an array of AttributesFormModel objects or an empty array.

export interface AttributesFormItemsProps {
code?: string;
name?: string;
id?: string;
required?: boolean;
label?: string;
options?: { is_default: boolean; label: string; value: string }[];
entityType?: string;
className?: string;
defaultValue?: string | boolean | number;
fieldType?: FieldEnumList;
multilineCount?: number;
isUnique?: boolean;
orderNumber: number;
isHidden?: boolean;
customUpperCode: string;
validateRules: Record<string, string>[];
}
export interface AttributesFormModel extends AttributesFormItemsProps {}

Usage

getAttributesList(entityType: 'RMA_ITEM');

getCustomer

The getCustomer function is a wrapper for the customer query. You must pass a customer ID to retrieve the customer data.

export const getCustomer = async (): Promise<CustomerDataModelShort>

Returns

Returns a promise that resolves to a CustomerDataModelShort object.

export interface CustomerDataModelShort {
firstname: string;
lastname: string;
email: string;
}

Usage

getCustomer();

getCustomerOrdersReturn

The getCustomerOrdersReturn function returns details about the returns a customer has requested. It is a wrapper for the customer query.

export const getCustomerOrdersReturn = async (
pageSize = 10
): Promise<CustomerOrdersReturnModel | null>
Parameter Type Req? Description
pageSizenumberNo The number of orders to return at a time.

Returns

Returns a promise that resolves to a CustomerOrdersReturnModel object or null.

export interface CustomerOrdersReturnModel {
ordersReturn: OrdersReturnPropsModel[];
pageInfo?: PageInfoProps;
}
export interface OrdersReturnItemsPropsModel extends OrderItemModel {
quantity: number;
requestQuantity: number;
status: string;
uid: string;
}
export interface PageInfoProps {
pageSize: number;
totalPages: number;
currentPage: number;
}

Usage

The following example demonstrates how to retrieve a customer’s return orders:

getCustomerOrdersReturn();

getGuestOrder

The getGuestOrder function is a wrapper for the guestOrder query.

export const getGuestOrder = async (form: {
number: string;
email: string;
lastname: string;
}): Promise<OrderDataModel | null>
Parameter Type Req? Description
numberstringYes The order number.
emailstringYes The email address associated with the order.
lastnamestringYes The last name associated with the order.

Returns

Returns a promise that resolves to an OrderDataModel object or null.

type OrderDataModel = {
id: string;
orderStatusChangeDate?: string;
number: string;
email?: string;
token?: string;
status: string;
isVirtual: boolean;
totalQuantity: number;
shippingMethod?: string;
carrier?: string;
coupons: {
code: string;
}[];
payments: {
code: string;
name: string;
}[];
shipping?: { code: string; amount: number; currency: string };
shipments: ShipmentsModel[];
items: OrderItemModel[];
grandTotal: MoneyProps;
subtotal: MoneyProps;
totalTax: MoneyProps;
shippingAddress: OrderAddressModel;
billingAddress: OrderAddressModel;
availableActions: AvailableActionsProps[];
};

Usage

The following example demonstrates how to retrieve a guest order:

getGuestOrder({
number: '12345',
email: 'jdoe@example.com',
lastname: 'Doe'
});

getOrderDetailsById

The getOrderDetailsById function is a wrapper for the customer query. You must pass an order ID to retrieve the order details.

export const getOrderDetailsById = async <T extends QueryType>({
orderId,
returnRef,
queryType,
returnsPageSize = 50,
}: GetOrderDetailsByIdProps): Promise<TransformedData<T>>
Parameter Type Req? Description
orderIdstringYes The ID of the order to retrieve.
returnRefbooleanNo Whether to return the reference.
queryTypeQueryTypeNo The type of query to perform. Use orderData as the value
returnsPageSizenumberNo The number of returns to return at a time.

Returns

Returns a promise that resolves to a TransformedData object.

Usage

type QueryType = ‘orderData’;

getOrderDetailsById(
orderId?: string;
queryType: QueryType;
);

getStoreConfig

The getStoreConfig function returns information about the storefront configuration. It is a wrapper for the storeConfig query.

export const getStoreConfig = async (): Promise<StoreConfigModel | null>

Returns

Returns a promise that resolves to a StoreConfigModel object or null.

type StoreConfigModel = {
order_cancellation_enabled: boolean;
order_cancellation_reasons: {
description: string;
};
};

Usage

The following example demonstrates how to retrieve the store configuration:

getStoreConfig();

guestOrderByToken

The guestOrderByToken function retrieves a guest order using a token generated by Adobe Commerce. It is a wrapper for the guestOrderByToken query.

export const guestOrderByToken = async (
token?: string,
returnRef?: string
): Promise<OrderDataModel | null>
Parameter Type Req? Description
tokenstringNo A token for the order assigned by Adobe Commerce.
returnRefstringNo The reference to return.

Returns

Returns a promise that resolves to an OrderDataModel object or null.

type OrderDataModel = {
id: string;
orderStatusChangeDate?: string;
number: string;
email?: string;
token?: string;
status: string;
isVirtual: boolean;
totalQuantity: number;
shippingMethod?: string;
carrier?: string;
coupons: {
code: string;
}[];
payments: {
code: string;
name: string;
}[];
shipping?: { code: string; amount: number; currency: string };
shipments: ShipmentsModel[];
items: OrderItemModel[];
grandTotal: MoneyProps;
subtotal: MoneyProps;
totalTax: MoneyProps;
shippingAddress: OrderAddressModel;
billingAddress: OrderAddressModel;
availableActions: AvailableActionsProps[];
};

Usage

guestOrderByToken(token:'abcde12345');

reorderItems

The reorderItems function allows a logged-in customer to add all the products from a previous order into their cart. It is a wrapper for the reorderItems mutation.

export const reorderItems = async (
orderNumber: string
): Promise<ReorderItemsProps>
Parameter Type Req? Description
orderNumberstringYes The order number to reorder.

Returns

Returns a promise that resolves to a ReorderItemsProps object.

export interface ReorderItemsResponse {
data: {
reorderItems: {
cart: {
itemsV2: {
items: { uid: string }[];
};
};
userInputErrors: UserInputErrorProps[];
};
};
errors?: {
message: string;
}[];
}

Usage

The following example demonstrates how to reorder items from a previous order:

reorderItems(orderNumber: string);

requestGuestOrderCancel

The requestGuestOrderCancel function is simmilar to the cancelOrder function, but it is used for guest orders. The token is a unique value generated using guest’s email, order number and postcode

export const requestGuestOrderCancel = async (
token: string,
reason: string,
onSuccess: Function,
onError: Function
): Promise<void>
Parameter Type Req? Description
tokenstringYes The token for the order assigned by Adobe Commerce.
reasonstringYes The reason for canceling the order.
onSuccessFunctionNo The callback function to execute when the order is successfully canceled.
onErrorFunctionNo The callback function to execute when an error occurs.

Returns

Returns a promise that resolves to a boolean value.

Usage

requestGuestOrderCancel(
{
token: `abcde12345`,;
reason: `It is too big`;
}
): boolean

requestReturn

The requestReturn function takes the RequestReturnProps form as an argument and initiates the process of returning items from an order. It is a wrapper for the requestReturn mutation.

export const requestReturn = async (
form: RequestReturnProps
): Promise<{
uid: string;
number: string;
status: string;
createdAt: string;
}>
Parameter Type Req? Description
formRequestReturnPropsYes The form data for the return request.

The RequestReturnProps object has the following properties:

export interface RequestReturnProps {
orderUid: string;
contactEmail: string;
items: {
orderItemUid: string;
quantityToReturn: number;
selectedCustomAttributes?: { attribute_code: string; value: string }[];
enteredCustomAttributes?: { attribute_code: string; value: string }[];
}[];
}

Returns

Returns a promise that resolves to an object containing the return request details.

Usage

requestReturn(token:'abcde12345');