Skip to content

Commit

Permalink
fix: Replace existing values with Producer Supplied Allergens and Tra…
Browse files Browse the repository at this point in the history
…ces values (#8538)
  • Loading branch information
MonalikaPatnaik authored Jun 19, 2023
1 parent e7d3503 commit 82fbf7c
Show file tree
Hide file tree
Showing 21 changed files with 4,313 additions and 28 deletions.
5 changes: 5 additions & 0 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ $options{categories_exempted_from_nutrient_levels} = [
)
];

$options{replace_existing_values_when_importing_those_tags_fields} = {
"allergens" => 1,
"traces" => 1,
};

# fields for which we will load taxonomies
# note: taxonomies that are used as properties of other taxonomies must be loaded first
# (e.g. additives_classes are referenced in additives)
Expand Down
10 changes: 10 additions & 0 deletions lib/ProductOpener/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use Log::Any qw($log);

use Storable qw(dclone);
use Text::Fuzzy;
use Data::DeepAccess qw(deep_exists);

BEGIN {
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
Expand Down Expand Up @@ -519,6 +520,15 @@ sub set_field_value (
$product_ref->{$field} = "";
delete $product_ref->{$field . "_tags"};
}

# If we are on the producers platform, replace existing values by producer supplied values for allergens and traces
if (deep_exists(\%options, "replace_existing_values_when_importing_those_tags_fields", $field)) {
if ($imported_product_ref->{$field} ne "") {
$product_ref->{$field} = "";
delete $product_ref->{$field . "_tags"};
}
}

# existing is the list of already existing tags
# that will be completed with more values
my %existing = ();
Expand Down
Loading

0 comments on commit 82fbf7c

Please sign in to comment.