From 5590d09fe7b400711ada4c9abdda37b34589a8ee 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 JK: Remove unused @itemnumbers_on_order variable Signed-off-by: Joonas Kylmälä Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- .../bootstrap/en/includes/item-status.inc | 2 +- opac/opac-detail.pl | 17 ++--------------- 2 files changed, 3 insertions(+), 16 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 5f08752a13..414f522768 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -651,19 +651,10 @@ $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} = { @@ -739,10 +730,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.39.5