From a063c111702ce015567aaa2b6584e9cbfca493b2 Mon Sep 17 00:00:00 2001 From: kados Date: Sat, 4 Feb 2006 01:56:42 +0000 Subject: [PATCH] Adds Fully Preferences-based Amazon.com feature. See mail to koha-devel for details. --- C4/Amazon.pm | 2 +- opac/opac-detail.pl | 36 +++++++++++++++++++++++++++++++++--- opac/opac-search.pl | 1 + 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/C4/Amazon.pm b/C4/Amazon.pm index 0fab1f7570..86e5767798 100755 --- a/C4/Amazon.pm +++ b/C4/Amazon.pm @@ -50,7 +50,7 @@ sub get_amazon_details { my ( $isbn ) = @_; #get rid of MARC cataloger's nonsense - $isbn ~= /(p|-)//g; + $isbn =~ s/(p|-)//g; # grab the developer's key: mine is 'ektostoukadou-20' my $dev_key=C4::Context->preference('AmazonDevKey'); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index dccb8bebb6..6372762867 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -9,6 +9,7 @@ use C4::Interface::CGI::Output; use HTML::Template; use C4::Biblio; use C4::SearchMarc; +use C4::Amazon; my $query=new CGI; my ($template, $borrowernumber, $cookie) @@ -63,7 +64,6 @@ my $marc = C4::Context->preference("marc"); #preformat isbn for amazon content $dat->{'isbn'} =~ s|-||g; - my @results = ($dat,); if (C4::Boolean::true_p($marc)) { my $dbh = C4::Context->dbh; @@ -87,11 +87,41 @@ $template->param(BIBLIO_RESULTS => $resultsarray, SITE_RESULTS => $sitearray, subscriptions => \@subs, subscriptionsnumber => $subscriptionsnumber, - LibraryName => C4::Context->preference("LibraryName"), + LibraryName => C4::Context->preference("LibraryName"), suggestion => C4::Context->preference("suggestion"), virtualshelves => C4::Context->preference("virtualshelves"), OpacNav => C4::Context->preference("OpacNav"), + AmazonContent => C4::Context->preference("AmazonContent"), ); -output_html_with_http_headers $query, $cookie, $template->output; +## Amazon.com stuff +if (C4::Context->preference("AmazonContent")==1) { + my $isbn=$dat->{'isbn'}; + my $amazon_details = &get_amazon_details($isbn); + + foreach my $result (@{$amazon_details->{Details}}){ + $template->param(item_description => $result->{ProductDescription}); + $template->param(image => $result->{ImageUrlMedium}); + $template->param(list_price => $result->{ListPrice}); + $template->param(amazon_url => $result->{url}); + } + my @products; + my @reviews; + for my $details( @{ $amazon_details->{ Details } } ) { + next unless $details->{ SimilarProducts }; + for my $product ( @{ $details->{ SimilarProducts }->{ Product } } ) { + push @products, +{ Product => $product }; + } + next unless $details->{ Reviews }; + for my $product ( @{ $details->{ Reviews }->{ AvgCustomerRating } } ) { + $template->param(rating => $product * 20); + } + for my $reviews ( @{ $details->{ Reviews }->{ CustomerReview } } ) { + push @reviews, +{ Summary => $reviews->{ Summary }, Comment => $reviews->{ Comment }, }; + } + } + $template->param( SIMILAR_PRODUCTS => \@products ); + $template->param( REVIEWS => \@reviews ); +} +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 954b067e0f..7da67cdb4e 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -214,6 +214,7 @@ if ($op eq "do_search") { virtualshelves => C4::Context->preference("virtualshelves"), LibraryName => C4::Context->preference("LibraryName"), OpacNav => C4::Context->preference("OpacNav"), + AmazonContent => C4::Context->preference("AmazonContent"), ); } -- 2.39.5