From 76897ec7f8692b19007ce26f8ee5ec71da97ef27 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Fri, 29 Jul 2022 13:06:07 +0200
Subject: [PATCH] Bug 27272: Allow to pass params and attributes to
 search_ordered

---
 Koha/Items.pm | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/Koha/Items.pm b/Koha/Items.pm
index 04db9654aae..9bc35fdf135 100644
--- a/Koha/Items.pm
+++ b/Koha/Items.pm
@@ -407,10 +407,22 @@ Search and sort items in a specific order, depending if serials are present or n
 =cut
 
 sub search_ordered {
-    my ($self) = @_;
+    my ($self, $params, $attributes) = @_;
+
+    $self = $self->search($params, $attributes);
 
-    if ( $self->search({ select => ["enumchron IS NOT NULL"] }) ) {
-        return $self->search( {}, { order_by => 'enumchron' } );
+    my @biblionumbers = $self->get_column('biblionumber');
+
+    if ( @biblionumbers == 1
+        && Koha::Biblios->find( $biblionumbers[0] )->serial )
+    {
+        return $self->search(
+            {},
+            {
+                order_by => [ 'serial.publisheddate', 'me.enumchron' ],
+                join     => 'serial'
+            }
+        );
     } else {
         return $self->search(
             {},
-- 
2.25.1