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>
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>;
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[]>
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[] | []>
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>
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>
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>>
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>
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>
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>
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;}>
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');