Acesso Comercial / Docs / Storefront / API
Ctrl K
MUTATION

removeShoppingCartItem

Remove um produto do carrinho ou reduz sua quantidade.

Input

RemoveShoppingCartItemMutationInput!

CampoTipoDescrição
hostnameString!Hostname da loja.
productIdID!ID global Relay do produto a remover.

Retorno

CampoTipoDescrição
shoppingCartShoppingCartCarrinho atualizado após remoção.

Mutation

GraphQL
mutation RemoveItem($input: RemoveShoppingCartItemMutationInput!) {
  removeShoppingCartItem(input: $input) {
    shoppingCart {
      id
      totalPrice
      totalQuantity
      products {
        id
        title
        quantity
      }
    }
  }
}

Variables

JSON
{
  "input": {
    "hostname": "minha-loja",
    "productId": "UHJvZHVjdDphYmMx"
  }
}

Resposta

JSON
{
  "data": {
    "removeShoppingCartItem": {
      "shoppingCart": {
        "id": "Q2FydDp4eXo=",
        "totalPrice": 0,
        "totalQuantity": 0,
        "products": []
      }
    }
  }
}

Fetch

JavaScript
const response = await fetch('/graphql', {
  method: 'POST',
  credentials: 'include',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: `mutation($input: RemoveShoppingCartItemInput!) {
      removeShoppingCartItem(input: $input) {
        shoppingCart { id totalPrice totalQuantity }
      }
    }`,
    variables: { input: { hostname: "minha-loja", productId: "UHJvZHVjdDphYmMx" } }
  })
});

cURL

Bash
curl -X POST https://minha-loja.com/graphql \
  -H "Content-Type: application/json" \
  -b "authJwtClient=YOUR_SESSION_COOKIE" \
  -d '{"query":"mutation { removeShoppingCartItem(input: { hostname: \"minha-loja\", productId: \"UHJvZHVjdDphYmMx\" }) { shoppingCart { id totalPrice } } }"}'