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
If you are using commercetools stores, this method deletes the cart within the current store. By default, its key is read from the vsf-store cookie. However, you can overwrite it by using the customQuery parameter. Refer to the Examples section for more details.
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. We can use it to specify response fields as well as overwrite certain query variables (e.g. storeKey).
export const integrations = {
ct: {
// ...
customQueries: {
'delete-cart-custom-query': ({ variables, metadata }) => {
variables.storeKey = metadata.storeKey;
return {
variables,
query: `
mutation deleteCart($id: String!, $version: Long!, $storeKey: KeyReferenceInput) {
cart: deleteMyCart(id: $id, version: $version, storeKey: $storeKey) {
${metadata.fields}
}
}
`;
}
}
}
}
}
};Deleting a cart from a specific store using the custom GraphQL query from the previous example.
const { cart } = await sdk.commerce.deleteCart({ id: '00035084', version: 5 }, {
deleteCart: 'delete-cart-custom-query',
metadata: { storeKey: 'store-fr', fields: 'id,version' }
});