updateCartDiscountCodes method

Future<Cart> updateCartDiscountCodes({
  1. required String cartId,
  2. required List<String> discountCodes,
})

update cart discount codes

Implementation

Future<Cart> updateCartDiscountCodes({
  required String cartId,
  required List<String> discountCodes,
}) async {
  final MutationOptions updateDiscountCodes = MutationOptions(
    document: gql(updateCartDiscountCodesMutation),
    variables: {
      'cartId': cartId,
      'discountCodes': discountCodes,
      'country': ShopifyLocalization.countryCode,
    },
  );
  QueryResult result = await _graphQLClient!.mutate(updateDiscountCodes);
  checkForError(result,
      key: 'cartDiscountCodesUpdate', errorKey: 'userErrors');

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