Skip to content

Commit

Permalink
fix: sample import file for producers on pro platform (#10312)
Browse files Browse the repository at this point in the history
* fix: sample import file for producers on pro platform

* update test
  • Loading branch information
stephanegigandet authored May 20, 2024
1 parent 42ef40a commit 6844c75
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
21 changes: 13 additions & 8 deletions cgi/generate_sample_import_file.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
use ProductOpener::Config qw/:all/;
use ProductOpener::Display qw/init_request/;
use ProductOpener::Users qw/:all/;
use ProductOpener::Lang qw/$lc lang/;
use ProductOpener::Lang qw/lang/;
use ProductOpener::Mail qw/:all/;
use ProductOpener::Producers qw/generate_import_export_columns_groups_for_select2/;
use ProductOpener::Tags qw/%language_fields %tags_fields/;
use ProductOpener::Tags qw/%language_fields %tags_fields display_taxonomy_tag/;
use ProductOpener::Food qw/default_unit_for_nid/;
use ProductOpener::TaxonomySuggestions qw/:all/;
use ProductOpener::Paths qw/%BASE_DIRS/;

use Apache2::RequestRec ();
use Apache2::Const ();
Expand All @@ -49,7 +50,8 @@
my $r = Apache2::RequestUtil->request();

$r->headers_out->set("Content-type" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
$r->headers_out->set("Content-disposition" => "attachment;filename=openfoodfacts_import_template_$lc.xlsx");
$r->headers_out->set(
"Content-disposition" => "attachment;filename=openfoodfacts_import_template_" . $request_ref->{lc} . ".xlsx");

print "Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n";

Expand Down Expand Up @@ -88,7 +90,7 @@
);

# Re-use the structure used to output select2 options in import_file_select_format.pl
my $select2_options_ref = generate_import_export_columns_groups_for_select2([$lc]);
my $select2_options_ref = generate_import_export_columns_groups_for_select2([$request_ref->{lc}]);

my $headers_row = 0;

Expand All @@ -101,10 +103,10 @@
my $comment;

my $example = lang("example");
my $example_tsv_file = 'conf/pro-platform/Import template - Example translations - Import sheet.tsv';
my $example_tsv_file = $BASE_DIRS{CONF} . '/pro-platform/Import template - Example translations - Import sheet.tsv';
my %example_values_by_language_and_header;

open(my $example_fh, '<', $example_tsv_file) or die "Cannot open $example_tsv_file: $!";
open(my $example_fh, "<:encoding(UTF-8)", $example_tsv_file) or die "Cannot open $example_tsv_file: $!";
my $header_line = <$example_fh>;
chomp($header_line);
my @headers = split("\t", $header_line);
Expand All @@ -121,6 +123,8 @@
close($example_fh);

$worksheet->set_row(0, 70);
$worksheet->set_row(1, 200);
$worksheet->set_row(2, 30);
$worksheet->set_column('A:ZZ', 30);
$worksheet->set_column('A:A', 30);
$worksheet->write($description_row, 0, $description, $formats{'description'});
Expand Down Expand Up @@ -253,9 +257,10 @@
}

