From 4ce82d0c605fe8876ffa5206d0a858faa9fc273f Mon Sep 17 00:00:00 2001
From: Josef Moravec <josef.moravec@gmail.com>
Date: Thu, 14 Mar 2019 13:23:19 +0000
Subject: [PATCH] Bug 8995: (follow-up) Take system preference
 item-level_itypes into account

Signed-off-by: Magnus Enger <magnus@libriotech.no>
Tested with all 9 current patches. Works as advertised, including
OPACURLOpenInNewWindow. If a record has no items, no OpenURL link
is displayed. All the suggested tests pass. I did not test with
XSLT turned off.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 C4/XSLT.pm | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index fb2752c683..da9d350532 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -247,11 +247,18 @@ sub XSLTParse4Display {
 
     $variables ||= {};
     if (C4::Context->preference('OPACShowOpenURL')) {
-        my $biblio_object = Koha::Biblios->find($biblionumber);
-        my $biblio = $biblio_object->biblioitem->unblessed;
+        my @biblio_itemtypes;
+        my $biblio = Koha::Biblios->find($biblionumber);
+        if (C4::Context->preference('item-level_itypes')) {
+            @biblio_itemtypes = $biblio->items->get_column("itype");
+        } else {
+            push @biblio_itemtypes, $biblio->biblioitem->itemtype;
+        }
         my @itypes = split( /\s/, C4::Context->preference('OPACOpenURLItemTypes') );
-        if (grep /^$biblio->{itemtype}$/, @itypes) {
-            $variables->{OpenURLResolverURL} = $biblio_object->get_openurl;
+        my %original = ();
+        map { $original{$_} = 1 } @biblio_itemtypes;
+        if ( grep { $original{$_} } @itypes ) {
+            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
         }
     }
     my $varxml = "<variables>\n";
-- 
2.20.1