Skip to content

Order Functions

The Order drop-in provides API functions that enable you to programmatically control behavior, fetch data, and integrate with Adobe Commerce backend services.

Version: 1.4.0
FunctionDescription
cancelOrderCalls the cancelOrder mutation.
confirmCancelOrderConfirms the cancellation of an order using the provided order ID and confirmation key.
confirmGuestReturnConfirms a return request for a guest order using an order ID and confirmation key.
getAttributesFormCalls the attributesForm query..
getAttributesListIs a wrapper for the attributesList query.
getCustomerIs a wrapper for the customer query.
getCustomerOrdersReturnReturns details about the returns a customer has requested.
getGuestOrderIs a wrapper for the guestOrder query..
getStoreConfigReturns information about the storefront configuration.
guestOrderByTokenRetrieves a guest order using a token generated by Adobe Commerce.
placeNegotiableQuoteOrderPlaces an order for a negotiable quote.
reorderItemsAllows a logged-in customer to add all the products from a previous order into their cart.
requestGuestOrderCancelIs similar to the cancelOrder function, but it is used for guest orders.
requestGuestReturnInitiates a return request for a guest order.
requestReturnTakes the RequestReturnProps form as an argument and initiates the process of returning items from an order.
setPaymentMethodAndPlaceOrderSets the payment method on a cart and immediately places the order.

cancelOrder

The cancelOrder function calls the cancelOrder mutation. You must pass an order ID and reason.

const cancelOrder = async (
orderId: string,
reason: string,
onSuccess: Function,
onError: Function
): Promise<void | null | undefined>
ParameterTypeReq?Description
orderIdstringYesThe ID of the order to cancel.
reasonstringYesThe reason for canceling the order.
onSuccessFunctionYesThe callback function to execute when the order is successfully canceled.
onErrorFunctionYesThe callback function to execute when an error occurs.

Events

Does not emit any drop-in events.

Returns

Returns void | null | undefined.


confirmCancelOrder

The confirmCancelOrder function confirms the cancellation of an order using the provided order ID and confirmation key. The function calls the confirmCancelOrder mutation.

const confirmCancelOrder = async (
orderId: string,
confirmationKey: string
): Promise<any>
ParameterTypeReq?Description
orderIdstringYesThe ID of the order to cancel.
confirmationKeystringYesA key generated when a guest requests to cancel an order.

Events

Emits the order/data event with the updated order information after confirming the cancellation.

Returns

Returns void.


confirmGuestReturn

The confirmGuestReturn function confirms a return request for a guest order using an order ID and confirmation key. The function calls the confirmReturn mutation.

const confirmGuestReturn = async (
orderId: string,
confirmationKey: string
): Promise<OrderDataModel | null>
ParameterTypeReq?Description
orderIdstringYesThe ID of the order for which the return is being confirmed.
confirmationKeystringYesThe confirmation key sent to the guest’s email address to authorize the return.

Events

Emits the order/data event.

Returns

Returns OrderDataModel or null.


getAttributesForm

The getAttributesForm function calls the attributesForm query.

const getAttributesForm = async (
formCode: string
): Promise<AttributesFormModel[]>
ParameterTypeReq?Description
formCodestringYesOne of “customer_account_create”, “customer_account_edit”, “customer_address_create”, “customer_address_edit”.

Events

Does not emit any drop-in events.

Returns

Returns AttributesFormModel[].


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.

const getAttributesList = async (
entityType: string
): Promise<AttributesFormModel[] | []>
ParameterTypeReq?Description
entityTypestringYesThe entity type for which to retrieve the list of attributes.

Events

Does not emit any drop-in events.

Returns

Returns AttributesFormModel[] | [].


getCustomer

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

const getCustomer = async (): Promise<CustomerDataModelShort>

Events

Does not emit any drop-in events.

Returns

Returns CustomerDataModelShort.


getCustomerOrdersReturn

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

const getCustomerOrdersReturn = async (
pageSize = 10,
currentPage = 1
): Promise<CustomerOrdersReturnModel | null>
ParameterTypeReq?Description
pageSizenumberNoThe number of orders to return at a time.
currentPagenumberNoSee function signature above

Events

Does not emit any drop-in events.

Returns

Returns CustomerOrdersReturnModel or null.


getGuestOrder

The getGuestOrder function is a wrapper for the guestOrder query.

const getGuestOrder = async (
form: { number: string; email: string; lastname: string; }
): Promise<OrderDataModel | null>
ParameterTypeReq?Description
numberstringYesThe order number.
emailstringYesThe email address associated with the order.
lastnamestringYesThe last name associated with the order.

Events

Does not emit any drop-in events.

Returns

Returns OrderDataModel or null.


getStoreConfig

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

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

Events

Does not emit any drop-in events.

Returns

Returns StoreConfigModel or null.


guestOrderByToken

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

const guestOrderByToken = async (
token?: string,
returnRef?: string
): Promise<OrderDataModel | null>
ParameterTypeReq?Description
tokenstringNoA token for the order assigned by Adobe Commerce.
returnRefstringNoThe reference to return.

Events

Does not emit any drop-in events.

Returns

Returns OrderDataModel or null.


placeNegotiableQuoteOrder

The placeNegotiableQuoteOrder function places an order for a negotiable quote. It is a wrapper for the placeNegotiableQuoteOrder mutation. The function calls the placeNegotiableQuoteOrder mutation.

const placeNegotiableQuoteOrder = async (
quoteUid: string
): Promise<OrderDataModel | null | undefined>
ParameterTypeReq?Description
quoteUidstringYesThe unique identifier (UID) of the negotiable quote to place as an order.

Events

Emits the order/placed event.

Returns

Returns OrderDataModel | null | undefined. See OrderDataModel.


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.

