getProductAttributeTerms method

Future<List<WooProductAttributeTerm>> getProductAttributeTerms({
  1. required int attributeId,
  2. int? page,
  3. int? perPage,
  4. String? search,
  5. List<int>? exclude,
  6. List<int>? include,
  7. String? order,
  8. String? orderBy,
  9. bool? hideEmpty,
  10. int? parent,
  11. int? product,
  12. String? slug,
})

Implementation

Future<List<WooProductAttributeTerm>> getProductAttributeTerms(
    {required int attributeId,
    int? page,
    int? perPage,
    String? search,
    List<int>? exclude,
    List<int>? include,
    String? order,
    String? orderBy,
    bool? hideEmpty,
    int? parent,
    int? product,
    String? slug}) async {
  Map<String, dynamic> payload = {};

  ({
    'page': page,
    'per_page': perPage,
    'search': search,
    'exclude': exclude,
    'include': include,
    'order': order,
    'orderby': orderBy,
    'hide_empty': hideEmpty,
    'parent': parent,
    'product': product,
    'slug': slug,
  }).forEach((k, v) {
    if (v != null) payload[k] = v.toString();
  });
  List<WooProductAttributeTerm> productAttributeTerms = [];
  _setApiResourceUrl(
      path: 'products/attributes/' + attributeId.toString() + '/terms',
      queryParameters: payload);
  final response = await get(queryUri.toString());
  for (var t in response) {
    var term = WooProductAttributeTerm.fromJson(t);
    _printToLog('term gotten here : ' + term.toString());
    productAttributeTerms.add(term);
  }
  return productAttributeTerms;
}