createCart method

Future<Cart> createCart(
  1. CartInput cartInput
)

create cart

Implementation

Future<Cart> createCart(CartInput cartInput) async {
  final data = {
    'discountCodes': cartInput.discountCodes,
    'lines': cartInput.lines.map((e) => e?.toJson()).toList(),
    'note': cartInput.note,
    'buyerIdentity': cartInput.buyerIdentity?.toJson(),
  };
  final MutationOptions createCart = MutationOptions(
    document: gql(cartCreateMutation),
    variables: {
      'input': data,
      'country': ShopifyLocalization.countryCode,
    },
  );
  QueryResult result = await _graphQLClient!.mutate(createCart);
  checkForError(result, key: 'cartCreate', errorKey: 'userErrors');

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