FreshCart has an HTML/JavaScript frontend and a Django JSON API. Trace requests
across that boundary and fix two independent backend bugs. Products and
categories live in SQLite; the cart lives in the customer's Django session.
The frontend is correct. Change only backend/store/views.py; preserve the
tests, models, URLs, and session-based cart. Each fix should be small and local.
Run Tests executes the current task with Django's HTTP test client and an
isolated SQLite database. Run Code executes the full 12-test suite. No local
setup is needed. Open Preview and start the store to reproduce the bugs
visually. After editing the backend, use Apply changes & restart to load your
code; this resets the cart. Expand API requests to inspect responses.
README.md also explains how to run both apps locally.
Clicking Add to cart sends POST /api/cart/add/<product_id>/ with no
request body. The response is 200 OK with {"ok": true}, but the
following GET /api/cart/ returns {"items": [], "total": "0.00"}.
Adding the same product again still leaves the cart empty.
Fix the backend so an added product appears with quantity 1, and adding
it again increases the quantity. The cart must persist between requests
in the existing Django session, with product IDs stored as string keys
and quantities as integer values. Keep unavailable products excluded.
Removing a manually seeded cart item already works and must keep working.
The frontend sends the session cookie using credentials: "include".
Compare the add response with the subsequent cart response, then trace
the handlers that read and write the session. Do not change any public
interface or introduce a database-backed cart.
test_added_item_is_stored_in_the_session
test_adding_twice_increments_quantity
test_added_item_shows_in_cart_response
test_cart_total_is_correct
test_remove_deletes_item_from_session