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

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
(cherry picked from commit 3f7c9f0f6c)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
Signed-off-by: Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz>
This commit is contained in:
Tomás Cohen Arazi 2026-03-04 10:11:43 -03:00 committed by Wainui Witika-Park
parent a45a642f35
commit d12c78f596
No known key found for this signature in database
GPG Key ID: 2D0A6AB5DAF1B78D
1 changed files with 2 additions and 1 deletions

View File

@ -300,7 +300,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;