bug 3219: handle variation in Amazon responses
authorGalen Charlton <galen.charlton@liblime.com>
Tue, 26 May 2009 19:20:03 +0000 (14:20 -0500)
committerGalen Charlton <galen.charlton@liblime.com>
Wed, 27 May 2009 12:06:20 +0000 (07:06 -0500)
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 <galen.charlton@liblime.com>
C4/External/Amazon.pm
catalogue/detail.pl
opac/opac-detail.pl

index f89200a..47f4b5e 100644 (file)
@@ -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;
 }
index 1f5a291..649c46f 100755 (executable)
@@ -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      );
index 18b00cb..a29fdb2 100755 (executable)
@@ -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?