Bug 20763: AllowPurchaseSuggestionBranchChoice triggers error opac-suggestions.pl...
authorKyle M Hall <kyle@bywatetsolutions.com>
Mon, 14 May 2018 12:45:00 +0000 (08:45 -0400)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 4 Jun 2018 12:58:52 +0000 (12:58 +0000)
Some code executed in the script opac-suggestions.pl if the system preference AllowPurchaseSuggestionBranchChoice is enabled assumes there is a logged in user. If there is not, patrons will see the error "Internal Server Error".

Test Plan:
1) Enable AllowPurchaseSuggestionBranchChoice
2) Enable AnonSuggestions
3) In the OPAC, perform a search that will have no results,
   click the "Make a purchase suggestion" link.
4) Note the error
5) Apply this patch
6) Reload the page
7) The page should load now!

Signed-off-by: Pierre-Luc Lapointe <pierreluc.lapointe@inLibro.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
opac/opac-suggestions.pl

index e086b14..c29278c 100755 (executable)
@@ -196,16 +196,18 @@ my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
 
 # Is the person allowed to choose their branch
 if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
+    my $branchcode = $input->param('branchcode') || q{};
 
-# pass the pickup branch along....
-    my $userbranch = '';
-    if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
-        $userbranch = C4::Context->userenv->{'branch'};
+    if ( !$branchcode && $borrowernumber ) {
+        my $patron = Koha::Patrons->find($borrowernumber);
+        $branchcode = $patron->branchcode;
     }
-    my $branchcode = $input->param('branchcode');
-    unless ( $branchcode ) {
-        my $patron = Koha::Patrons->find( $borrowernumber );
-        $branchcode = $patron->branchcode || $userbranch || '' ;
+
+    if (   !$branchcode
+        && C4::Context->userenv
+        && C4::Context->userenv->{branch} )
+    {
+        $branchcode = C4::Context->userenv->{branch};
     }
 
     $template->param( branchcode => $branchcode );