From cafeb9528068d4d2de7ba167829cc19f35f1693c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Wed, 4 Mar 2026 10:11:43 -0300 Subject: [PATCH] Bug 40481: Fix OPAC MARC detail showing hidden items The OPAC MARC detail view (opac-MARCdetail.pl) uses $record->fields() to build the items table. This pulls item fields from the embedded MARC record, bypassing the OPACHiddenItems filtering done by filter_by_visible_in_opac. This patch replaces the $record->fields() call with the already-filtered $items resultset, converting each Koha::Item back to a MARC::Field via as_marc_field. Test plan: 1. Apply patch, do not restart plack yet 2. Setup: $ ktd --shell k$ koha-mysql kohadev <<< "UPDATE systempreferences SET value = 'damaged: [1]' WHERE variable = 'OpacHiddenItems';" k$ koha-mysql kohadev <<< "UPDATE items SET damaged = 1 WHERE biblionumber = 416 LIMIT 1;" k$ flush_memcached 3. Point your browser to the OPAC MARC detail view: http://kohadev.localhost/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=416 => FAIL: The damaged item is displayed in the items table 4. Restart plack: k$ restart_all 5. Refresh the page => SUCCESS: The damaged item is no longer displayed 6. Undo the test data: k$ koha-mysql kohadev <<< "UPDATE items SET damaged = 0 WHERE biblionumber = 416;" k$ koha-mysql kohadev <<< "UPDATE systempreferences SET value = '' WHERE variable = 'OpacHiddenItems';" k$ flush_memcached 7. Sign off :-D --- opac/opac-MARCdetail.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 03c2d18dd0..01ba8ff886 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -277,7 +277,8 @@ for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) { # warning : we may have different number of columns in each row. Thus, we first build a hash, complete it if necessary # then construct template. # $record has already had all the item fields filtered above. -my @fields = $record->fields(); +$items->reset(); +my @fields = map { $_->as_marc_field } $items->as_list; my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code my @item_subfield_codes; my @item_loop; -- 2.50.1 (Apple Git-155)