deleteCart(cartInput)

Deletes a cart in a webstore.

Syntax 

1import { deleteCart } from 'lightning/commerceCartApi';
2deleteCart(cartInput: object): Promise<void>

Commerce API Resource 

1DELETE /commerce/webstores/{webstoreId}/carts/{activeCartOrId}

deleteCart uses this Commerce API resource.

Parameters 

  • webstoreId—(Required) The ID of the webstore. The ID prefix is 0ZE.
  • activeCartOrId—(Required) The ID of the cart to delete, or the string active to target the buyer’s active cart.
  • version—(Required) The API version for the adapter, for example, v62.0. Without this parameter, the call doesn’t fire.
  • effectiveAccountId—(Optional) The effective account ID for the cart operation.

Returns 

The return type is void. On success, the server returns 204 No Content. On error, the Promise rejects with an error object containing an errorCode and a message.

Usage 

deleteCart is an imperative function, not a @wire adapter. Call it in response to a user action.

1import { LightningElement, api } from 'lwc';
2import { deleteCart } from 'lightning/commerceCartApi';
3
4export default class DeleteCartExample extends LightningElement {
5  @api webstoreId;
6  @api cartId;
7
8  async handleDeleteCart() {
9    try {
10      await deleteCart({
11        webstoreId: this.webstoreId,
12        activeCartOrId: this.cartId,
13        version: 'v62.0',
14      });
15      console.log('Cart deleted successfully');
16    } catch (error) {
17      console.error('Error deleting cart:', error);
18    }
19  }
20}

Error Handling 

If the call fails, the Promise rejects with an error object containing an errorCode and a message.

See Also