---
title: "Action add_to_cart"
description: "Adds an item to the cart in dialog constants and updates totals."
---

# Action `add_to_cart`

> **System ID:** `action_add_to_cart`

## Description

Reads item fields from constants by paths (dot-notation), adds a line item to the cart, and recalculates `total.count` / `total.sum`. If the cart does not exist yet — creates a new one. Required for adding: model, id, and price.

## Events (scenario branches)

| Event | When it occurs |
|-------|----------------|
| **success** | Item added |
| **error** | Required fields missing (`item_model`, `item_id`, or `price`) |

## Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `item_model` | string | yes | — | Path to the model in constants (e.g. `product.model`) |
| `item_id` | string | yes | — | Path to the ID (e.g. `product.id`) |
| `price` | string | yes | — | Path to the price (e.g. `product.price`) |
| `count` | string | no | `1` | Path to quantity; if no value — `1` |
| `attributes` | string | no | — | Path to the attributes object |
| `save_to` | string | no | `cart` | Cart constant name |

## Configuration example

```json
{
  "item_model": "product.model",
  "item_id": "product.id",
  "price": "product.price",
  "count": "product.quantity",
  "attributes": "product.attributes",
  "save_to": "cart"
}
```

## Related docs

- [Actions reference](/en/actionjail/reference/actions-reference.md)
