deleteCart
Deletes a cart.
It deletes a cart in commercetools by sending a request to its GraphQL API. By default, it uses the deleteCartDefaultQuery GraphQL query
Signature
declare function deleteCart(
context: CommercetoolsIntegrationContext,
params: DeleteCartParams,
customQuery?: CustomQuery
): Promise<DeleteCartResponse>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | CommercetoolsIntegrationContext | |
params | Required | DeleteCartParams | |
customQuery | Optional | CustomQuery |
Returns
Returns a representation of the DeleteCartResponse.
Referenced Types
Examples
Deleting a cart.
const { cart } = await sdk.commerce.deleteCart({ id: '00035084', version: 1 });Creating a custom GraphQL query for the method in middleware.config.ts.
export const integrations = {
ct: {
// ...
customQueries: {
'delete-cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
mutation deleteCart($id: String, $key: String, $version: Long!, $personalDataErasure: Boolean, $storeKey: KeyReferenceInput, $asAssociate: AsAssociateArgument) {
cart: deleteCart(id: $id, key: $key, version: $version, personalDataErasure: $personalDataErasure, storeKey: $storeKey, asAssociate: $asAssociate) {
${metadata}
}
}
`;
})
}
}
}
};Deleting a cart and using the customQuery parameter to leverage the custom GraphQL query from the previous example. Notice how we are using the type parameter to overwrite the default response interface.
const { cart } = wait sdk.commerce.deleteCart({ id: '00035084', version: 5 }, {
deleteCart: 'delete-cart-custom-query',
metadata: 'id,version'
});