getCustomerOrders method
Get customer orders with pagination and filters
Implementation
Future<OrderListResponse> getCustomerOrders({
int page = 1,
int pageSize = 20,
Map<String, dynamic>? filters,
}) async {
try {
String url =
'/rest/V1/customers/me/orders?searchCriteria[currentPage]=$page&searchCriteria[pageSize]=$pageSize';
if (filters != null) {
filters.forEach((key, value) {
url +=
'&searchCriteria[filterGroups][0][filters][0][field]=$key&searchCriteria[filterGroups][0][filters][0][value]=$value';
});
}
final response = await _client.authenticatedRequest<Map<String, dynamic>>(
url,
);
if (response.statusCode == 200) {
return OrderListResponse.fromJson(response.data!);
} else {
throw Exception(
'Failed to get customer orders: ${response.statusMessage}',
);
}
} on DioException catch (e) {
throw Exception('Failed to get customer orders: ${e.message}');
} catch (e) {
throw Exception('Failed to get customer orders: $e');
}
}