From 8c844b1cadafa889f5ff53c25e643380ceabc902 Mon Sep 17 00:00:00 2001 From: areeshatariq Date: Thu, 9 Jul 2020 19:13:45 +0500 Subject: [PATCH] Search and display products templatization (#3802) * Display products wip * Display products template * Changed template file name --- lib/ProductOpener/Display.pm | 135 ++++++------------ templates/search_and_display_products.tt.html | 73 ++++++++++ 2 files changed, 118 insertions(+), 90 deletions(-) create mode 100755 templates/search_and_display_products.tt.html diff --git a/lib/ProductOpener/Display.pm b/lib/ProductOpener/Display.pm index 11621bf608e9d..e85c5b4d28212 100644 --- a/lib/ProductOpener/Display.pm +++ b/lib/ProductOpener/Display.pm @@ -3921,6 +3921,11 @@ sub search_and_display_products($$$$$) { my $limit = shift; my $page = shift; + my $template_data_ref = { + lang => \&lang, + display_pagination => \&display_pagination, + }; + $log->debug("request_ref: ". Dumper($request_ref)."query_ref: ". Dumper($query_ref)) if $log->is_debug(); add_country_and_owner_filters_to_query($request_ref, $query_ref); @@ -4102,15 +4107,16 @@ sub search_and_display_products($$$$$) { my $html = ''; my $html_count = ''; + my $error = ''; my $decf = get_decimal_formatter($lc); if (not defined $request_ref->{jqm_loadmore}) { if ($count < 0) { - $html .= "

" . lang("error_database") . "

"; + $error = lang("error_database"); } elsif ($count == 0) { - $html .= "

" . lang("no_products") . "

"; + $error = lang("no_products"); } elsif ($count == 1) { $html_count .= lang("1_product"); @@ -4118,36 +4124,26 @@ sub search_and_display_products($$$$$) { elsif ($count > 1) { $html_count .= sprintf(lang("n_products"), $decf->format($count)) ; } + $template_data_ref->{error} = $error; + $template_data_ref->{html_count} = $html_count; } - if ((defined $request_ref->{current_link_query}) and (not defined $request_ref->{jqm})) { - - if ($country ne 'en:world') { - $html .= "

{current_link_query} . "&action=display\">" . lang('view_results_from_the_entire_world') . "

"; - } - - $request_ref->{current_link_query_display} = $request_ref->{current_link_query}; - $html .= "→ {current_link_query_display}&action=display\">" . lang("search_link") . "
"; - $request_ref->{current_link_query_display} =~ s/\?action=process/\?action=display/; - $html .= "→ {current_link_query_display}&action=display\">" . lang("search_edit") . "
"; - - - } + $template_data_ref->{current_link_query} = $request_ref->{current_link_query}; + $template_data_ref->{jqm} = $request_ref->{jqm}; + $template_data_ref->{country} = $country; + $template_data_ref->{world_subdomain} = $world_subdomain; + $template_data_ref->{current_link_query} = $request_ref->{current_link_query}; + + $request_ref->{current_link_query_display} =~ s/\?action=process/\?action=display/; + $template_data_ref->{current_link_query_display} = $request_ref->{current_link_query_display}; + $template_data_ref->{count} = $count; if ($count > 0) { + $request_ref->{current_link_query_download} = $request_ref->{current_link_query}; + $request_ref->{current_link_query_download} .= "&download=on"; - if ((defined $request_ref->{current_link_query}) and (not defined $request_ref->{jqm})) { - $request_ref->{current_link_query_download} = $request_ref->{current_link_query}; - $request_ref->{current_link_query_download} .= "&download=on"; - $html .= "→ " . lang("search_download_results") . "
"; - - if ($count <= $export_limit) { - $html .= ""; - } - } + $template_data_ref->{current_link_query_download} = $request_ref->{current_link_query_download}; + $template_data_ref->{export_limit} = $export_limit; if ($log->is_debug()) { my $debug_log = "search - count: $count"; @@ -4158,7 +4154,7 @@ sub search_and_display_products($$$$$) { if ((not defined $request_ref->{search}) and ($count >= 5) and (not defined $request_ref->{tagid2}) and (not defined $request_ref->{product_changes_saved})) { - + $template_data_ref->{explore_products} = 'true'; my $nofollow = ''; if (defined $request_ref->{tagid}) { # Prevent crawlers from going too deep in facets #938: @@ -4170,36 +4166,20 @@ sub search_and_display_products($$$$$) { if ($country eq 'en:world') { unshift (@current_drilldown_fields, "countries"); } - $html .= < -
  • $html_count
  • -
  • - -\n
  • \n\n\n"; - - - } - else { - $html .= "

    $html_count " . separator_before_colon($lc) . ":

    "; - } - - if (defined $request_ref->{jqm}) { - if (not defined $request_ref->{jqm_loadmore}) { - $html .= '