getCoupons method
Returns a list of all WooCoupon, with filter options.
Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#coupons
Implementation
Future<List<WooCoupon>?> getCoupons({
int? page,
int? perPage,
String? search,
String? after,
String? before,
//List<int> exclude,
//List<int> include,
int? offset,
String? order,
String? orderBy,
String? code,
}) 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, 'code': code,
}).forEach((k, v) {
if (v != null) payload[k] = v.toString();
});
List<WooCoupon>? coupons;
_printToLog('Getting Coupons With Payload : ' + payload.toString());
_setApiResourceUrl(path: 'coupons', queryParameters: payload);
final response = await get(queryUri.toString());
for (var c in response) {
var coupon = WooCoupon.fromJson(c);
_printToLog('prod gotten here : ' + order.toString());
coupons!.add(coupon);
}
return coupons;
}