From 3cfa84362f3d363756f9ca87e781a11013ff60af Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 26 May 2009 14:20:03 -0500 Subject: [PATCH] bug 3219: handle variation in Amazon responses An Amazon ItemLookup response can sometimes have more than one Item element, where the ones after the first appear to be cross references to items that have the same ISBN. Changed parsing so that those responses are no longer treated like pseudohashes. This fixes the following crash: [error] detail.pl: Pseudo-hashes are deprecated at /catalogue/detail.pl line 213., referer: /cgi-bin/koha/catalogue/detail.pl Which may lead to a nasty: [error] Out of memory!, referer: /cgi-bin/koha/catalogue/detail.pl Signed-off-by: Galen Charlton --- C4/External/Amazon.pm | 2 +- catalogue/detail.pl | 8 ++++---- opac/opac-detail.pl | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/C4/External/Amazon.pm b/C4/External/Amazon.pm index f89200af2e..47f4b5ee83 100644 --- a/C4/External/Amazon.pm +++ b/C4/External/Amazon.pm @@ -146,7 +146,7 @@ sub get_amazon_details { my $xmlsimple = XML::Simple->new(); my $response = $xmlsimple->XMLin( $content, - forcearray => [ qw(SimilarProduct EditorialReview Review) ], + forcearray => [ qw(SimilarProduct EditorialReview Review Item) ], ) unless !$content; return $response; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 1f5a291c82..649c46f6d8 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -239,7 +239,7 @@ if ( C4::Context->preference("AmazonEnabled") == 1 ) { if ( $amazon_similars ) { my $similar_products_exist; my @similar_products; - for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) { + for my $similar_product (@{$amazon_details->{Items}->{Item}->[0]->{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 @@ -252,10 +252,10 @@ if ( C4::Context->preference("AmazonEnabled") == 1 ) { $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products ); } if ( $amazon_reviews ) { - my $item = $amazon_details->{Items}->{Item}; + my $item = $amazon_details->{Items}->{Item}->[0]; 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; + #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}}; + #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{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 ); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 18b00cba61..a29fdb22c4 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -285,7 +285,7 @@ if ( C4::Context->preference("OPACAmazonEnabled") ) { my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services ); my $similar_products_exist; if ( $amazon_reviews ) { - my $item = $amazon_details->{Items}->{Item}; + my $item = $amazon_details->{Items}->{Item}->[0]; my $customer_reviews = \@{ $item->{CustomerReviews}->{Review} }; for my $one_review ( @$customer_reviews ) { $one_review->{Date} = format_date($one_review->{Date}); @@ -297,7 +297,7 @@ if ( C4::Context->preference("OPACAmazonEnabled") ) { $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews ); } if ( $amazon_similars ) { - my $item = $amazon_details->{Items}->{Item}; + my $item = $amazon_details->{Items}->{Item}->[0]; my @similar_products; for my $similar_product (@{ $item->{SimilarProducts}->{SimilarProduct} }) { # do we have any of these isbns in our collection? -- 2.20.1