update total price

This commit is contained in:
efrilm
2025-10-25 03:03:44 +07:00
parent 013f313e35
commit 0e83d213fc
9 changed files with 401 additions and 60 deletions
@@ -46,30 +46,33 @@ class CheckoutFormBloc extends Bloc<CheckoutFormEvent, CheckoutFormState> {
product: e.product,
quantity: 1,
variant: e.variant,
notes: '',
),
);
}
log('🛒 Items updated: ${items.length} items total');
log('🛒 Items updated: ${items.length} items total ${items.toList()}');
final totalQuantity = items.fold<int>(
0,
(sum, item) => sum + item.quantity,
);
final totalPrice = items.fold<int>(
0,
(sum, item) =>
sum +
(item.quantity *
(item.variant?.priceModifier.toInt() ??
item.product.price.toInt())),
);
final totalPrice = state.items.isEmpty
? 0.0
: state.items
.map(
(e) =>
(e.product.price * e.quantity) +
(e.variant?.priceModifier ?? 0),
)
.reduce((value, element) => value + element);
emit(
currentState.copyWith(
items: items,
totalQuantity: totalQuantity,
totalPrice: totalPrice,
totalPrice: totalPrice.toInt(),
isLoading: false,
),
);