getProductVariations method
Future<List<WooProductVariation> >
getProductVariations({
- required int productId,
- int? page,
- int? perPage,
- String? search,
- String? after,
- String? before,
- List<
int> ? exclude, - List<
int> ? include, - int? offset,
- String? order,
- String? orderBy,
- List<
int> ? parent, - List<
int> ? parentExclude, - String? slug,
- String? status,
- String? sku,
- String? taxClass,
- bool? onSale,
- String? minPrice,
- String? maxPrice,
- String? stockStatus,
Returns a list of all WooProductVariation, with filter options.
Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#product-variations
Implementation
Future<List<WooProductVariation>> getProductVariations(
{required int productId,
int? page,
int? perPage,
String? search,
String? after,
String? before,
List<int>? exclude,
List<int>? include,
int? offset,
String? order,
String? orderBy,
List<int>? parent,
List<int>? parentExclude,
String? slug,
String? status,
String? sku,
String? taxClass,
bool? onSale,
String? minPrice,
String? maxPrice,
String? stockStatus}) 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,
'sku': sku,
'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();
});
List<WooProductVariation> productVariations = [];
_setApiResourceUrl(
path: 'products/' + productId.toString() + '/variations',
queryParameters: payload);
_printToLog('this is the curent path : ' + this.apiPath);
final response = await get(queryUri.toString());
for (var v in response) {
var prodv = WooProductVariation.fromJson(v);
_printToLog('prod gotten here : ' + prodv.toString());
productVariations.add(prodv);
}
return productVariations;
}