From 4413276810f533d4f65da014be073f02ed34d283 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 26 Oct 2021 11:22:04 +0000 Subject: [PATCH] Bug 29320: Update OverDrive availability to V2 This patch updates the call to overdrive_proxy to allow passing a version and updates the code to use V2 for availability To test: 1 - Enable OverDrive integration by setting the sysprefs 2 - Log in to your overdrive account in the Koha opac 3 - Perform a search and note availability display 4 - Confirm you can checkout/hold/return books 5 - Apply patch 6 - Repeat search and test functionality 7 - Note that title with '0 out of 0 copies available' now say 'Currently unavailable' Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- .../bootstrap/en/modules/opac-overdrive-search.tt | 10 +++++++--- koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js | 2 +- opac/svc/overdrive_proxy | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt index 1ca0dac2f3..794fe29848 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt @@ -82,13 +82,17 @@ $availability_summary.html( '' + _("Availability:") + ' ' + _("Loading...") ); KOHA.OverDrive.Get( - prod.links.availability.href, - {}, + prod.links.availabilityV2.href, + { version: 2}, function ( data ) { if ( data.error ) return; if( data.availabilityType == 'AlwaysAvailable' ){ $availability_summary.html( '' + _("Availability:") + ' ' + '' + _("Always available") + '' ); + } else if ( data.availabilityType == 'LimitedAvailability' && data.available ) { + $availability_summary.html( '' + _("Availability:") + ' ' + '' + _("Currently available") + '' ); + } else if ( !data.available ) { + $availability_summary.html( '' + _("Availability:") + ' ' + '' + _("Currently unavailable") + '' ); } else { $availability_summary.html( '' + _("Availability:") + ' ' + '' + _("Items available:") + ' ' + data.copiesAvailable + " " + _("out of") + ' ' + data.copiesOwned + '' ); } @@ -98,7 +102,7 @@ } $tr.find( '.info' ).each(function() { - KOHA.OverDriveCirculation.add_actions(this, data.id, data.copiesAvailable); + KOHA.OverDriveCirculation.add_actions(this, data.reserveId, data.copiesAvailable); }); } ); diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js b/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js index 0d95baf27d..2dd332ea2c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js @@ -11,7 +11,7 @@ KOHA.OverDrive = ( function() { Get: function( url, params, callback ) { $.ajax( { type: 'GET', - url: url.replace( /https?:\/\/api.overdrive.com\/v1/, proxy_base_url ), + url: url.replace( /https?:\/\/api.overdrive.com\/v[1|2]/, proxy_base_url ), dataType: 'json', data: params, error: function( xhr, error ) { diff --git a/opac/svc/overdrive_proxy b/opac/svc/overdrive_proxy index 9df4d0cd07..9422079b7d 100755 --- a/opac/svc/overdrive_proxy +++ b/opac/svc/overdrive_proxy @@ -59,10 +59,11 @@ if ( !(C4::Context->preference('OverDriveClientKey') && C4::Context->preference( exit; } +my $version = $query->param('version') // 1; my $fixed_query = $query->query_string; $fixed_query =~ tr/;/&/; -my $request = HTTP::Request::Common::GET( "https://api.overdrive.com/v1" . $query->path_info . '?' . $fixed_query ); +my $request = HTTP::Request::Common::GET( "https://api.overdrive.com/v$version" . $query->path_info . '?' . $fixed_query ); $request->header( Authorization => $token ); my $ua = LWP::UserAgent->new( "Koha " . Koha::version() ); -- 2.39.5