<<

NAME

ProductOpener::ProductSchemaChanges - convert product data between different schema versions

DESCRIPTION

ProductOpener::ProductSchemaChanges is used to convert product data between different schema versions.

It can convert older product data (e.g. from old revisions of products) to the current schema version.

And for API backward compatibility, it can also convert the current product data to older schema versions.

Schema version numbering

Starting from March 2024, we will now include a new field in the product data called "schema_version", which will be an integer, starting at 1001.

The schema version will be incremented by 1 each time we make a change to the product data schema.

Products without a schema_version field will be considered to be at a schema version under 1000

Schema conversion functions

We will keep a list of functions that can convert product data between different schema versions.

FUNCTIONS

convert_product_schema ($product_ref, $to_version)

Convert product data between different schema versions.

998 to 999 - Change in barcode normalization

Change in normalization of leading 0s.

999 to 1000 - Rename ecoscore fields to environmental_score fields - API v3.1

2024/12/12 -

1000 to 1001 - Remove the ingredients_hierarchy field - API v3.2

2012/03/14

- Remove the ingredients_hierarchy field, which was a duplicate of the ingredients_tags field - Taxonomize brands

1001 to 1002 - Refactor the images object

The images object is restructured to separate uploaded images from selected images

1002 to 1003 - Refactor the product nutrition schema - API v3.5

The nutrition schema is updated to allow storing several nutrition sets

set_per_unit

Set the per unit depending on the given product quantity unit, the serving quantity unit and on the fact that the created set is per 100g or per serving

1003 to 1002 - Refactor the product nutrition schema - API v3.5

The nutrition schema is updated to allow storing several nutrition input sets. To downgrade, we use only the aggregated set to generate the nutriments field.

This means that for some products, we will return less information in the downgraded version, as we will return only as sold data or prepared data, but not both as was possible in the 1002 version.

_has_nutrition_data_for_product_type ($product_ref, $nutrition_product_type)

NOTE: this function used to be in Food.pm and it was used for the old nutrition data schema in the "nutriments" field.

It has been moved to this module as it is now needed only for schema upggrades.

--

Check if the product has nutrition data for the given type ("" or "_prepared").

Arguments

$product_ref - ref to the product

$nutrition_product_type - string, either "" or "_prepared"

Return values

0 or 1

0 if the product does not have nutrition data for the given type

1 if the product has nutrition data for the given type

_compute_nutrition_data_per_100g_and_per_serving_for_old_nutrition_schema ($product_ref)

NOTE: this function used to be in Food.pm and it was used for the old nutrition data schema in the "nutriments" field.

It has been moved to this module as it is now needed only for schema downgrades.

--

Input nutrition data is indicated per 100g or per serving. This function computes the nutrition data for the other quantity (per serving or per 100g) if we know the serving quantity.

<<