diff --git a/lib/ProductOpener/Display.pm b/lib/ProductOpener/Display.pm index 1b504328db7f1..0ada85c14f703 100644 --- a/lib/ProductOpener/Display.pm +++ b/lib/ProductOpener/Display.pm @@ -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 @@ -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}; } @@ -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"); diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index c66dd1a26569f..335dc9d8ce93d 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -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 @@ -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); } @@ -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. @@ -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(); @@ -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);