query GetCart($hostname: String!) {
shoppingCart(hostname: $hostname) {
id
totalPrice
originalTotalPrice
isShippingCalculated
maximumInstallments
coupon {
code
discountPercentage
}
products {
id
title
price
finalPrice
quantity
availableQuantity
images { url }
variation { name value }
}
shippingOptions {
code
name
totalValue
totalDeliveryTime
}
totalPriceByPaymentMethod {
paymentMethod
totalPrice
}
}
}
{
"data": {
"shoppingCart": {
"id": "U2hvcHBpbmdDYXJ0Onh5eg==",
"totalPrice": 17980,
"originalTotalPrice": 19980,
"isShippingCalculated": true,
"maximumInstallments": 12,
"coupon": null,
"products": [
{
"id": "U2hvcHBpbmdDYXJ0UHJvZHVjdDphYmMx",
"title": "Camiseta Premium",
"price": 8990,
"finalPrice": 8990,
"quantity": 2,
"availableQuantity": 42,
"images": [{ "url": "https://..." }],
"variation": { "name": "Tamanho", "value": "M" }
}
],
"shippingOptions": [
{
"code": "SEDEX",
"name": "Sedex",
"totalValue": 1500,
"totalDeliveryTime": 3
},
{
"code": "PAC",
"name": "PAC",
"totalValue": 800,
"totalDeliveryTime": 7
}
],
"totalPriceByPaymentMethod": [
{ "paymentMethod": "pix", "totalPrice": 16182 },
{ "paymentMethod": "credit_card", "totalPrice": 17980 }
]
}
}
}
const response = await fetch(
'/graphql',
{
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `query($hostname: String!) {
shoppingCart(hostname: $hostname) {
id totalPrice totalPriceByPaymentMethod { paymentMethod totalPrice }
products { id title price quantity }
}
}`,
variables: { hostname: "minha-loja" }
})
}
);
const data = await response.json();