Verifica se um código de cupom é válido para o carrinho atual sem aplicá-lo.
CheckCouponOnShoppingCartMutationInput!
| Campo | Tipo | Descrição |
|---|---|---|
| hostname | String! | Hostname da loja. |
| code | String! | Código do cupom a verificar. |
| Campo | Tipo | Descrição |
|---|---|---|
| coupon | Coupon | Dados do cupom se válido. |
| isValid | Boolean | Se o cupom é válido para o carrinho. |
mutation CheckCoupon($input: CheckCouponOnShoppingCartMutationInput!) {
checkCouponOnShoppingCart(input: $input) {
isValid
coupon {
code
discountPercentage
discountValue
}
}
} {
"input": {
"hostname": "minha-loja",
"code": "DESCONTO10"
}
} {
"data": {
"checkCouponOnShoppingCart": {
"isValid": true,
"coupon": {
"code": "DESCONTO10",
"discountPercentage": 10,
"discountValue": null
}
}
}
} const response = await fetch('/graphql', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `mutation($input: CheckCouponOnShoppingCartInput!) {
checkCouponOnShoppingCart(input: $input) {
shoppingCart { id totalPrice totalDiscount coupon { code discountPercentage } }
}
}`,
variables: { input: { hostname: "minha-loja", couponCode: "DESCONTO10" } }
})
}); curl -X POST https://minha-loja.com/graphql \
-H "Content-Type: application/json" \
-b "authJwtClient=YOUR_SESSION_COOKIE" \
-d '{"query":"mutation { checkCouponOnShoppingCart(input: { hostname: \"minha-loja\", couponCode: \"DESCONTO10\" }) { shoppingCart { totalDiscount } } }"}'