update cart/favorite

This commit is contained in:
Phuoc Nguyen
2025-12-03 15:53:46 +07:00
parent e1c9f818d2
commit 27798cc234
19 changed files with 370 additions and 119 deletions

View File

@@ -190,15 +190,21 @@ class CartRemoteDataSourceImpl implements CartRemoteDataSource {
try {
// Map API response to CartItemModel
// API fields: name, item, quantity, amount, item_code, item_name, image, conversion_of_sm
final quantity = (item['quantity'] as num?)?.toDouble() ?? 0.0;
final unitPrice = (item['amount'] as num?)?.toDouble() ?? 0.0;
final cartItem = CartItemModel(
cartItemId: item['name'] as String? ?? '',
cartId: 'user_cart', // Fixed cart ID for user's cart
productId: item['item_code'] as String? ?? item['item'] as String? ?? '',
quantity: (item['quantity'] as num?)?.toDouble() ?? 0.0,
unitPrice: (item['amount'] as num?)?.toDouble() ?? 0.0,
subtotal: ((item['quantity'] as num?)?.toDouble() ?? 0.0) *
((item['amount'] as num?)?.toDouble() ?? 0.0),
quantity: quantity,
unitPrice: unitPrice,
subtotal: quantity * unitPrice,
addedAt: DateTime.now(), // API doesn't provide timestamp
// Product details from cart API - no need to fetch separately
itemName: item['item_name'] as String?,
image: item['image'] as String?,
conversionOfSm: (item['conversion_of_sm'] as num?)?.toDouble(),
);
cartItems.add(cartItem);