+my (@itemloop, @otheritemloop);
+my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
+if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
+ $template->param(SeparateHoldings => 1);
+}
+my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
+my $viewallitems = $query->param('viewallitems');
+my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
+
+# Get items on order
+my ( @itemnumbers_on_order );
+if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
+ my $orders = C4::Acquisition::SearchOrders({
+ biblionumber => $biblionumber,
+ ordered => 1,
+ });
+ my $total_quantity = 0;
+ for my $order ( @$orders ) {
+ if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
+ for my $itemnumber ( C4::Acquisition::GetItemnumbersFromOrder( $order->{ordernumber} ) ) {
+ push @itemnumbers_on_order, $itemnumber;
+ }
+ }
+ $total_quantity += $order->{quantity};
+ }
+ $template->{VARS}->{acquisition_details} = {
+ total_quantity => $total_quantity,
+ };
+}
+
+if ( not $viewallitems and @items > $max_items_to_display ) {
+ $template->param(
+ too_many_items => 1,
+ items_count => scalar( @items ),
+ );
+} else {
+ for my $itm (@items) {