const reorderItems = async (
orderNumber: string
): Promise<ReorderItemsProps>
ParameterTypeReq?Description
orderNumberstringYesThe order number to reorder.

Events

Does not emit any drop-in events.

Returns

Returns ReorderItemsProps.


requestGuestOrderCancel

The requestGuestOrderCancel function is similar 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 The function calls the requestGuestOrderCancel mutation.

const requestGuestOrderCancel = async (
token: string,
reason: string,
onSuccess: Function,
onError: Function
): Promise<void>
ParameterTypeReq?Description
tokenstringYesThe token for the order assigned by Adobe Commerce.
reasonstringYesThe reason for canceling the order.
onSuccessFunctionYesThe callback function to execute when the order is successfully canceled.
onErrorFunctionYesThe callback function to execute when an error occurs.

Events

Does not emit any drop-in events.

Returns

Returns void.


requestGuestReturn

The requestGuestReturn function initiates a return request for a guest order. The function calls the requestGuestReturn mutation.

const requestGuestReturn = async (
form: RequestGuestReturnProps
): Promise<{
uid: string;
number: string;
status: string;
createdAt: string;
}>
ParameterTypeReq?Description
formRequestGuestReturnPropsYesThe form data for the guest return request, including order details and items to return.

Events

Does not emit any drop-in events.

Returns

Returns Promise<{ uid: string; number: string; status: string; createdAt: string; }>.


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.

const requestReturn = async (
form: RequestReturnProps
): Promise<RequestReturnModel | {}>
ParameterTypeReq?Description
formRequestReturnPropsYesThe form data for the return request.

Events

Does not emit any drop-in events.

Returns

Returns RequestReturnModel | {}. See RequestReturnModel.


setPaymentMethodAndPlaceOrder

The setPaymentMethodAndPlaceOrder function sets the payment method on a cart and immediately places the order. The function calls the setPaymentMethodOnCart mutation.

const setPaymentMethodAndPlaceOrder = async (
cartId: string,
paymentMethod: any
): Promise<OrderDataModel | null | undefined>
ParameterTypeReq?Description
cartIdstringYesThe ID of the cart to place as an order.
paymentMethodanyYesThe payment method information to apply to the cart before placing the order.

Events

Emits the following events: cart/reset, order/placed.

Returns

Returns OrderDataModel | null | undefined. See OrderDataModel.


Data Models

The following data models are used by functions in this drop-in.

CustomerDataModelShort

The CustomerDataModelShort object is returned by the following functions: getCustomer.

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

CustomerOrdersReturnModel

The CustomerOrdersReturnModel object is returned by the following functions: getCustomerOrdersReturn.

interface CustomerOrdersReturnModel {
ordersReturn: OrdersReturnPropsModel[];
pageInfo?: PageInfoProps;
}

OrderDataModel

The OrderDataModel object is returned by the following functions: confirmGuestReturn, getGuestOrder, guestOrderByToken, placeNegotiableQuoteOrder, setPaymentMethodAndPlaceOrder.

type OrderDataModel = {
giftReceiptIncluded: boolean;
printedCardIncluded: boolean;
giftWrappingOrder: {
price: MoneyProps;
uid: string;
};
placeholderImage?: string;
returnNumber?: string;
id: string;
orderStatusChangeDate?: string;
number: string;
email: string;
token?: string;
status: string;
isVirtual: boolean;
totalQuantity: number;
shippingMethod?: string;
carrier?: string;
orderDate: string;
returns: OrdersReturnPropsModel[];
discounts: { amount: MoneyProps; label: string }[];
coupons: {
code: string;
}[];
payments: {
code: string;
name: string;
}[];
shipping?: { code: string; amount: number; currency: string };
shipments: ShipmentsModel[];
items: OrderItemModel[];
totalGiftCard: MoneyProps;
grandTotal: MoneyProps;
grandTotalExclTax: MoneyProps;
totalShipping?: MoneyProps;
subtotalExclTax: MoneyProps;
subtotalInclTax: MoneyProps;
totalTax: MoneyProps;
shippingAddress: OrderAddressModel;
totalGiftOptions: {
giftWrappingForItems: MoneyProps;
giftWrappingForItemsInclTax: MoneyProps;
giftWrappingForOrder: MoneyProps;
giftWrappingForOrderInclTax: MoneyProps;
printedCard: MoneyProps;
printedCardInclTax: MoneyProps;
};
billingAddress: OrderAddressModel;
availableActions: AvailableActionsProps[];
taxes: { amount: MoneyProps; rate: number; title: string }[];
appliedGiftCards: {
code: string;
appliedBalance: MoneyProps;
}[];
};

ReorderItemsProps

The ReorderItemsProps object is returned by the following functions: reorderItems.

interface ReorderItemsProps {
success: boolean;
userInputErrors: UserInputErrorProps[];
}

RequestReturnModel

The RequestReturnModel object is returned by the following functions: requestReturn.

interface RequestReturnModel {
uid: string;
number: string;
status: string;
createdAt: string;
}

StoreConfigModel

The StoreConfigModel object is returned by the following functions: getStoreConfig.

interface StoreConfigModel {
baseMediaUrl: string;
orderCancellationEnabled: boolean;
orderCancellationReasons: OrderCancellationReason[];
shoppingOrderDisplayPrice: OrderDisplayPriceProps;
shoppingOrdersDisplayShipping: OrderDisplayPriceProps;
shoppingOrdersDisplaySubtotal: OrderDisplayPriceProps;
shoppingOrdersDisplayFullSummary: boolean;
shoppingOrdersDisplayGrandTotal: boolean;
shoppingOrdersDisplayZeroTax: boolean;
salesPrintedCard: number;
salesGiftWrapping: number;
}