setCartAsInactive mutation

data-variant=info
data-slots=text
This mutation is available automatically on Adobe Commerce as a Cloud Service. On Adobe Commerce on Cloud and on-premises instances, you must install Payment Services for Adobe Commerce 2.10.0 or higher to use this mutation.

The setCartAsInactive mutation sets a specific cartId as inactive. Use this mutation when a payment error occurs, or when a shopper cancels a payment flow, after the addProductsToNewCart mutation returns a cartId. This mutation helps prevent a customer having multiple active carts created with the addProductsToNewCart mutation.

See the addProductsToNewCart mutation use case for more information about a common workflow for the setCartAsInactive mutation.

Syntax

mutation {
    setCartAsInactive(
        cartId: String!
    ): SetCartAsInactiveOutput
    }

Reference

The setCartAsInactive reference provides detailed information about the types and fields defined in this mutation.

Example usage

The following examples show responses to the setCartAsInactive mutation.

Request:

mutation {
    setCartAsInactive(
        cartId: "gVFVNBSJPt7L6uCQis4Q1ryj6DQtcwM2"
    ) {
           success
           error 
        }
    }

Set cart as inactive (success)

The following response example shows what the mutation returns when setCartAsInactive is successful, and no error.

Response:

{
    "data": {
        "setCartAsInactive": {
            "success": true,
            "error": null
        }
    }
}

Set cart as inactive (failure)

The following example response indicates the mutation failed due to a non-existent cartId.

Response:

{
    "data": {
        "setCartAsInactive": {
            "success": false,
            "error": "Error when setting the cart gVFVNBSJPt7L6uCQis4Q1ryj6QtcwM2 as inactive - No such entity with cartId = null "
        }
    }
}