From 0f5eac52dd9d6711a85161474a2acae606ad7ddd Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Tue, 3 Mar 2026 19:28:01 +0000 Subject: [PATCH] Bug 41982: Linked items resulting from EasyAnalyticalRecords are not shown on OPAC results page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using EasyAnalyticalRecords, "virtual" items originating from host records are shown in: 1) staff detail, 2) staff results, 3) OPAC detail, but not on OPAC results page. This is confusing and inconsistent. To reproduce (in ktd): 1. Turn EasyAnalyticalRecords on. 2. Link the item 3999900000001 (originating from biblio #1) to biblio #2 (with New > Link to host record). 3. Check that you are able to see the linked item in staff detail and OPAC detail (biblio record #2) and also on the staff results page (make a search with the word 'behind'). Verify that on the OPAC results page (with the same search) you get: "Availability: No items available." 4. Apply the patch ; restart_all 5. Repeat p. 3. You should now be able to see information from the linked item on OPAC results page. Sponsored-by: Pontificia Università di San Tommaso d'Aquino (Angelicum) --- C4/XSLT.pm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index be3ac7d41f..46c82181a9 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -335,6 +335,34 @@ sub buildKohaItemsNamespace { $items_rs = Koha::Items->new; } + # adding linked items that belong to host records + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + my $marcflavor = C4::Context->preference("marcflavour"); + my $analyticsfield = '773'; + if ( $marcflavor eq 'MARC21' ) { + $analyticsfield = '773'; + } elsif ( $marcflavor eq 'UNIMARC' ) { + $analyticsfield = '461'; + } + my $marcrecord = Koha::Biblios->find($biblionumber)->metadata->record; + my $query_linked = []; + foreach my $hostfield ( $marcrecord->field($analyticsfield) ) { + my $hostbiblionumber = $hostfield->subfield("0"); + my $linkeditemnumber = $hostfield->subfield("9"); + if ( $hostbiblionumber && $linkeditemnumber ) { + push @$query_linked, + { + 'me.biblionumber' => $hostbiblionumber, + 'me.itemnumber' => { '=' => $linkeditemnumber, not_in => $hidden_items } + }; + } + } + if (@$query_linked) { + unshift @$query_linked, $query; + $query = { "-or" => $query_linked }; + } + } + my $items = $items_rs->search( $query, { prefetch => [ 'current_branchtransfers', 'reserves', 'tmp_holdsqueue' ] } ); -- 2.39.5