addLineItemsToCheckout method

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

Implementation

Future<Checkout> addLineItemsToCheckout({
  required String checkoutId,
  required List<LineItem> lineItems,
}) async {
  final MutationOptions _options = MutationOptions(
      document: gql(addLineItemsToCheckoutMutation),
      variables: {
        'checkoutId': checkoutId,
        'lineItems': [
          for (var lineItem in lineItems)
            {
              '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: 'addLineItemsToCheckout',
    errorKey: 'checkoutUserErrors',
  );

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