updateLineItemsInCart method

Future<Cart> updateLineItemsInCart({
  1. required String cartId,
  2. required List<CartLineUpdateInput> cartLineInputs,
})

update line items in cart

Implementation

Future<Cart> updateLineItemsInCart({
  required String cartId,
  required List<CartLineUpdateInput> cartLineInputs,
}) async {
  final lineInputs = cartLineInputs.map((e) => e.toJson()).toList();
  final MutationOptions updateLineItem = MutationOptions(
    document: gql(updateLineItemInCartMutation),
    variables: {
      'cartId': cartId,
      'lines': lineInputs,
      'country': ShopifyLocalization.countryCode,
    },
  );
  QueryResult result = await _graphQLClient!.mutate(updateLineItem);
  checkForError(result, key: 'cartLinesUpdate', errorKey: 'userErrors');

  return Cart.fromJson(
      ((result.data!['cartLinesUpdate'] ?? const {})['cart'] ?? const {}));
}