getProductReviews method

Future<List<WooProductReview>> getProductReviews({
  1. int? page,
  2. int? perPage,
  3. String? search,
  4. String? after,
  5. String? before,
  6. int? offset,
  7. String? order,
  8. String? orderBy,
  9. List<int>? reviewer,
  10. List<int>? product,
  11. String? status,
})

Returns a list of all WooProductReview, with filter options.

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

Implementation

Future<List<WooProductReview>> getProductReviews(
    {int? page,
    int? perPage,
    String? search,
    String? after,
    String? before,
    //List<int> exclude,
    //List<int> include,
    int? offset,
    String? order,
    String? orderBy,
    List<int>? reviewer,
    //List<int> reviewerExclude,
    //List<String> reviewerEmail,
    List<int>? product,
    String? status}) 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,
    'reviewer': reviewer,
    //'reviewer_exclude': reviewerExclude, 'reviewer_email': reviewerEmail,
    'product': product,
    'status': status,
  }).forEach((k, v) {
    if (v != null) payload[k] = v;
  });
  String meQueryPath = 'products/reviews' + getQueryString(payload);
  List<WooProductReview> productReviews = [];
  //_setApiResourceUrl(path: 'products/reviews', queryParameters: payload);
  final response = await get(meQueryPath);
  _printToLog('response gotten : ' + response.toString());
  for (var r in response) {
    var rev = WooProductReview.fromJson(r);
    _printToLog('reviews gotten here : ' + rev.toString());
    productReviews.add(rev);
  }
  return productReviews;
}