getProductCategories method
Returns a list of all WooProductCategory, with filter options.
Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#product-categories
Implementation
Future<List<WooProductCategory>> getProductCategories(
{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<WooProductCategory> productCategories = [];
_printToLog('payload : ' + payload.toString());
_setApiResourceUrl(path: 'products/categories', queryParameters: payload);
_printToLog('this is the path : ' + this.apiPath);
final response = await get(queryUri.toString());
for (var c in response) {
var cat = WooProductCategory.fromJson(c);
_printToLog('category gotten here : ' + cat.toString());
productCategories.add(cat);
}
return productCategories;
}