From 3e508ff5c7c7205d6124e9a0099910e0717fcb85 Mon Sep 17 00:00:00 2001 From: danyonsewell Date: Tue, 20 Aug 2024 05:11:45 +0000 Subject: [PATCH] Bug 37463: Show Amazon cover images in checkouts table for selected patron categories This patch allows cover images to display in the patron checkout module for selected patron categories but only ones from Amazon for now. Test plan: Step 1 - apply this patch Step 2 - Make sure AmazonCoverImages syspref is set to "show" step 3 - Search for the CoverImagesCategories syspref and enable it for a specific patron category (choose the category that your patron account is) step 4 - checkout an item to your patron account step 5 - in the patron checkouts page, click the "show checkouts" button, you should see the items cover image there, as long as there is one available from Amazon Sponsored by: Pymble Ladies College --- ...37463-add_CoverImagesCategories_syspref.pl | 16 +++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/circulation.pref | 5 +++++ koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 20 +++++++++++++++++++ svc/checkouts | 16 +++++++++++++-- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl diff --git a/installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl b/installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl new file mode 100755 index 00000000000..0ab6e4d78bf --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "37463", + description => "Add new system preference CoverImagesCategories", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('CoverImagesCategories', '', NULL, 'Cover images will show in the patron checkouts table for selected patron categories. Please note: this only currently works for Amazon cover images.:', 'Free')} + ); + + say $out "Added system preference 'CoverImagesCategories'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 682b9fb950b..fce376cc6f7 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -177,6 +177,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ContentWarningField', '', NULL, 'MARC field to use for content warnings', 'Free'), ('CookieConsent', '0', NULL, 'Require cookie consent to be displayed', 'YesNo'), ('CookieConsentedJS', '', NULL, 'Add Javascript code that will run if cookie consent is provided (e.g. tracking code).', 'Free'), +('CoverImagesCategories', '', NULL, 'Cover images will show in the patron checkouts table for selected patron categories. Please note: this only currently works for Amazon cover images', 'Free'), ('CreateAVFromCataloguing', '1', '', 'Ability to create authorized values from the cataloguing module', 'YesNo'), ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'), ('CSVDelimiter',',',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 7192181ea4e..6888b610db3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -1307,6 +1307,11 @@ Circulation: - pref: SelfCheckAllowByIPRanges class: short - (Leave blank if not used. Use ranges or simple IP addresses separated by spaces, like 192.168.1.1 192.168.0.0/24.) + - + - "Cover images will show in the patron checkouts table for selected patron categories. Please note: this only currently works for Amazon cover images" + - pref: CoverImagesCategories + choices: patron-categories + class: multiple - - "Patron categories allowed to check out in a batch while logged into the self checkout system:" - pref: SCOBatchCheckoutsValidCategories diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index 394d319cbba..808a55eea64 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -165,6 +165,26 @@ function LoadIssuesTable() { + "" + onsite_checkout + if (oObj.showcoverimage == 1 ) { + var amazonurl = 'https://images-na.ssl-images-amazon.com/images/P/' + oObj.isbn + '.01.MZZZZZZZ.jpg'; + var img = new Image(); + img.src = amazonurl; + var w = img.width; + var h = img.height; + if (w == 1 && h == 1) { + /* Amazon returned single-pixel placeholder */ + } + else { + title += '
' + + 'Amazon cover image
Image from Amazon.com
'; + } + } return title; }, "type": "anti-the" diff --git a/svc/checkouts b/svc/checkouts index dd8d1d0f820..015e8b265f0 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -240,6 +240,16 @@ while ( my $c = $sth->fetchrow_hashref() ) { } } + my @coverimagescategories = split( ",", C4::Context->preference("CoverImagesCategories") ); + my $showcoverimage = 0; + my $patroncategory = Koha::Patrons->find( $c->{borrowernumber} )->categorycode; + if ( grep( /^$patroncategory$/, @coverimagescategories ) ) { + $showcoverimage = 1; + } + + my $biblio = Koha::Biblios->find( $c->{biblionumber} ); + my $isbn = $biblio->normalized_isbn; + my $checkout = { DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber}, title => $c->{title}, @@ -305,8 +315,10 @@ while ( my $c = $sth->fetchrow_hashref() ) { firstname => $c->{firstname}, cardnumber => $c->{cardnumber}, }, - issued_today => !$c->{not_issued_today}, - recalled => $recalled, + issued_today => !$c->{not_issued_today}, + recalled => $recalled, + isbn => $isbn, + showcoverimage => $showcoverimage, }; if ( $c->{not_issued_today} ) { -- 2.39.5