From 33fffbcfd6b292a578fe6a82fd68dd7128a70e37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Mon, 27 Apr 2009 07:49:57 +0200 Subject: [PATCH] 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 --- C4/External/Amazon.pm | 66 ++++++------------- catalogue/detail.pl | 54 +++++++++------ .../prog/en/modules/catalogue/detail.tmpl | 4 +- 3 files changed, 58 insertions(+), 66 deletions(-) diff --git a/C4/External/Amazon.pm b/C4/External/Amazon.pm index 78cdadf812..f89200af2e 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 aaf07c7b0e..1f5a291c82 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -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; 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 f3ae4b9e4b..554f7fd805 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() { - + +/gp/reader//ref=sib_dp_pt/002-7879865-0184864#reader-link">.01.MZZZZZZZ.jpg" alt="" />
    -- 2.39.5