updateLineItemsInCart method

Future<Cart> updateLineItemsInCart({
  1. required String cartId,
  2. required List<CartLineUpdateInput> cartLineInputs,
  3. bool reverse = false,
})

update line items in cart

If the reverse is set to true, the line items in the cart will be in reverse order.

Implementation

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

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