ProductOpener::Import - import products data in CSV format and products photos
ProductOpener::Import
is used to import product data in the Open Food Facts CSV format and associated product photos.
use ProductOpener::Import qw/:all/; import_csv_file( { user_id => "user", org_id => "organization", csv_file => "/path/to/product_data.csv", });
This module is used to import product data provided by manufacturers on the producers platform: the data from manufacturers (in CSV or Excel files) is first converted to the Open Food Facts CSV format, then imported with import_csv_file
.
It is also used to export product data from the producers platform to the public database. The data is first exported from the producers platform with the ProductOpener::Export
module, and then imported in the public database with the import_csv_file
function.
In the producers platform, the import_csv_file
function is executed through a Minion worker.
It is also used in the scripts/import_csv_file.pl
script.
..
Do some pre-processing on input field values:
- Fields suffixed with _if_not_existing are loaded only if the product does not have an existing value - Special handling of tags fields: - Empty values are skipped - For labels and categories, we can have columns like labels:Bio with values like 1, Y, Yes - [tags type]_if_match_in_taxonomy : contains candidate values that we import only if we have a matching taxonomy entry - Values for multiple columns for the same tag field. e.g. brands, brands.2, brands.3 etc. are concatenated with a comma
Update a product field value in $product_ref based on the value in the imported product $imported_product_ref
Return an incremented $modified value if a change was made.
import_csv_file()
imports product data in the Open Food Facts CSV format and associated product photos.
Arguments are passed through a single hash reference with the following keys:
User id to which the changes (new products, added or changed values, new images) will be attributed.
If the user_id is 'all', the change will be attributed to the org of the product. (e.g. when importing products from the producers database to the public database)
Organization id to which the changes (new products, added or changed values, new images) will be attributed.
For databases with private products, owner (user or org) that the products belong to. Values are of the form user-[user id] or org-[organization id].
If not set, for databases with private products, it will be constructed from the user_id and org_id parameters.
The owner can be overrode if the CSV file contains a org_name field. In that case, the owner is set to the value of the org_name field, and a new org is created if it does not exist yet.
Path and file name of the CSV file to import.
The CSV file needs to be in the Open Food Facts CSV format, encoded in UTF-8 with tabs as separators.
Hash ref that specifies fields and values that will be used as default values.
If the CSV contains a non-empty value for a field, the value from the CSV file is used.
Path to a directory that contains images for the products.
Comment that will be saved in the product history.
Indicates that there should not be a data source attribution.
Source id for the data and images.
Name of the source.
URL for the source.
License that the source data is available in.
URL for the license.
A positive value indicates that the data is imported from the manufacturer of the products.
Compute statistics on the number of products the import would add or change, but do not actually import and save the changes.
Only import one product with the corresponding code.
Only import product data if the product already exists in the database. This can be useful when we have very sparse data to import (e.g. a list of codes of products sold in a given store chain), and we do not want to create products when we have no other existing data.
Do not import products when we do not have info (product name or brands)
Do not import products if there are no corresponding images in the directory specified by the images_dir argument/
If a product already has existing values for some fields, do not overwrite it with values from the CSV file.
If the product already has an image for front, ingredients or nutrition in a given language, do not overwrite it with an image from the import. The image will still be uploaded and added to the product, but it will not be selected.
Once products from a CSV file have been exported from the producers platform and imported on the public platform, update_export_status_for_csv_file() marks them as exported on the producers platform.
Arguments are passed through a single hash reference with the following keys:
User id to which the changes (new products, added or changed values, new images) will be attributed.
Organization id to which the changes (new products, added or changed values, new images) will be attributed.
For databases with private products, owner (user or org) that the products belong to. Values are of the form user-[user id] or org-[organization id].
If not set, for databases with private products, it will be constructed from the user_id and org_id parameters.
The owner can be overrode if the CSV file contains a org_name field. In that case, the owner is set to the value of the org_name field, and a new org is created if it does not exist yet.
Path and file name of the CSV file to import.
The CSV file needs to be in the Open Food Facts CSV format, encoded in UTF-8 with tabs as separators.
Time of the export.
import_products_categories_from_public_database()
imports categories from the public Open Food Facts database to the producers platform, for products with a specific owner.
The products have to already exist in the producers platform.
Arguments are passed through a single hash reference with the following keys:
User id to which the changes (new products, added or changed values, new images) will be attributed.
Organization id to which the changes (new products, added or changed values, new images) will be attributed.
Owner of the products on the producers platform.