diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index 7f6363beab..afaa7758a4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -507,7 +507,7 @@ [% END # IF RequestOnOpac %] [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) %] - [% IF Koha.Preference('ArticleRequests') %] + [% IF SEARCH_RESULT.artreqpossible %] Request article [% END %] [% END %] diff --git a/opac/opac-search.pl b/opac/opac-search.pl index fbc0c308e8..b36aaafacc 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -56,6 +56,7 @@ use Koha::ItemTypes; use Koha::Ratings; use Koha::Virtualshelves; use Koha::Library::Groups; +use Koha::Patrons; use POSIX qw(ceil floor strftime); use URI::Escape; @@ -641,6 +642,12 @@ for (my $i=0;$i<@servers;$i++) { } $hits = 0 unless @newresults; + my $categorycode; # needed for may_article_request + if( $borrowernumber && C4::Context->preference('ArticleRequests') ) { + my $patron = Koha::Patrons->find( $borrowernumber ); + $categorycode = $patron ? $patron->categorycode : undef; + } + foreach my $res (@newresults) { # must define a value for size if not present in DB @@ -696,6 +703,12 @@ for (my $i=0;$i<@servers;$i++) { $res->{ratings} = $ratings; $res->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; } + + # BZ17530: 'Intelligent' guess if result can be article requested + $res->{artreqpossible} = Koha::Biblio->may_article_request({ + categorycode => $categorycode, + itemtype => $res->{itemtype}, + }); } if ($results_hashref->{$server}->{"hits"}){