getOrders method
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;
}