From 00abfedf8de3d159ca8a7c81dee380a4f7b75dbb Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Thu, 11 May 2017 13:07:37 -0300
Subject: [PATCH] Bug 18579: Make EmbedItemsAvailability handle control fields
 correctly
Content-Type: text/plain; charset=utf-8

This patch makes the EmbedItemsAvailability filter handle the biblio.biblionumber > control field mapping gracefully.
Right now, it was assuming a regular data field was used, and such is not the case for UNIMARC (001).

To test:
- Apply the tests patch
- Run:
  $ sudo koha-shell kohadev
 k$ cd kohaclone
 k$ prove t/db_dependent/Koha/Filter/EmbedItemsAvailability.t
=> FAIL: Tests fail to run
- Apply this patch
- Run:
 k$ prove t/db_dependent/Koha/Filter/EmbedItemsAvailability.t
=> SUCCESS: Tests pass!
- Sign off :-D

Sponsored-by: ByWater Solutions

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 Koha/Filter/MARC/EmbedItemsAvailability.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Koha/Filter/MARC/EmbedItemsAvailability.pm b/Koha/Filter/MARC/EmbedItemsAvailability.pm
index 2f23036..e42ba02 100644
--- a/Koha/Filter/MARC/EmbedItemsAvailability.pm
+++ b/Koha/Filter/MARC/EmbedItemsAvailability.pm
@@ -72,7 +72,9 @@ sub _processrecord {
     my $record = shift;
 
     my ($biblionumber_field, $biblionumber_subfield) = GetMarcFromKohaField("biblio.biblionumber", '');
-    my $biblionumber = $record->field($biblionumber_field)->subfield($biblionumber_subfield);
+    my $biblionumber  = ( $biblionumber_field > 9 )
+                      ? $record->field($biblionumber_field)->subfield($biblionumber_subfield)
+                      : $record->field($biblionumber_field)->data();
 
     my $not_onloan_items = Koha::Items->search({
         biblionumber => $biblionumber,
-- 
2.1.4