getAllOrders method

Future<List<Order>?> getAllOrders(
  1. String customerAccessToken, {
  2. SortKeyOrder sortKey = SortKeyOrder.PROCESSED_AT,
  3. bool reverse = true,
})

Returns all Order in a List of Orders.

Returns a List of Orders from the Customer with the customerAccessToken.

Implementation

Future<List<Order>?> getAllOrders(
  String customerAccessToken, {
  SortKeyOrder sortKey = SortKeyOrder.PROCESSED_AT,
  bool reverse = true,
}) async {
  final MutationOptions _options =
      MutationOptions(document: gql(getAllOrdersQuery), variables: {
    'accessToken': customerAccessToken,
    'sortKey': sortKey.parseToString(),
    'reverse': reverse,
    'country': ShopifyLocalization.countryCode,
  });
  QueryResult result = await _graphQLClient!.mutate(_options);
  checkForError(result);
  final ordersData = result.data!['customer']?['orders'];
  if (ordersData == null) return [];
  final orderResult = ordersData as Map<String, dynamic>;
  Orders orders = Orders.fromGraphJson(orderResult);
  // Orders orders = Orders.fromJson(
  //     (((result.data ?? const {})['customer'] ?? const {})['orders'] ??
  //         const {}));
  return orders.orderList;
}