getOrders method

Future<List<WooOrder>> getOrders({
  1. int? page,
  2. int? perPage,
  3. String? search,
  4. String? after,
  5. String? before,
  6. List<int>? exclude,
  7. List<int>? include,
  8. int? offset,
  9. String? order,
  10. String? orderBy,
  11. List<int>? parent,
  12. List<int>? parentExclude,
  13. List<String>? status,
  14. int? customer,
  15. int? product,
  16. int? dp,
})

Returns a list of all Order, with filter options.

Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#orders

Implementation

Future<List<WooOrder>> getOrders(
    {int? page,
    int? perPage,
    String? search,
    String? after,
    String? before,
    List<int>? exclude,
    List<int>? include,
    int? offset,
    String? order,
    String? orderBy,
    List<int>? parent,
    List<int>? parentExclude,
    List<String>?
        status, // Options: any, pending, processing, on-hold, completed, cancelled, refunded, failed and trash. Default is any.
    int? customer,
    int? product,
    int? dp}) async {
  Map<String, dynamic> payload = {};

  ({
    'page': page,
    'per_page': perPage,
    'search': search,
    'after': after,
    'before': before,
    'exclude': exclude,
    'include': include,
    'offset': offset,
    'order': order,
    'orderby': orderBy,
    'parent': parent,
    'parent_exclude': parentExclude,
    'status': status,
    'customer': customer,
    'product': product,
    'dp': dp,
  }).forEach((k, v) {
    if (v != null) payload[k] = v.toString();
  });
  List<WooOrder> orders = [];
  _printToLog('Getting Order With Payload : ' + payload.toString());
  _setApiResourceUrl(path: 'orders', queryParameters: payload);
  final response = await get(queryUri.toString());
  for (var o in response) {
    var order = WooOrder.fromJson(o);
    _printToLog('order gotten here : ' + order.toString());
    orders.add(order);
  }
  return orders;
}