From 23431f06b5b66025b9bff8984c89cc68b95fdeca Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 25 Aug 2022 13:12:19 +0000 Subject: [PATCH] Bug 31463: Add order status to opac-detail.pl This adds a check for the preference OPACAcquisitionDetails and fetches the active orders for the item if necessary Additionally, we simply the check for biblio orders to use object methods and remove code that stored order information in the item_info To test: 1 - Enable preference: OPACAcquisitionDetails 2 - Create a basket with items created on order, add an order for a biblio, close the basket 3 - Create a second basket as above, add an order with multiple copies, leave basket open 4 - View biblio on opac 5 - You should see 1 item marked on order, and "1 items on order" below items table 6 - Close second basket 7 - Reload opac view, now 3 on order and in message 8 - Reopen first basket 9 - Reload opac view, now 2 on order and in message --- .../bootstrap/en/includes/item-status.inc | 2 +- opac/opac-detail.pl | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc index 4c179ca0dd..ffa5b838b0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc @@ -103,7 +103,7 @@ [% END %] [% END %] -[% IF NOT ( item.isa('Koha::Item') ) AND item.on_order %][%# on_order is only set from opac-detail.pl %] +[% IF Koha.Preference('OPACAcquisitionDetails') AND ( item.isa('Koha::Item') ) AND ( item.orders.filter_by_active.count ) %][%# on_order is only set from opac-detail.pl %] [% SET itemavailable = 0 %] On order [% END %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index a7289f3d0a..eadcbc31d0 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -652,17 +652,9 @@ $template->param( # Get items on order my ( @itemnumbers_on_order ); if ( C4::Context->preference('OPACAcquisitionDetails' ) ) { - my $orders = C4::Acquisition::SearchOrders({ - biblionumber => $biblionumber, - ordered => 1, - }); + my $orders = $biblio->orders->filter_by_active; my $total_quantity = 0; - for my $order ( @$orders ) { - my $order = Koha::Acquisition::Orders->find( $order->{ordernumber} ); - my $basket = $order->basket; - if ( $basket->effective_create_items eq 'ordering' ) { - @itemnumbers_on_order = $order->items->get_column('itemnumber'); - } + while ( my $order = $orders->next ) { $total_quantity += $order->quantity; } $template->{VARS}->{acquisition_details} = { @@ -728,10 +720,6 @@ else { $item_info->{checkout} = $item->checkout; $item_info->{object} = $item; - if ( C4::Context->preference('OPACAcquisitionDetails') ) { - $item_info->{on_order} = 1 - if grep { $_ eq $item->itemnumber } @itemnumbers_on_order; - } if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) { $item_info->{cover_images} = $item->cover_images; -- 2.30.2