Bug 21248: Fix COinS carp in MARC details page on unknown record
[srvgit] / catalogue / itemsearch.pl
index ee8ca66..ab833db 100755 (executable)
@@ -61,9 +61,15 @@ if (defined $format and $format eq 'json') {
             my @words = split /\s+/, $sSearch;
             foreach my $word (@words) {
                 push @f, $columns[$i];
-                push @q, "%$word%";
-                push @op, 'like';
                 push @c, 'and';
+
+                if ( grep /^$columns[$i]$/, qw( ccode homebranch holdingbranch location notforloan ) ) {
+                    push @q, "$word";
+                    push @op, '=';
+                } else {
+                    push @q, "%$word%";
+                    push @op, 'like';
+                }
             }
         }
     }
@@ -91,10 +97,10 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user({
     flagsrequired   => { catalogue => 1 },
 });
 
-my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.notforloan', authorised_value => { not => undef } });
+my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.notforloan', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
 my $notforloan_values = $mss->count ? GetAuthorisedValues($mss->next->authorised_value) : [];
 
-$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.location', authorised_value => { not => undef } });
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.location', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
 my $location_values = $mss->count ? GetAuthorisedValues($mss->next->authorised_value) : [];
 
 if (scalar keys %params > 0) {
@@ -227,8 +233,9 @@ if (scalar keys %params > 0) {
         }
 
         foreach my $item (@$results) {
-            $item->{biblio} = Koha::Biblios->find( $item->{biblionumber} );
-            ($item->{biblioitem}) = GetBiblioItemByBiblioNumber($item->{biblionumber});
+            my $biblio = Koha::Biblios->find( $item->{biblionumber} );
+            $item->{biblio} = $biblio;
+            $item->{biblioitem} = $biblio->biblioitem->unblessed;
             $item->{status} = $notforloan_map->{$item->{notforloan}};
             if (defined $item->{location}) {
                 $item->{location} = $location_map->{$item->{location}};
@@ -253,6 +260,7 @@ if (scalar keys %params > 0) {
             print "$line\n" unless $line =~ m|^\s*$|;
         }
     } elsif ($format eq 'json') {
+        $template->param(sEcho => scalar $cgi->param('sEcho'));
         output_with_http_headers $cgi, $cookie, $template->output, 'json';
     }
 
@@ -277,7 +285,7 @@ foreach my $itemtype ( Koha::ItemTypes->search ) {
     };
 }
 
-$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
 my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
 my $ccodes = GetAuthorisedValues($ccode_avcode);
 my @ccodes;