getProductVariants method
Get product variants (configurable options)
Implementation
Future<List<ProductOption>> getProductVariants(String sku) async {
try {
final response = await _client.guestRequest<Map<String, dynamic>>(
'/rest/V1/products/$sku/options',
);
if (response.statusCode == 200) {
final List<dynamic> optionsData = response.data!['options'] ?? [];
return optionsData.map((json) => ProductOption.fromJson(json)).toList();
} else {
throw Exception(
'Failed to get product variants: ${response.statusMessage}',
);
}
} on DioException catch (e) {
throw Exception('Failed to get product variants: ${e.message}');
} catch (e) {
throw Exception('Failed to get product variants: $e');
}
}