Alokai
You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current

deleteCart

Method deleting a cart with a given identifier in commercetools.

This method sends a POST request to the deleteCart endpoint of the Vue Storefront API Middleware. In turn, it deletes a cart in commercetools by sending a request to its GraphQL API. default GraphQL query used by this method can be found here.

Signature

export declare function deleteCart<Res extends PartialDeleteCartResponse = DeleteCartResponse>(
	params: DeleteCartParams,
	options?: MethodOptions<CustomQuery<"deleteCart">>
): Promise<Res>;

Parameters

NameRequiredTypeDescription
paramsRequiredDeleteCartParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodOptions<CustomQuery<"deleteCart">>Options that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of the DeleteCartResponse.

Referenced Types

Examples

Deleting a cart.

import { sdk } from '~/sdk.config.ts';

const { cart } = await sdk.commerce.deleteCart({ id: '00035084', version: 1 });

Creating a custom GraphQL query for the method in middleware.config.js.

module.exports = {
  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.

import { sdk } from '~/sdk.config.ts';

type CustomDeleteCartResponse = {
 cart: {
   id: string;
   version: string;
   }
}

const { cart } = wait sdk.commerce.deleteCart<CustomDeleteCartResponse>({ id: '00035084', version: 5 }, {
  customQuery: {
    deleteCart: 'delete-cart-custom-query',
    metadata: 'id,version'
  }
});

On this page