The "Add to Cart" functionality was still using the real database. I've now fully mocked the cart system so it works entirely with in-memory data when mock mode is enabled.
Added in-memory cart storage with methods:
- ✅
addToCart(productId, quantity)- Add items to mock cart - ✅
getCart()- Get current cart contents - ✅
clearCart()- Clear all cart items - ✅
removeFromCart(productId)- Remove specific item - ✅
updateCartItemQuantity(productId, quantity)- Update quantities
Added mock implementations for:
- ✅
addToCart(AddToCartRequest)- Mock add to cart API - ✅
getCart()- Mock get cart API
Updated to pass CartApi to the MockApiWrapper:
MockApiWrapper.init(productApi, authApi, cartApi);Changed from:
ApiClient.cart().addToCart(...)To:
MockApiWrapper.addToCart(...)Changed from:
ApiClient.cart().getCart()To:
MockApiWrapper.getCart()-
Add to Cart:
- Click "Add to Cart" on any product
- Items are stored in memory (not database)
- Instant response (no network call)
- Success message shown
-
View Cart:
- Open cart screen
- Shows all items added during this session
- Data loaded from memory (not database)
- No API or database required!
-
Cart Persistence:
- Cart data stored in memory during app runtime
- Cleared when app is closed/restarted
- Perfect for testing without database setup
- Everything uses real API and database
- Full functionality with backend server
-
Login:
- Username:
admin - Password:
admin1234
- Username:
-
Browse Products:
- See 8 gaming products
-
Add to Cart:
- Click any product
- Click "Add to Cart" button
- Adjust quantity (use +/- buttons)
- Click "Confirm"
- Should see: "Đã thêm X [product] vào giỏ" ✅
-
View Cart:
- Click cart icon in toolbar
- See all added items
- Shows product image, name, price, quantity ✅
-
Add More Items:
- Go back to product list
- Add different products
- Add same product again (quantity increases) ✅
-
Verify Mock Mode:
- No database connection needed
- No backend server needed
- Everything works offline! 🎉
✅ Add items - Multiple products, multiple quantities
✅ Update quantities - Add same item increases quantity
✅ View cart - See all cart items with details
✅ Product data - Full product info (name, price, image)
✅ Session-based - Persists during app runtime
✅ No database - Pure in-memory storage
✅ No API calls - Instant responses
| Feature | Mock Mode (ON) | Real Mode (OFF) |
|---|---|---|
| Add to Cart | ✅ In-memory | ❌ Needs API |
| View Cart | ✅ In-memory | ❌ Needs API |
| Products | ✅ 8 mock items | ❌ Needs API |
| Login | ✅ 3 mock users | ❌ Needs API |
| Database | ✅ Not needed | ❌ Required |
| Backend | ✅ Not needed | ❌ Required |
| Internet | ✅ Not needed | ❌ Required |
- ✅ Login with mock users
- ✅ Browse mock products
- ✅ View product details
- ✅ Add items to cart (NEW!)
- ✅ View cart contents (NEW!)
- ✅ Update quantities (NEW!)
- ✅ All offline, no database needed!
- 📱 UI testing
- 🎨 Design reviews
- 👥 Demo presentations
- 🧪 Feature development
- 🚀 Rapid prototyping
To Enable Mock Cart (Already Enabled):
// In MockDataProvider.java
public static final boolean USE_MOCK_DATA = true;To Use Real Cart:
public static final boolean USE_MOCK_DATA = false;Check: Make sure USE_MOCK_DATA = true in MockDataProvider.java
Solution: Rebuild the project to apply all changes
Expected: Mock cart clears when app restarts (by design for testing)
Solution: Add this to your code:
MockDataRepository.clearCart();All cart functionality is now mocked! 🎉
- ✅ Add to cart - works without database
- ✅ View cart - works without database
- ✅ Update quantities - works without database
- ✅ Mock data for products, users, and cart
- ✅ Easy toggle between mock and real API
- ✅ Zero dependencies on backend server
Ready to test! Build and run the app - everything should work perfectly now! 🚀