updateCartAttributes method

Future<Cart> updateCartAttributes({
  1. required String cartId,
  2. required List<AttributeInput> attributes,
  3. bool reverse = false,
})

update cart atributes

If the reverse is set to true, the line items in the cart will be in reverse order.

Implementation

Future<Cart> updateCartAttributes({
  required String cartId,
  required List<AttributeInput> attributes,
  bool reverse = false,
}) async {
  final MutationOptions updateAttributes = MutationOptions(
    document: gql(updateCartAttributesMutation),
    variables: {
      'cartId': cartId,
      'attributes': attributes.map((e) => e.toJson()).toList(),
      'country': ShopifyLocalization.countryCode,
      'reverse': reverse
    },
  );
  QueryResult result = await _graphQLClient!.mutate(updateAttributes);
  checkForError(result, key: 'cartAttributesUpdate', errorKey: 'userErrors');

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