getProducts method
Future<List<WooProduct> >
getProducts({
- int? page,
- int? perPage,
- String? search,
- String? after,
- String? before,
- String? order,
- String? orderBy,
- String? slug,
- String? status,
- String? type,
- String? sku,
- String? category,
- String? tag,
- String? shippingClass,
- String? attribute,
- String? attributeTerm,
- String? taxClass,
- String? minPrice,
- String? maxPrice,
- String? stockStatus,
- List<
int> ? exclude, - List<
int> ? parentExclude, - List<
int> ? include, - List<
int> ? parent, - int? offset,
- bool? featured,
- bool? onSale,
Returns a list of all WooProduct, with filter options.
Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#products.
Implementation
Future<List<WooProduct>> getProducts(
{int? page,
int? perPage,
String? search,
String? after,
String? before,
String? order,
String? orderBy,
String? slug,
String? status,
String? type,
String? sku,
String? category,
String? tag,
String? shippingClass,
String? attribute,
String? attributeTerm,
String? taxClass,
String? minPrice,
String? maxPrice,
String? stockStatus,
List<int>? exclude,
List<int>? parentExclude,
List<int>? include,
List<int>? parent,
int? offset,
bool? featured,
bool? onSale}) 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,
'parent': parent,
'parent_exclude': parentExclude,
'slug': slug,
'status': status,
'type': type,
'sku': sku,
'featured': featured,
'category': category,
'tag': tag,
'shipping_class': shippingClass,
'attribute': attribute,
'attribute_term': attributeTerm,
'tax_class': taxClass,
'on_sale': onSale,
'min_price': minPrice,
'max_price': maxPrice,
'stock_status': stockStatus,
}).forEach((k, v) {
if (v != null) payload[k] = v.toString();
});
_printToLog("Parameters: " + payload.toString());
List<WooProduct> products = [];
_setApiResourceUrl(path: 'products', queryParameters: payload);
final response = await get(queryUri.toString());
_printToLog('response gotten : ' + response.toString());
_printToLog('this is the queri uri : ' + queryUri.toString());
for (var p in response) {
var prod = WooProduct.fromJson(p);
_printToLog('product gotten here : ' + prod.name.toString());
products.add(prod);
}
return products;
}