Bug 19048: (bug 17829 follow-up) Fix regression in self checkout
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 7 Aug 2017 12:54:27 +0000 (09:54 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 8 Aug 2017 12:20:50 +0000 (09:20 -0300)
$patronid is not necessarily set or does not match a valid cardnumber.
These cases must be taken into account to avoid the script to crash and
raise the following error:
Can't call method "unblessed" on an undefined value at
(...)/koha/opac/sco/sco-main.pl line 117

Test plan:
Hit sco/sco-main.pl and confirm that the error is gone with this patch
applied

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
opac/sco/sco-main.pl

index 80ac47d..4020e27 100755 (executable)
@@ -114,7 +114,12 @@ if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
     my $resval;
     ($resval, $patronid) = checkpw($dbh, $patronlogin, $patronpw);
 }
-my $borrower = Koha::Patrons->find( { cardnumber => $patronid } )->unblessed;
+
+my $borrower;
+if ( $patronid ) {
+    $borrower = Koha::Patrons->find( { cardnumber => $patronid } );
+    $borrower = $borrower->unblessed if $borrower;
+}
 
 my $currencySymbol = "";
 if ( my $active_currency = Koha::Acquisition::Currencies->get_active ) {
@@ -131,10 +136,8 @@ if ($op eq "logout") {
 }
 elsif ( $op eq "returnbook" && $allowselfcheckreturns ) {
     my ($doreturn) = AddReturn( $barcode, $branch );
-    #warn "returnbook: " . $doreturn;
-    $borrower = Koha::Patrons->find( { cardnumber => $patronid } )->unblessed;
 }
-elsif ( $op eq "checkout" ) {
+elsif ( $borrower and $op eq "checkout" ) {
     my $impossible  = {};
     my $needconfirm = {};
     ( $impossible, $needconfirm ) = CanBookBeIssued(
@@ -250,7 +253,7 @@ elsif ( $op eq "checkout" ) {
     }
 } # $op
 
-if ($borrower->{cardnumber}) {
+if ($borrower) {
 #   warn "issuer's  branchcode: " .   $issuer->{branchcode};
 #   warn   "user's  branchcode: " . $borrower->{branchcode};
     my $borrowername = sprintf "%s %s", ($borrower->{firstname} || ''), ($borrower->{surname} || '');