Cart & Checkout¶
Source: pharmanet/lib/features/cart/
Pages¶
| Page | File | Description |
|---|---|---|
CartPage |
features/cart/presentation/pages/cart_page.dart |
Cart items list with quantity controls |
CheckoutPage |
features/cart/presentation/pages/checkout_page.dart |
Order review, address, payment method |
Providers¶
| Provider | Type | Description |
|---|---|---|
cartProvider |
NotifierProvider<List<CartItem>> |
Local cart state (Backed by Supabase carts table) |
addressesProvider |
AsyncNotifierProvider<List<Address>> |
User's saved addresses |
selectedAddressProvider |
NotifierProvider<Address?> |
Currently selected shipping address |
Cart Features¶
- Add/remove items with quantity stepper
- Persistent across sessions (synced to Supabase
cart_itemstable) - Real-time price updates (offer-aware via
activeOffersMapProvider) - Empty state with "Start Shopping" CTA
- Swipe-to-delete
Checkout Flow¶
sequenceDiagram
participant U as User
participant C as CheckoutPage
participant P as Providers
participant S as Supabase
participant CP as Chapa
U->>C: Review cart items
C->>P: Fetch addresses
P-->>C: Address list
U->>C: Select shipping address
C->>P: Calculate totals (subtotal + shipping)
P-->>C: Total amount
U->>C: Choose payment method
C->>S: Create order (pending payment)
S-->>C: Order ID
C->>CP: Initialize payment
CP-->>U: Hosted checkout page
U->>CP: Complete payment
CP-->>C: Callback with tx_ref
C->>S: Update payment status
S-->>C: Success → navigate to order confirmation
API: Cart¶
Source: pharmanet/lib/core/api/cart_api.dart
| Method | Description |
|---|---|
fetchCart() |
Get user's cart with items |
createCart() |
Create new cart |
addToCart(productId, variantCombinationId, quantity) |
Add item |
updateCartItemQuantity(itemId, quantity) |
Update quantity |
removeFromCart(itemId) |
Remove item |
clearCart() |
Clear entire cart |
API: Order (creation)¶
Source: pharmanet/lib/core/api/order_api.dart
| Method | Description |
|---|---|
createOrder(items, shippingAddress, paymentMethod, notes) |
Create order + notify sellers + admins |
On order creation, NotificationService.notifySellers() and notifyAdmins() are called automatically.