Add to Cart
Add a product to the shopping cart with specified quantity and attributes.
Endpoint
POST /api/shop/cart/itemsRequest Headers
| Header | Required | Description |
|---|---|---|
Content-Type | Yes | application/json |
X-STOREFRONT-KEY | Yes | Your storefront API key |
Request Body
json
{
"productId": 1,
"quantity": 2,
"attributes": {
"color": "Black",
"size": "Large"
}
}| Field | Type | Required | Description |
|---|---|---|---|
productId | integer | Yes | Product ID to add |
quantity | integer | Yes | Quantity (minimum 1) |
attributes | object | No | Product attributes (color, size, etc.) |
Response Fields (201 Created)
| Field | Type | Description |
|---|---|---|
id | integer | Cart item ID |
productId | integer | Product ID |
productName | string | Product name |
quantity | integer | Quantity added |
price | decimal | Unit price |
subtotal | decimal | Line item total |
attributes | object | Selected attributes |
Response Metadata
| Field | Type | Description |
|---|---|---|
message | string | Success message |
cartTotal | decimal | Updated cart total |
Behavior
- If product already in cart, quantity is increased
- Stock validation performed
- Price calculated at time of addition
- Attributes are validated for configurable products
Use Cases
- Add product to cart from product page
- Update quantity by adding more
- Support cart on product detail pages
- Build "Quick Add" functionality

