getCrossSellProducts method
Get cross-sell products
Implementation
Future<List<Product>> getCrossSellProducts(String sku) async {
try {
final response = await _client.guestRequest<Map<String, dynamic>>(
'/rest/V1/products/$sku/links',
queryParameters: {'type': 'crosssell'},
);
if (response.statusCode == 200) {
final List<dynamic> productsData = response.data!['items'] ?? [];
return productsData.map((json) => Product.fromJson(json)).toList();
} else {
throw Exception(
'Failed to get cross-sell products: ${response.statusMessage}',
);
}
} on DioException catch (e) {
throw Exception('Failed to get cross-sell products: ${e.message}');
} catch (e) {
throw Exception('Failed to get cross-sell products: $e');
}
}