+ if ( $patron ) {
+ my $patron_unblessed = $patron->unblessed;
+ my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
+
+ my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
+
+ $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
+
+ my $can_item_be_reserved = CanItemBeReserved( $patron, $item_object )->{status};
+ $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
+
+ $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
+
+ if (
+ !$item->{cantreserve}
+ && !$exceeded_maxreserves
+ && $can_item_be_reserved eq 'OK'
+ # items_any_available defined outside of the current loop,
+ # so we avoiding loop inside IsAvailableForItemLevelRequest:
+ && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
+ )
+ {
+ # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
+ my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list;
+ $item->{pickup_locations_count} = scalar @pickup_locations;
+
+ if ( @pickup_locations ) {
+ $num_available++;
+ $item->{available} = 1;
+
+ my $default_pickup_location;
+
+ # Default to logged-in, if valid
+ if ( C4::Context->userenv->{branch} ) {
+ ($default_pickup_location) = grep { $_->branchcode eq C4::Context->userenv->{branch} } @pickup_locations;
+ }
+
+ $item->{default_pickup_location} = $default_pickup_location;
+ }
+ else {
+ $item->{available} = 0;
+ $item->{not_holdable} = "no_valid_pickup_location";
+ }
+
+ push( @available_itemtypes, $item->{itype} );
+ }
+ elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
+ # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
+ # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
+ if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) {
+ # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
+ my $pickup_locations = $item_object->pickup_locations({ patron => $patron });
+ $item->{pickup_locations_count} = $pickup_locations->count;
+ if ( $item->{pickup_locations_count} > 0 ) {
+ $item->{override} = 1;
+ $num_override++;
+ # pass the holding branch for use as default
+ my $default_pickup_location = $pickup_locations->search({ branchcode => $item->{holdingbranch} })->next;
+ $item->{default_pickup_location} = $default_pickup_location;
+ }
+ else {
+ $item->{available} = 0;
+ $item->{not_holdable} = "no_valid_pickup_location";
+ }
+ } else { $num_alreadyheld++ }
+
+ push( @available_itemtypes, $item->{itype} );
+ }
+
+ # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
+
+ # Show serial enumeration when needed
+ if ($item->{enumchron}) {
+ $itemdata_enumchron = 1;
+ }
+ # Show collection when needed
+ if ($item->{ccode}) {
+ $itemdata_ccode = 1;
+ }
+ }