Bug 2920 Fixes Amazon content use in pro interface
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 Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
parent
199ec1473a
commit
33fffbcfd6
|
|
@ -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 %hformat = ( a => 'Books', g => 'Video', j => 'Music' );
|
||||
my $search_index = $hformat{ substr($record->leader(),6,1) } || 'Books';
|
||||
|
||||
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 $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;
|
||||
|
|
|
|||
|
|
@ -223,26 +223,42 @@ if (C4::Context->preference("FRBRizeEditions")==1) {
|
|||
if ($@) { warn "XISBN Failed $@"; }
|
||||
}
|
||||
if ( C4::Context->preference("AmazonEnabled") == 1 ) {
|
||||
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 @similar_products;
|
||||
for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
|
||||
# do we have any of these isbns in our collection?
|
||||
my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
|
||||
# verify that there is at least one similar item
|
||||
if (scalar(@$similar_biblionumbers)){
|
||||
$similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
|
||||
push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
|
||||
}
|
||||
$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 $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
|
||||
if ( $amazon_similars ) {
|
||||
my $similar_products_exist;
|
||||
my @similar_products;
|
||||
for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
|
||||
# do we have any of these isbns in our collection?
|
||||
my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
|
||||
# verify that there is at least one similar item
|
||||
if (scalar(@$similar_biblionumbers)){
|
||||
$similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
|
||||
push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
|
||||
}
|
||||
}
|
||||
$template->param( AmazonSimilarItems => $similar_products_exist );
|
||||
$template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
|
||||
}
|
||||
if ( $amazon_reviews ) {
|
||||
my $item = $amazon_details->{Items}->{Item};
|
||||
my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
|
||||
#my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
|
||||
#my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
|
||||
#$template->param( amazon_average_rating => $average_rating * 20 );
|
||||
#$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
|
||||
$template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
|
||||
}
|
||||
my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
|
||||
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_SIMILAR_PRODUCTS => \@similar_products );
|
||||
$template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
|
||||
}
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue