From a0876f37e4dc0d3292d9d86e842b746e570a56b6 Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Wed, 21 Aug 2019 02:24:11 +0000
Subject: [PATCH] Bug 23482: Fix BakerTaylor cover images on lists

While this needs a username/pass to fully test, it should be possible to
verify the code changes by comparing to opac-results code

To test:
1 - Enable BakerTaylor images
2 - Enter your usernme and password
3 - Do not fill the BookStore URL
4 - Verify OPAC covers are working
5 - Save some times with covers to a public list
6 - Verify they do not display in list
7 - Apply patch
8 - Verify images now work

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 15 +++++++++++++--
 opac/opac-shelves.pl                                     |  7 +++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
index ebaa86e27d..63b9a7128e 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
@@ -368,10 +368,21 @@
                                                             [% END %]
 
                                                         </a> <!-- / .p1 -->
-                                                        [% IF ( BakerTaylorEnabled ) %]
+                                                        [% IF ( Koha.Preference('BakerTaylorEnabled') && !Koha.Preference('BakerTaylorBookstoreURL') ) %]
                                                             [% bt_id = ( itemsloo.normalized_upc || itemsloo.normalized_isbn ) %]
                                                             [% IF ( bt_id ) %]
-                                                                <a href="https://[% BakerTaylorBookstoreURL | uri %][% bt_id | uri %]"><img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL | html %][% bt_id | html %]" /></a>
+                                                                <img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL | html %][% bt_id | html %]" />
+                                                            [% ELSE %]
+                                                                <span class="no-image">No cover image available</span>
+                                                            [% END %]
+                                                        [% END %]
+
+                                                        [% IF ( Koha.Preference('BakerTaylorEnabled') && Koha.Preference('BakerTaylorBookstoreURL') ) %]
+                                                            [% bt_id = ( itemsloo.normalized_upc || itemsloo.normalized_isbn ) %]
+                                                            [% IF ( bt_id ) %]
+                                                                <a href="https://[% Koha.Preference('BakerTaylorBookstoreURL') | uri %][% bt_id | uri %]">
+                                                                    <img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL | html %][% bt_id | html %]" />
+                                                                </a>
                                                             [% ELSE %]
                                                                 <span class="no-image">No cover image available</span>
                                                             [% END %]
diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl
index ebdcf13399..c0140c7a75 100755
--- a/opac/opac-shelves.pl
+++ b/opac/opac-shelves.pl
@@ -70,6 +70,13 @@ if( $op eq 'view' || $op eq 'list' ){
         });
 }
 
+if (C4::Context->preference("BakerTaylorEnabled")) {
+    $template->param(
+        BakerTaylorImageURL => &image_url(),
+        BakerTaylorLinkURL  => &link_url(),
+    );
+}
+
 my $referer  = $query->param('referer')  || $op;
 my $category = $query->param('category') || 1;
 my ( $shelf, $shelfnumber, @messages );
-- 
2.11.0