diff --git a/C4/Search.pm b/C4/Search.pm index dc5935d28c..211e1fe1b9 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1909,6 +1909,12 @@ sub searchResults { my $lang = $xslfile ? C4::Languages::getlanguage() : undef; my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; + my $userenv = C4::Context->userenv; + my $patron = ( defined $userenv and $userenv->{number} ) + ? Koha::Patrons->find( $userenv->{number} ) + : undef; + my $patron_category_hide_lost_items = ($patron) ? $patron->category->hidelostitems : 0; + # loop through all of the records we've retrieved for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) { @@ -2095,11 +2101,8 @@ sub searchResults { my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item - my $userenv = C4::Context->userenv; if ( $item->{onloan} - && $userenv - && $userenv->{number} - && !( Koha::Patrons->find($userenv->{number})->category->hidelostitems && $item->{itemlost} ) ) + and !( $patron_category_hide_lost_items and $item->{itemlost} ) ) { $onloan_count++; my $key = $prefix . $item->{onloan} . $item->{barcode};