[Koha-patches] [PATCH 1/2] Bug 2920 Fixes Amazon content use in pro interface
Frédéric Demians
f.demians at tamil.fr
Sun Apr 26 22:33:34 CEST 2009
This patch fixes Amazon content use in pro interface :
* Control Amazon Editorial Review by a new syspref:
AmazonReviews.
* /catalogue/detail.tmpl doesn't display Amazon reader reviews.
It displays only Editorial review in Description tab.
This patch disable request for AWS reader reviews.
* Use Amazon TLD for linking book cover to local
Amazon Search Inside.
* Minor clean up on C4::External::Amazon.pm
---
C4/External/Amazon.pm | 66 ++++++-------------
catalogue/detail.pl | 23 +++++--
.../prog/en/modules/catalogue/detail.tmpl | 4 +-
3 files changed, 40 insertions(+), 53 deletions(-)
diff --git a/C4/External/Amazon.pm b/C4/External/Amazon.pm
index 78cdadf..f89200a 100644
--- a/C4/External/Amazon.pm
+++ b/C4/External/Amazon.pm
@@ -115,55 +115,31 @@ sub get_amazon_details {
$isbn = GetNormalizedISBN($isbn);
my $upc = GetNormalizedUPC($record,$marcflavour);
my $ean = GetNormalizedEAN($record,$marcflavour);
-
# warn "ISBN: $isbn | UPC: $upc | EAN: $ean";
- my ( $id_type, $item_id);
- if (defined($isbn) && length($isbn) == 13) { # if the isbn is 13-digit, search Amazon using EAN
- $id_type = 'EAN';
- $item_id = $isbn;
- }
- elsif ($isbn) {
- $id_type = 'ASIN';
- $item_id = $isbn;
- }
- elsif ($upc) {
- $id_type = 'UPC';
- $item_id = $upc;
- }
- elsif ($ean) {
- $id_type = 'EAN';
- $item_id = $upc;
- }
- else { # if no ISBN, UPC, or EAN exists, do not even attempt to query Amazon
- return undef;
- }
+ # Choose the appropriate and available item identifier
+ my ( $id_type, $item_id ) =
+ defined($isbn) && length($isbn) == 13 ? ( 'EAN', $isbn ) :
+ $isbn ? ( 'ASIN', $isbn ) :
+ $upc ? ( 'UPC', $upc ) :
+ $ean ? ( 'EAN', $upc ) : ( undef, undef );
+ return unless defined($id_type);
# grab the item format to determine Amazon search index
- # FIXME: This is MARC21 specific
- my $format = substr $record->leader(), 6, 1;
- my $formats;
- $formats->{'a'} = 'Books';
- $formats->{'g'} = 'Video';
- $formats->{'j'} = 'Music';
-
- my $search_index = $formats->{$format};
-
- # Determine which content to grab in the request
-
- # Determine correct locale
- my $tld = get_amazon_tld();
-
- # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2'
- my $aws_access_key_id = C4::Context->preference('AWSAccessKeyID');
-
- #grab the associates tag: mine is 'kadabox-20'
- my $af_tag=C4::Context->preference('AmazonAssocTag');
- my $response_group = join( ',', @aws );
- my $url = "http://ecs.amazonaws$tld/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=$aws_access_key_id&Operation=ItemLookup&AssociateTag=$af_tag&Version=2007-01-15&ItemId=$item_id&IdType=$id_type&ResponseGroup=$response_group";
- if ($id_type ne 'ASIN') {
- $url .= "&SearchIndex=$search_index";
- }
+ my %hformat = ( a => 'Books', g => 'Video', j => 'Music' );
+ my $search_index = $hformat{ substr($record->leader(),6,1) } || 'Books';
+
+ my $url =
+ "http://ecs.amazonaws" . get_amazon_tld() .
+ "/onca/xml?Service=AWSECommerceService" .
+ "&AWSAccessKeyId=" . C4::Context->preference('AWSAccessKeyID') .
+ "&Operation=ItemLookup" .
+ "&AssociateTag=" . C4::Context->preference('AmazonAssocTag') .
+ "&Version=2009-02-01" .
+ "&ItemId=$item_id" .
+ "&IdType=$id_type" .
+ "&ResponseGroup=" . join( ',', @aws );
+ $url .= "&SearchIndex=$search_index" if $id_type ne 'ASIN';
#warn $url;
my $content = get($url);
warn "could not retrieve $url" unless $content;
diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index aaf07c7..863a084 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -223,10 +223,21 @@ if (C4::Context->preference("FRBRizeEditions")==1) {
if ($@) { warn "XISBN Failed $@"; }
}
if ( C4::Context->preference("AmazonEnabled") == 1 ) {
+ $template->param( AmazonTld => get_amazon_tld() );
+ my $amazon_reviews = C4::Context->preference("AmazonReviews");
+ my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
+ my @services;
+ if ( $amazon_reviews ) {
+ $template->param( AmazonReviews => 1 );
+ push( @services, 'EditorialReview' );
+ }
+ if ( $amazon_similars ) {
+ $template->param( AmazonSimilarItems => 1 );
+ push( @services, 'Similarities' );
+ }
my $similar_products_exist;
- my @aws = qw( Similarities EditorialReview Reviews );
- my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@aws );
- my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
+ my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
+ #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
my @similar_products;
for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
# do we have any of these isbns in our collection?
@@ -238,10 +249,10 @@ if ( C4::Context->preference("AmazonEnabled") == 1 ) {
}
}
my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
- my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
+ #my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
$template->param( AmazonSimilarItems => $similar_products_exist );
- $template->param( amazon_average_rating => $average_rating * 20 );
- $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
+ #$template->param( amazon_average_rating => $average_rating * 20 );
+ #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
$template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
$template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
index f3ae4b9..554f7fd 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
@@ -97,9 +97,9 @@ function verify_images() {
<!-- /TMPL_IF -->
</ul>
</div>
-
+
<!-- TMPL_IF NAME="AmazonEnabled" --><!-- TMPL_IF NAME="AmazonCoverImages" --><div class="yui-u" id="bookcoverimg">
- <a href="http://www.amazon.com/gp/reader/<!-- TMPL_VAR NAME="normalized_isbn" -->/ref=sib_dp_pt/002-7879865-0184864#reader-link"><img border="0" src="http://images.amazon.com/images/P/<!-- TMPL_VAR NAME="normalized_isbn" -->.01._PIdp-schmooS,TopRight,7,-26_SCMZZZZZZZ_.jpg" alt="" /></a></div><!-- /TMPL_IF --><!-- /TMPL_IF -->
+<a href="http://www.amazon<!-- TMPL_VAR NAME="AmazonTld" -->/gp/reader/<!-- TMPL_VAR NAME="normalized_isbn" -->/ref=sib_dp_pt/002-7879865-0184864#reader-link"><img border="0" src="http://images.amazon.com/images/P/<!-- TMPL_VAR NAME="normalized_isbn" -->.01.MZZZZZZZ.jpg" alt="" /></a></div><!-- /TMPL_IF --><!-- /TMPL_IF -->
<div class="yui-u" style="margin-top: 1em;">
<ul>
--
1.5.6.5
More information about the Koha-patches
mailing list