getCartById method
Returns a Cart object.
Returns the Cart object of the Cart with the cartId
.
If the reverse
is set to true, the line items in the cart will be in reverse order.
Implementation
Future<Cart?> getCartById(String cartId, {bool reverse = false}) async {
final cartById = WatchQueryOptions(
document: gql(getCartByIdQuery),
variables: {
'id': cartId,
'country': ShopifyLocalization.countryCode,
'reverse': reverse
},
fetchPolicy: ShopifyConfig.fetchPolicy,
);
QueryResult result = await _graphQLClient!.query(cartById);
checkForError(result);
if (result.data?['cart'] == null) {
return null;
}
return Cart.fromJson(result.data!['cart'] ?? const {});
}