Overview
The CartItem entity represents individual products within a customer’s shopping cart. It maintains snapshots of product information and pricing to ensure consistency during the shopping session.
Entity Properties
Name | Type | Required | Description |
---|---|---|---|
cartItemId | UUID | Required | Unique identifier for the cart item |
cartId | UUID | Required | Shopping cart this item belongs to |
productId | UUID | Required | Product being added to cart |
sku | string | Required | Product SKU at time of adding to cart |
productName | string | Required | Product name snapshot at time of adding to cart |
productImage | string | Optional | Product image URL snapshot |
quantity | integer | Required | Quantity of this product in the cart |
unitPrice | decimal | Required | Unit price at time of adding to cart |
totalPrice | decimal | Required | Total price for this line item (quantity × unit price) |
originalPrice | decimal | Optional | Original product price before any discounts |
discountAmount | decimal | Optional | Discount applied to this line item |
productVariant | object | Optional | Product variant details (size, color, etc.) |
isAvailable | boolean | Required | Whether the product is still available |
notes | string | Optional | Customer notes for this item |
addedAt | DateTime | Required | Date and time when item was added to cart |
updatedAt | DateTime | Optional | Date and time when item was last updated |
Relationships
- ShoppingCart: Each cart item belongs to one
ShoppingCart
(identified bycartId
). - Product: Each cart item references one
Product
(identified byproductId
).
Price Calculations
- Total Price = Quantity × Unit Price - Discount Amount
- Savings = Original Price - Unit Price (if applicable)
Examples
- CartItem #1: iPhone 15 Pro, quantity 1, $999.99 unit price, no discount.
- CartItem #2: Running Shoes Size 9, quantity 2, $64.99 unit price (was $129.99).
- CartItem #3: T-Shirt Large/Blue, quantity 3, $19.99 unit price.
Business Rules
- Quantity must be greater than zero
- Unit price is captured at time of adding to maintain consistency
- Product availability is checked when cart is accessed
- Unavailable items are marked but not automatically removed
- Total price is recalculated when quantity changes
- Product snapshots prevent price changes from affecting active carts
- Maximum quantity limits may apply per product type