# Cart item flattening

> Cart item flattening is a process that splits each cart item whose quantity is greater than 1 into individual cart items.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Talon.One always flattens the cart items you send. This enables it to apply per-item
effects to **units** of a given product, instead of only considering all the units of a
given product.

For example, if you run a clothing company and a customer adds two T-shirts and three hats to
their cart, Talon.One flattens the cart items as follows:

:::note
- Talon.One applies per-item discounts to each instance of the item. Using per-item effects
  can lead to **more triggered effects**.
:::

## JSON representation of the flattening

Use the [Update customer session endpoint][cs] to share the details of a session, and
its cart items, to Talon.One.

Cart items are represented by the `cartItems` array inside the payload. For example, if
a customer adds **3 units** of a given item to their cart, you send the following payload
to Talon.One:

```json title="Your payload" {10}
{
  "customerSession": {
    "profileId": "URNGV8294NV",
    // ...
    "state": "open",
    "cartItems": [
      {
        "name": "Candle",
        "sku": "SKU1241028",
        "quantity": 3,
        "price": 15.99,
      }
    ]
}
```

Talon.One processes the cart as follows:

```json title="Internal version of your payload" {10,16,22}
{
  "customerSession": {
    "profileId": "URNGV8294NV",
    // ...
    "state": "open",
    "cartItems": [
      {
        "name": "Candle",
        "sku": "SKU1241028",
        "quantity": 1,
        "price": 15.99,
      },
      {
        "name": "Candle",
        "sku": "SKU1241028",
        "quantity": 1,
        "price": 15.99,
      },
      {
        "name": "Candle",
        "sku": "SKU1241028",
        "quantity": 1,
        "price": 15.99,
      },
    ]
}
```

As a result, if you use **per-item** effects, like a per-item discount applied to all items of
the session, you receive **three effects instead of one**.

## Related pages

- [Per-item effects](/docs/product/rules/effects/overview.md)
- [Return individual items](/docs/dev/tutorials/partially-return-a-session.md)
- [API effects](/docs/dev/integration-api/api-effects.md#setdiscountperitem)

[cs]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