my $tagtype = "categories";
my @category_entries = ProductOpener::TaxonomySuggestions::generate_sorted_list_of_taxonomy_entries($tagtype, $lc, {});
my @category_entries
= ProductOpener::TaxonomySuggestions::generate_sorted_list_of_taxonomy_entries($tagtype, $request_ref->{lc}, {});
foreach my $i (0 .. $#category_entries) {
my $category_entry = display_taxonomy_tag($lc, $tagtype, $category_entries[$i]);
my $category_entry = display_taxonomy_tag($request_ref->{lc}, $tagtype, $category_entries[$i]);
$worksheet_categories->write($i, 0, $category_entry);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
code lc product_name quantity_value_unit brands categories labels origins ingredients_text allergens traces energy-kj_100g_value_unit energy-kcal_100g_value_unit fat_100g_value_unit saturated-fat_100g_value_unit carbohydrates_100g_value_unit sugars_100g_value_unit fiber_100g_value_unit proteins_100g_value_unit salt_100g_value_unit fruits-vegetables-nuts_100g_value_unit fruits-vegetables-nuts-dried_100g_value_unit packaging_text image_front_url_fr image_ingredients_url_fr image_nutrition_url_fr image_packaging_url_fr image_other_type
Barcode Main language Product name Quantity Brands Categories Labels Countries where sold Ingredients list Allergens Traces Energy (kJ) for 100 g / 100 ml Energy (kcal) for 100 g / 100 ml Fat for 100 g / 100 ml Saturated fat for 100 g / 100 ml Carbohydrates for 100 g / 100 ml Sugars for 100 g / 100 ml Fiber for 100 g / 100 ml Proteins for 100 g / 100 ml Salt for 100 g / 100 ml Link to front product photo Link to ingredients list photo Link to nutrition facts table photo
en 3228857000838 en American Sandwich Nature 550 g Harrys Bran sliced breads Organic, No additives Spain, France, Italy wheat flour 65%, water, sugar, rapeseed oil, salt, vinegar, yeast, flour of beans, wheat gluten, flavor (contains alcohol), extract of acerola, may contain traces of eggs, soya, milk, fruit shell, sesame seeds Gluten Eggs, Milk, Nuts, Sesame seeds, Soybeans 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
fr 3228857000838 fr Sandwich américain nature 550 g Harrys Pains de mie tranchés Bio, sans additifs Espagne, France, Italie farine de blé 65%, eau, sucre, huile de colza, sel, vinaigre, levure, farine d'haricots, gluten de blé, arôme Gluten Oeufs, lait, fruits à coque, graines de sésame, soja 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
Barcode Main language Product name Quantity Brands Categories Labels Countries where sold Ingredients list Allergens Traces Energy (kJ) for 100 g / 100 ml Energy (kcal) for 100 g / 100 ml Fat for 100 g / 100 ml Saturated fat for 100 g / 100 ml Carbohydrates for 100 g / 100 ml Sugars for 100 g / 100 ml Fiber for 100 g / 100 ml Proteins for 100 g / 100 ml Salt for 100 g / 100 ml Link to front product photo Link to ingredients list photo Link to nutrition facts table photo
en 3228857000838 en American Sandwich Nature 550 g Harrys Bran sliced breads Organic, No additives Spain, France, Italy wheat flour 65%, water, sugar, rapeseed oil, salt, vinegar, yeast, flour of beans, wheat gluten, flavor (contains alcohol), extract of acerola, may contain traces of eggs, soya, milk, fruit shell, sesame seeds Gluten Eggs, Milk, Nuts, Sesame seeds, Soybeans 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
fr 3228857000838 fr Sandwich américain nature 550 g Harrys Pains de mie tranchés Bio, sans additifs Espagne, France, Italie farine de blé 65%, eau, sucre, huile de colza, sel, vinaigre, levure, farine d'haricots, gluten de blé, arôme Gluten Oeufs, lait, fruits à coque, graines de sésame, soja 1172 271 4.1 0.4 48.9 7.7 3.9 7.6 1.1 https://drive.google.com/file/d/1N6K0GOy8ZrO21732XF1M6klhRrzyAaaP/view?usp=sharing https://drive.google.com/file/d/14181RIHe89KN2aPzT3C2NQYqFZficOwE/view?usp=drive_link https://drive.google.com/file/d/1e8sW-Xp5QXc41V5ry-hLn8T8s13fvS38/view?usp=sharing
Binary file modified conf/pro-platform/Import template - Example translations.xlsx
Binary file not shown.
8 changes: 8 additions & 0 deletions lib/ProductOpener/Paths.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ Directory containing txt taxonomies

$BASE_DIRS{TAXONOMIES_SRC} = _source_dir() . "/taxonomies";

=head2 $BASE_DIRS{CONF}
Directory containing configuration files
=cut

$BASE_DIRS{CONF} = _source_dir() . "/conf";

=head2 $BASE_DIRS{PRIVATE_DATA}
Directory for private data
Expand Down
1 change: 1 addition & 0 deletions tests/unit/paths.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ my $EXPECTED_BASE_PATHS = {
CACHE_DEBUG => "$data_root/debug",
CACHE_NEW_IMAGES => "$data_root/new_images",
CACHE_TMP => "$data_root/tmp",
CONF => "$src_root/conf",
DELETED_IMAGES => "$data_root/deleted.images",
DELETED_PRIVATE_PRODUCTS => "$data_root/deleted_private_products",
DELETED_PRODUCTS => "$data_root/deleted_products",
Expand Down

0 comments on commit 6844c75

Please sign in to comment.