Skip to content

Commit

Permalink
feat: add allergens and traces to ingredients panel (#6266)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet authored Jan 7, 2022
1 parent 696c661 commit 686f4fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,24 @@ sub process_template($$$) {
$template_data_ref->{url_for_text} = \&url_for_text;
$template_data_ref->{product_url} = \&product_url;
$template_data_ref->{product_name_brand_quantity} = \&product_name_brand_quantity;

# Display one taxonomy entry in the target language
$template_data_ref->{display_taxonomy_tag} = sub ($$) {
return display_taxonomy_tag($lc, $_[0], $_[1]);
};

# Display a list of taxonomy entries in the target language
$template_data_ref->{display_taxonomy_tags_list} = sub ($$) {
my $tagtype = shift;
my $tags_ref = shift;
if (defined $tags_ref) {
return join(", ", map {display_taxonomy_tag($lc, $tagtype, $_) } @$tags_ref) ;
}
else {
return "";
}
};

$template_data_ref->{round} = sub($) {
return sprintf ("%.0f", $_[0]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,25 @@
"edit_field_value": `[% panel.ingredients_text %]`,
},
},
[% IF product.allergens_tags && product.allergens_tags.size %]
{
"element_type": "text",
"text_element": {
"html": `<strong>[% lang("allergens_p").ucfirst %][% sep %]:</strong>
[% display_taxonomy_tags_list("allergens", product.allergens_tags) %]
`,
},
},
[% END %]
[% IF product.traces_tags && product.traces_tags.size %]
{
"element_type": "text",
"text_element": {
"html": `<strong>[% lang("traces_p").ucfirst %][% sep %]:</strong>
[% display_taxonomy_tags_list("traces", product.traces_tags) %]
`,
},
},
[% END %]
]
}

0 comments on commit 686f4fd

Please sign in to comment.