Hernando Abella

E-commerce Storefront · Step 4 of 7

Create product details and add-to-cart

Add an add-to-cart action that increases an existing line instead of duplicating it. Decide how unavailable or out-of-stock products behave.

Understand

Cart state represents a domain rule: one line per product with a valid quantity.

Build

Create a CartItem model referencing the product ID, then implement add, remove, and quantity update operations as small pure functions.

Check

Adding twice increments quantity, invalid quantities are rejected, and unavailable items cannot be added.

Try it

Explain what should happen when a shopper lowers the quantity to zero, then implement that rule consistently.