Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add localized fields for conservation conditions and customer service in Product object #1020

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
34 changes: 34 additions & 0 deletions lib/src/model/product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ class Product extends JsonObject {
toJson: LanguageHelper.toJsonStringMap)
Map<OpenFoodFactsLanguage, String>? productNameInLanguages;

/// The conservation conditions of the product, either set directly or taken from one of the localizations.
///
/// Prefer using [conservationConditionsInLanguages] for more accurate and localized data.
@JsonKey(name: 'conservation_conditions')
String? conservation_conditions;
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved

/// Localized conservation conditions of the product, stored in a map where each language is represented by its respective key.
///
/// This field is useful when you need to retrieve conservation conditions in a specific language.
/// For general usage, rely on [conservation_conditions] or the localization-specific fields.
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
@JsonKey(
name: 'conservation_conditions_in_languages',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap)
Map<OpenFoodFactsLanguage, String>? conservationConditionsInLanguages;

/// The customer service information for the product, either set directly or taken from one of the localizations.
///
/// Prefer using [customerServiceInLanguages] for more accurate and localized data.
@JsonKey(name: 'customer_service')
String? customer_service;
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved

/// Localized customer service information for the product, stored in a map where each language is represented by its respective key.
///
/// This field is useful when you need to retrieve customer service information in a specific language.
/// For general usage, rely on [customer_service] or the localization-specific fields.
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
@JsonKey(
name: 'customer_service_in_languages',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap)
Map<OpenFoodFactsLanguage, String>? customerServiceInLanguages;

/// Common name. Example: "Chocolate bar with milk and hazelnuts".
@JsonKey(name: 'generic_name')
String? genericName;
Expand Down Expand Up @@ -604,6 +636,8 @@ class Product extends JsonObject {
{this.barcode,
this.productName,
this.productNameInLanguages,
this.conservation_conditions,
this.customer_service,
this.genericName,
this.brands,
this.brandsTags,
Expand Down
32 changes: 32 additions & 0 deletions lib/src/utils/product_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ enum ProductField implements OffTagged {
offTag: 'product_name_languages',
inLanguagesProductField: ProductField.NAME_IN_LANGUAGES,
isAllLanguages: true,
),
CONSERVATION_CONDITIONS(
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
offTag: 'conservation_conditions',
inLanguagesProductField: ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES,
),

CONSERVATION_CONDITIONS_IN_LANGUAGES(
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
offTag: 'conservation_conditions_',
isInLanguages: true,
),

CONSERVATION_CONDITIONS_ALL_LANGUAGES(
offTag: 'conservation_conditions_languages',
inLanguagesProductField: ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES,
isAllLanguages: true,
),
CUSTOMER_SERVICE(
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
offTag: 'customer_service',
inLanguagesProductField: ProductField.CUSTOMER_SERVICE_IN_LANGUAGES,
),

CUSTOMER_SERVICE_IN_LANGUAGES(
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
offTag: 'customer_service_',
isInLanguages: true,
),

CUSTOMER_SERVICE_ALL_LANGUAGES(
offTag: 'customer_service_languages',
inLanguagesProductField: ProductField.CUSTOMER_SERVICE_IN_LANGUAGES,
isAllLanguages: true,
),
GENERIC_NAME(
offTag: 'generic_name',
Expand Down Expand Up @@ -287,6 +317,8 @@ enum ProductField implements OffTagged {
@Deprecated('Use ProductField.getInLanguagesList() instead')
const Set<ProductField> fieldsInLanguages = {
ProductField.NAME_IN_LANGUAGES,
ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES,
AffanShaikhsurab marked this conversation as resolved.
Show resolved Hide resolved
ProductField.CUSTOMER_SERVICE_IN_LANGUAGES,
ProductField.GENERIC_NAME_IN_LANGUAGES,
ProductField.ABBREVIATED_NAME_IN_LANGUAGES,
ProductField.INGREDIENTS_TEXT_IN_LANGUAGES,
Expand Down
Loading