+ # Does this backend enable us to insert an availability stage and should
+ # we? If not, proceed as normal.
+ if (
+ # If the user has elected to continue with the request despite
+ # having viewed availability info, this flag will be set
+ C4::Context->preference("ILLCheckAvailability")
+ && !$params->{checked_availability}
+ && $request->_backend_capability( 'should_display_availability', $params )
+ ) {
+ # Establish which of the installed availability providers
+ # can service our metadata
+ my $availability = Koha::Illrequest::Availability->new($params);
+ my $services = $availability->get_services({
+ ui_context => 'staff'
+ });
+ if (scalar @{$services} > 0) {
+ # Modify our method so we use the correct part of the
+ # template
+ $op = 'availability';
+ $params->{method} = 'availability';
+ delete $params->{stage};
+ # Prepare the metadata we're sending them
+ my $metadata = $availability->prep_metadata($params);
+ $template->param(
+ whole => $params,
+ metadata => $metadata,
+ services_json => scalar encode_json($services),
+ services => $services
+ );
+ } else {
+ # No services can process this metadata, so continue as normal
+ my $backend_result = $request->backend_create($params);
+ $template->param(
+ whole => $backend_result,
+ request => $request
+ );
+ handle_commit_maybe($backend_result, $request);
+ }
+ } else {
+ my $backend_result = $request->backend_create($params);
+ $template->param(
+ whole => $backend_result,
+ request => $request
+ );
+ handle_commit_maybe($backend_result, $request);
+ }