> ## Documentation Index
> Fetch the complete documentation index at: https://docs.heychocolate.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Shopping Cart

> Mutations for real-time shopping cart sustainability calculations.

## calculateCartImpact

Calculate the total environmental impact of a shopping cart in real-time.

```graphql theme={null}
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:**

| Field             | Type               | Required | Description                |
| ----------------- | ------------------ | -------- | -------------------------- |
| `sessionId`       | String!            | Yes      | E-commerce session/cart ID |
| `items`           | \[CartItemInput!]! | Yes      | Cart line items            |
| `shippingMethod`  | TransportMethod    | No       | Delivery method            |
| `shippingAddress` | AddressInput       | No       | Delivery address           |

### CartItemInput

| Field       | Type | Required | Description        |
| ----------- | ---- | -------- | ------------------ |
| `productId` | ID!  | Yes      | Product identifier |
| `quantity`  | Int! | Yes      | Quantity           |

## updateCartItem

Update a single item in the cart and get the recalculated impact.

```graphql theme={null}
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.

```graphql theme={null}
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`:

```javascript theme={null}
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](/apps/sdks/shopify) for a complete integration guide.
