diff --git a/lib/src/model/product.dart b/lib/src/model/product.dart index 2b150fe921..ad591c68a8 100644 --- a/lib/src/model/product.dart +++ b/lib/src/model/product.dart @@ -109,6 +109,20 @@ class Product extends JsonObject { toJson: LanguageHelper.toJsonStringMap) Map? productNameInLanguages; + /// Localized conservation conditions of the product, stored in a map where each language is represented by its respective key. + @JsonKey( + name: 'conservation_conditions_in_languages', + fromJson: LanguageHelper.fromJsonStringMap, + toJson: LanguageHelper.toJsonStringMap) + Map? conservationConditionsInLanguages; + + /// Localized customer service information for the product, stored in a map where each language is represented by its respective key. + @JsonKey( + name: 'customer_service_in_languages', + fromJson: LanguageHelper.fromJsonStringMap, + toJson: LanguageHelper.toJsonStringMap) + Map? customerServiceInLanguages; + /// Common name. Example: "Chocolate bar with milk and hazelnuts". @JsonKey(name: 'generic_name') String? genericName; @@ -759,6 +773,14 @@ class Product extends JsonObject { result.countriesTagsInLanguages ??= {}; result.countriesTagsInLanguages![language] = labels; break; + case ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES: + result.conservationConditionsInLanguages ??= {}; + result.conservationConditionsInLanguages![language] = label; + break; + case ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES: + result.customerServiceInLanguages ??= {}; + result.customerServiceInLanguages![language] = label; + break; default: // not supposed to be called with other ProductField values. assert(false); diff --git a/lib/src/model/product.g.dart b/lib/src/model/product.g.dart index 1f3b609636..fcef642a4f 100644 --- a/lib/src/model/product.g.dart +++ b/lib/src/model/product.g.dart @@ -103,6 +103,10 @@ Product _$ProductFromJson(Map json) => Product( ) ..productType = $enumDecodeNullable(_$ProductTypeEnumMap, json['product_type']) + ..conservationConditionsInLanguages = LanguageHelper.fromJsonStringMap( + json['conservation_conditions_in_languages']) + ..customerServiceInLanguages = LanguageHelper.fromJsonStringMap( + json['customer_service_in_languages']) ..genericNameInLanguages = LanguageHelper.fromJsonStringMap(json['generic_name_in_languages']) ..abbreviatedName = json['abbreviated_product_name'] as String? @@ -194,6 +198,12 @@ Map _$ProductToJson(Product instance) { writeNotNull('product_name', instance.productName); writeNotNull('product_name_in_languages', LanguageHelper.toJsonStringMap(instance.productNameInLanguages)); + writeNotNull( + 'conservation_conditions_in_languages', + LanguageHelper.toJsonStringMap( + instance.conservationConditionsInLanguages)); + writeNotNull('customer_service_in_languages', + LanguageHelper.toJsonStringMap(instance.customerServiceInLanguages)); writeNotNull('generic_name', instance.genericName); writeNotNull('generic_name_in_languages', LanguageHelper.toJsonStringMap(instance.genericNameInLanguages)); diff --git a/lib/src/utils/product_fields.dart b/lib/src/utils/product_fields.dart index b17af30be7..54c2475ec1 100644 --- a/lib/src/utils/product_fields.dart +++ b/lib/src/utils/product_fields.dart @@ -18,6 +18,14 @@ enum ProductField implements OffTagged { inLanguagesProductField: ProductField.NAME_IN_LANGUAGES, isAllLanguages: true, ), + CONSERVATION_CONDITIONS_ALL_LANGUAGES( + offTag: 'conservation_conditions_languages', + isAllLanguages: true, + ), + CUSTOMER_SERVICE_ALL_LANGUAGES( + offTag: 'customer_service_languages', + isAllLanguages: true, + ), GENERIC_NAME( offTag: 'generic_name', inLanguagesProductField: ProductField.GENERIC_NAME_IN_LANGUAGES, @@ -310,6 +318,8 @@ const Set fieldsInLanguages = { @Deprecated('Use ProductField.getAllLanguagesList() instead') const Set fieldsAllLanguages = { ProductField.NAME_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, + ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, ProductField.GENERIC_NAME_ALL_LANGUAGES, ProductField.ABBREVIATED_NAME_ALL_LANGUAGES, ProductField.INGREDIENTS_TEXT_ALL_LANGUAGES, diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index 5b1b9821c7..055ac206fb 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -233,6 +233,41 @@ void main() { expect(nutriments.getValue(Nutrient.vitaminC, perSize), 0.0339); }); + test('get localized conservation conditions and customer service', + () async { + const String barcode = '3017620425035'; + ProductQueryConfiguration configuration = ProductQueryConfiguration( + barcode, + fields: [ + ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES + ], + version: ProductQueryVersion.v3, + language: OpenFoodFactsLanguage.JAPANESE, + ); + + ProductResultV3 result = await getProductV3InProd(configuration); + + expect(result.status, ProductResultV3.statusSuccess); + expect(result.product != null, true); + expect( + result.product!.conservationConditionsInLanguages! + .containsKey(OpenFoodFactsLanguage.FRENCH), + isTrue); + expect( + result.product!.customerServiceInLanguages! + .containsKey(OpenFoodFactsLanguage.FRENCH), + isTrue); + + final conservationConditions = + result.product!.conservationConditionsInLanguages; + expect(conservationConditions, isNotNull); + expect(conservationConditions, isNotEmpty); + + final customerService = result.product!.customerServiceInLanguages; + expect(customerService, isNotNull); + expect(customerService, isNotEmpty); + }); test('get uncommon nutrients', () async { // PROD data as of 2021-07-16 const OpenFoodFactsLanguage language = OpenFoodFactsLanguage.FRENCH;