update cart/favorite
This commit is contained in:
@@ -60,6 +60,48 @@ class FavoriteProductsLocalDataSource {
|
||||
bool isBoxOpen() {
|
||||
return Hive.isBoxOpen(HiveBoxNames.favoriteProductsBox);
|
||||
}
|
||||
|
||||
/// Check if a product is in favorites (local only - no API call)
|
||||
bool isFavorite(String productId) {
|
||||
try {
|
||||
return _box.containsKey(productId);
|
||||
} catch (e) {
|
||||
_debugPrint('Error checking favorite: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all favorite product IDs (local only - no API call)
|
||||
Set<String> getFavoriteIds() {
|
||||
try {
|
||||
return _box.keys.cast<String>().toSet();
|
||||
} catch (e) {
|
||||
_debugPrint('Error getting favorite IDs: $e');
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a product to local favorites cache
|
||||
Future<void> addFavorite(ProductModel product) async {
|
||||
try {
|
||||
await _box.put(product.productId, product);
|
||||
_debugPrint('Added to local favorites: ${product.productId}');
|
||||
} catch (e) {
|
||||
_debugPrint('Error adding to local favorites: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a product from local favorites cache
|
||||
Future<void> removeFavorite(String productId) async {
|
||||
try {
|
||||
await _box.delete(productId);
|
||||
_debugPrint('Removed from local favorites: $productId');
|
||||
} catch (e) {
|
||||
_debugPrint('Error removing from local favorites: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Debug print helper
|
||||
|
||||
Reference in New Issue
Block a user