updateLineItemsInCheckout method

Future<Checkout> updateLineItemsInCheckout({
  1. required String checkoutId,
  2. required List<LineItem> lineItems,
  3. bool deleteThisPartOfCache = false,
})

Implementation

Future<Checkout> updateLineItemsInCheckout(
    {required String checkoutId,
    required List<LineItem> lineItems,
    bool deleteThisPartOfCache = false}) async {
  final MutationOptions _options = MutationOptions(
      document: gql(updateLineItemsInCheckoutMutation),
      variables: {
        'checkoutId': checkoutId,
        'lineItems': [
          for (var lineItem in lineItems)
            {
              'variantId': lineItem.id,
              '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',
  );
  if (deleteThisPartOfCache) {
    _graphQLClient!.cache.writeQuery(_options.asRequest, data: {});
  }

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