From 00e1f37b5c5e20096c7960291f2a60a66c1ff653 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Tue, 9 Apr 2019 15:59:14 -0300
Subject: [PATCH] Bug 22675: Fix SCO behaviour on non-existent barcodes

Bug 21206 replaced GetItem for Koha::Items->find, and introduced this
problem. This patch verifies $item is defined before attempting to use
its methods.

To test:
- Log into SCO
- Type an invalid barcode
=> FAIL: Things explode :-/
- Apply this patch, reload
- Type an invalid barcode
=> SUCCESS: A nice error message is displayed :-D
- Sign off :-D

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
---
 opac/sco/sco-main.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl
index 7fd6ee8e40..a303524630 100755
--- a/opac/sco/sco-main.pl
+++ b/opac/sco/sco-main.pl
@@ -158,11 +158,12 @@ elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) {
     if (scalar keys %$impossible) {
 
         my $issue_error = (keys %$impossible)[0]; # FIXME This is wrong, we assume only one error and keys are not ordered
+        my $title = ( $item ) ? $item->biblio->title : '';
 
         $template->param(
             impossible                => $issue_error,
             "circ_error_$issue_error" => 1,
-            title                     => $item->biblio->title, # FIXME Need to be backport! GetItem did not return the biblio's title
+            title                     => $title,
             hide_main                 => 1,
         );
         if ($issue_error eq 'DEBT') {
-- 
2.11.0