updateLineItemsInCheckout method

Future<Checkout> updateLineItemsInCheckout({
  1. required String checkoutId,
  2. required List<LineItem> lineItems,
})

Implementation

Future<Checkout> updateLineItemsInCheckout({
  required String checkoutId,
  required List<LineItem> lineItems,
}) async {
  final MutationOptions _options = MutationOptions(
      document: gql(updateLineItemsInCheckoutMutation),
      variables: {
        'checkoutId': checkoutId,
        'lineItems': [
          for (var lineItem in lineItems)
            {
              'id': lineItem.id,
              'variantId': lineItem.variantId,
              'quantity': lineItem.quantity,
              'customAttributes': lineItem.customAttributes
                  .map((e) => {
                        'key': e.key,
                        'value': e.value,
                      })
                  .toList(),
            }
        ],
      });
  final QueryResult result = await _graphQLClient!.mutate(_options);
  checkForError(
    result,
    key: 'updateLineItemsInCheckout',
    errorKey: 'checkoutUserErrors',
  );

  return Checkout.fromJson(
      ((result.data!['checkoutLineItemsUpdate'] ?? const {})['checkout'] ??
          const {}));
}