Skip to main content

calculateCartImpact

Calculate the total environmental impact of a shopping cart in real-time.
mutation {
  calculateCartImpact(input: {
    sessionId: "session_abc"
    items: [
      { productId: "prod_abc123", quantity: 2 },
      { productId: "prod_def456", quantity: 1 },
      { productId: "prod_ghi789", quantity: 5 }
    ]
    shippingMethod: STANDARD
    shippingAddress: { country: "NL", postalCode: "1012AB" }
  }) {
    totalCo2Equivalent
    totalMkiScore
    shippingImpact
    perItemBreakdown {
      productId
      productName
      quantity
      co2Equivalent
      percentage
    }
    equivalency {
      description
      value
      icon
    }
  }
}
Input:
FieldTypeRequiredDescription
sessionIdString!YesE-commerce session/cart ID
items[CartItemInput!]!YesCart line items
shippingMethodTransportMethodNoDelivery method
shippingAddressAddressInputNoDelivery address

CartItemInput

FieldTypeRequiredDescription
productIdID!YesProduct identifier
quantityInt!YesQuantity

updateCartItem

Update a single item in the cart and get the recalculated impact.
mutation {
  updateCartItem(input: {
    sessionId: "session_abc"
    productId: "prod_abc123"
    quantity: 5
  }) {
    totalCo2Equivalent
    perItemBreakdown {
      productId
      co2Equivalent
      percentage
    }
    equivalency {
      description
      value
    }
  }
}

removeCartItem

Remove an item from the cart.
mutation {
  removeCartItem(input: {
    sessionId: "session_abc"
    productId: "prod_abc123"
  }) {
    totalCo2Equivalent
    perItemBreakdown {
      productId
      co2Equivalent
    }
  }
}

E-commerce integration

For Shopify stores, use the cart token as the sessionId:
const cartImpact = await client.calculateCartImpact({
  sessionId: window.Shopify.cart.token,
  items: cart.items.map(item => ({
    productId: item.variant_id.toString(),
    quantity: item.quantity,
  })),
  shippingAddress: { country: shippingCountry },
});
See the Shopify SDK for a complete integration guide.