getProductTags method

Future<List<WooProductTag>> getProductTags({
  1. int? page,
  2. int? perPage,
  3. String? search,
  4. int? offset,
  5. String? order,
  6. String? orderBy,
  7. bool? hideEmpty,
  8. int? product,
  9. String? slug,
})

Returns a list of all ProductTag, with filter options.

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

Implementation

Future<List<WooProductTag>> getProductTags(
    {int? page,
    int? perPage,
    String? search,
    //List<int> exclude,
    //List<int> include,
    int? offset,
    String? order,
    String? orderBy,
    bool? hideEmpty,
    int? product,
    String? slug}) async {
  Map<String, dynamic> payload = {};
  ({
    'page': page, 'per_page': perPage, 'search': search,
    // 'exclude': exclude, 'include': include,
    'offset': offset,
    'order': order, 'orderby': orderBy, 'hide_empty': hideEmpty,
    'product': product, 'slug': slug,
  }).forEach((k, v) {
    if (v != null) payload[k] = v.toString();
  });
  List<WooProductTag> productTags = [];
  _printToLog('making request with payload : ' + payload.toString());
  _setApiResourceUrl(path: 'products/tags', queryParameters: payload);
  final response = await get(queryUri.toString());
  _printToLog('response gotten : ' + response.toString());
  for (var c in response) {
    var tag = WooProductTag.fromJson(c);
    _printToLog('prod gotten here : ' + tag.toString());
    productTags.add(tag);
  }
  return productTags;
}