update cart/favorite
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/features/cart/domain/entities/cart_item.dart';
|
||||
|
||||
part 'cart_item_model.g.dart';
|
||||
|
||||
/// Cart Item Model - Type ID: 5
|
||||
///
|
||||
/// Includes product details from cart API to avoid fetching each product.
|
||||
@HiveType(typeId: HiveTypeIds.cartItemModel)
|
||||
class CartItemModel extends HiveObject {
|
||||
CartItemModel({
|
||||
@@ -14,6 +17,9 @@ class CartItemModel extends HiveObject {
|
||||
required this.unitPrice,
|
||||
required this.subtotal,
|
||||
required this.addedAt,
|
||||
this.itemName,
|
||||
this.image,
|
||||
this.conversionOfSm,
|
||||
});
|
||||
|
||||
@HiveField(0)
|
||||
@@ -37,6 +43,18 @@ class CartItemModel extends HiveObject {
|
||||
@HiveField(6)
|
||||
final DateTime addedAt;
|
||||
|
||||
/// Product name from cart API
|
||||
@HiveField(7)
|
||||
final String? itemName;
|
||||
|
||||
/// Product image URL from cart API
|
||||
@HiveField(8)
|
||||
final String? image;
|
||||
|
||||
/// Conversion factor (m² to tiles) from cart API
|
||||
@HiveField(9)
|
||||
final double? conversionOfSm;
|
||||
|
||||
factory CartItemModel.fromJson(Map<String, dynamic> json) {
|
||||
return CartItemModel(
|
||||
cartItemId: json['cart_item_id'] as String,
|
||||
@@ -67,6 +85,9 @@ class CartItemModel extends HiveObject {
|
||||
double? unitPrice,
|
||||
double? subtotal,
|
||||
DateTime? addedAt,
|
||||
String? itemName,
|
||||
String? image,
|
||||
double? conversionOfSm,
|
||||
}) => CartItemModel(
|
||||
cartItemId: cartItemId ?? this.cartItemId,
|
||||
cartId: cartId ?? this.cartId,
|
||||
@@ -75,5 +96,22 @@ class CartItemModel extends HiveObject {
|
||||
unitPrice: unitPrice ?? this.unitPrice,
|
||||
subtotal: subtotal ?? this.subtotal,
|
||||
addedAt: addedAt ?? this.addedAt,
|
||||
itemName: itemName ?? this.itemName,
|
||||
image: image ?? this.image,
|
||||
conversionOfSm: conversionOfSm ?? this.conversionOfSm,
|
||||
);
|
||||
|
||||
/// Convert to domain entity
|
||||
CartItem toEntity() => CartItem(
|
||||
cartItemId: cartItemId,
|
||||
cartId: cartId,
|
||||
productId: productId,
|
||||
quantity: quantity,
|
||||
unitPrice: unitPrice,
|
||||
subtotal: subtotal,
|
||||
addedAt: addedAt,
|
||||
itemName: itemName,
|
||||
image: image,
|
||||
conversionOfSm: conversionOfSm,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user