Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deactivate physical activities equivalence panel #6943

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4672,6 +4672,22 @@ sub add_params_to_query($$) {
}


=head2 initialize_knowledge_panels_options( $knowledge_panels_options_ref )

Initialize the options for knowledge panels from parameters.

=cut

sub initialize_knowledge_panels_options($) {

my $knowledge_panels_options_ref = shift;

# Activate physical activity knowledge panel only when specified
if (param("activate_knowledge_panel_physical_activities")) {
$knowledge_panels_options_ref->{activate_knowledge_panel_physical_activities} = 1;
}
}

=head2 customize_response_for_product ( $request_ref, $product_ref )

Using the fields parameter, API product or search queries can request
Expand Down Expand Up @@ -4819,6 +4835,7 @@ sub customize_response_for_product($$) {
}
# Knowledge panels in the $lc language
elsif ($field eq "knowledge_panels") {
initialize_knowledge_panels_options($knowledge_panels_options_ref);
create_knowledge_panels($product_ref, $lc, $cc, $knowledge_panels_options_ref);
$customized_product_ref->{$field} = $product_ref->{"knowledge_panels_" . $lc};
}
Expand Down Expand Up @@ -7539,6 +7556,7 @@ CSS
# for debugging and demonstration purposes
# Also activate them for moderators
if (($User{moderator}) or (param('panels'))) {
initialize_knowledge_panels_options($knowledge_panels_options_ref);
create_knowledge_panels($product_ref, $lc, $cc, $knowledge_panels_options_ref);
$template_data_ref->{environment_card_panel} = display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "environment_card");
$template_data_ref->{health_card_panel} = display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "health_card");
Expand Down
18 changes: 12 additions & 6 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ Needed for some country specific panels like the Eco-Score.

Defines how some panels should be created (or not created)

- skip_[panel_id] : do not create a specific panel
- deactivate_[panel_id] : do not create a default panel -- currently unimplemented
- activate_[panel_id] : create an on demand panel -- currently only for physical_activities panel

=head3 Return values

Expand Down Expand Up @@ -165,12 +166,12 @@ sub create_knowledge_panels($$$$) {
# Create recommendation panels first, as they will be included in cards such has the health card and environment card
create_recommendation_panels($product_ref, $target_lc, $target_cc);

create_health_card_panel($product_ref, $target_lc, $target_cc);
create_health_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
create_environment_card_panel($product_ref, $target_lc, $target_cc);

# Create the root panel that contains the panels we want to show directly on the product page
create_panel_from_json_template("root", "api/knowledge-panels/root.tt.json",
{}, $product_ref, $target_lc, $target_cc);
{}, $product_ref, $target_lc, $target_cc);
}


Expand Down Expand Up @@ -724,7 +725,7 @@ sub create_manufacturing_place_panel($$$) {
}


=head2 create_health_card_panel ( $product_ref, $target_lc, $target_cc )
=head2 create_health_card_panel ( $product_ref, $target_lc, $target_cc, $options_ref )

Creates a knowledge panel card that contains all knowledge panels related to health.

Expand All @@ -743,13 +744,16 @@ This parameter sets the desired language for the user facing strings.

We may display country specific recommendations from health authorities, or country specific scores.

=head4 options reference $options_ref

=cut

sub create_health_card_panel($$$) {
sub create_health_card_panel($$$$) {

my $product_ref = shift;
my $target_lc = shift;
my $target_cc = shift;
my $options_ref = shift;

$log->debug("create health card panel", { code => $product_ref->{code} }) if $log->is_debug();

Expand All @@ -759,7 +763,9 @@ sub create_health_card_panel($$$) {

create_nutrition_facts_table_panel($product_ref, $target_lc, $target_cc);

create_physical_activities_panel($product_ref, $target_lc, $target_cc);
if ($options_ref->{activate_knowledge_panel_physical_activities}) {
create_physical_activities_panel($product_ref, $target_lc, $target_cc);
}

create_serving_size_panel($product_ref, $target_lc, $target_cc);

Expand Down