Bug 20832: Fix opac user profile page when there is overdue fine and no rental charge
[koha.git] / opac / opac-search.pl
index ebe870b..1d7615b 100755 (executable)
@@ -53,9 +53,9 @@ use C4::SocialData;
 use C4::External::OverDrive;
 
 use Koha::ItemTypes;
-use Koha::LibraryCategories;
 use Koha::Ratings;
 use Koha::Virtualshelves;
+use Koha::Library::Groups;
 
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
@@ -108,7 +108,7 @@ if ($format =~ /(rss|atom|opensearchdescription)/) {
 elsif (@params && $build_grouped_results) {
     $template_name = 'opac-results-grouped.tt';
 }
-elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) {
+elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) || @searchCategories ) {
     $template_name = 'opac-results.tt';
 }
 else {
@@ -214,8 +214,8 @@ if ($cgi->cookie("search_path_code")) {
     }
 }
 
-my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
-$template->param( searchdomainloop => $library_categories );
+my @search_groups = Koha::Library::Groups->get_search_groups();
+$template->param( search_groups => \@search_groups );
 
 # load the language limits (for search)
 my $languages_limit_loop = getLanguages($lang, 1);
@@ -226,7 +226,10 @@ my $itemtypes = GetItemTypesCategorized;
 # add translated_description to itemtypes
 foreach my $itemtype ( keys %{$itemtypes} ) {
     # Itemtypes search categories don't have (yet) translated descriptions, they are auth values (and could still have no descriptions too BZ 18400)
-    my $translated_description = Koha::ItemTypes->find( $itemtype )->translated_description;
+    # If 'iscat' (see ITEMTYPECAT) then there is no itemtype and the description is not translated
+    my $translated_description = $itemtypes->{$itemtype}->{iscat}
+      ? $itemtypes->{$itemtype}->{description}
+      : Koha::ItemTypes->find($itemtype)->translated_description;
     $itemtypes->{$itemtype}->{translated_description} = $translated_description || $itemtypes->{$itemtype}->{description} || q{};
 }
 
@@ -377,9 +380,6 @@ if ( $template_type && $template_type eq 'advsearch' ) {
         }
     }
 
-    if (C4::Context->preference('OPACNumbersPreferPhrase')) {
-        $template->param('numbersphr' => 1);
-    }
 
     output_html_with_http_headers $cgi, $cookie, $template->output;
     exit;
@@ -491,9 +491,9 @@ if (@searchCategories > 0) {
 @limits = map { uri_unescape($_) } @limits;
 
 if($params->{'multibranchlimit'}) {
-    my $library_category = Koha::LibraryCategories->find( $params->{multibranchlimit} );
-    my @libraries = $library_category->libraries;
-    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
+    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
+    my @libraries = $search_group->all_libraries;
+    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->branchcode } @libraries ) .')';
     push @limits, $multibranch if ($multibranch ne  '()');
 }