updateCartItemQuantity method

Future<void> updateCartItemQuantity(
  1. String productId,
  2. int newQuantity
)

Updates the quantity of a cart item in Firestore.

Parameters:

  • productId: The ID of the product whose quantity is to be updated.
  • newQuantity: The new quantity for the cart item.

Returns: A Future<void> that completes when the quantity is updated.

Implementation

Future<void> updateCartItemQuantity(String productId, int newQuantity) async {
  try {
    await _firestore
        .collection('carts')
        .doc(userId)
        .collection('items')
        .doc(productId)
        .update({'quantity': newQuantity});
  } catch (e) {
    print('Error updating cart item quantity: $e');
  }
}