From 393711396a5e529822883acb22aaf20b72cb6825 Mon Sep 17 00:00:00 2001
From: the_g_bomb <gareth_alexander@hotmail.com>
Date: Tue, 28 Feb 2017 12:09:44 +0000
Subject: [PATCH] Issue #[2856588] by the_g_bomb: Removing Variations response
 group from outside US.

---
 amazon_store.module |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/amazon_store.module b/amazon_store.module
index a057ca9..ec37cce 100644
--- a/amazon_store.module
+++ b/amazon_store.module
@@ -20,7 +20,7 @@ module_load_include('inc', 'amazon_store', 'amazon_store.pages');
  * Implements hook_init().
  */
 function amazon_store_init() {
-  $locale = variable_get('amazon_locale', 'US');
+  $locale = variable_get('amazon_default_locale', 'US');
   //TODO: We probably don't need to load this in hook_init. Figure out where to do it
   $GLOBALS['amazon_store_search_indexes'] = new SearchIndexes($locale);
 }
@@ -320,7 +320,7 @@ function template_preprocess_amazon_store_all(&$variables) {
 function amazon_store_cache_item($xml) {
 
   $cache_timeout = variable_get('amazon_store_refresh_schedule', 43200);
-  $locale = variable_get('amazon_locale', 'US');
+  $locale = variable_get('amazon_default_locale', 'US');
 
   // If you cache the object itself it can't be deserialized. http://drupal.org/node/199337
   // So we cache the XML instead
@@ -339,7 +339,7 @@ function amazon_store_cache_item($xml) {
  * 	Item as SimpleXML object
  */
 function amazon_store_retrieve_item($asin) {
-  $locale = variable_get('amazon_locale', 'US');
+  $locale = variable_get('amazon_default_locale', 'US');
 
   $item = cache_get("ASIN-{$asin}-{$locale}", 'cache_amazon_store');
   if ($item && $item->data) {
@@ -362,7 +362,7 @@ function amazon_store_retrieve_item($asin) {
  */
 function amazon_store_cache_search($parameters, $results) {
   $cache_timeout = variable_get('amazon_store_refresh_schedule', 43200);
-  $locale = variable_get('amazon_locale', 'US');
+  $locale = variable_get('amazon_default_locale', 'US');
 
   ksort($parameters);
   $key = "Search-$locale-" . implode('/', array_keys($parameters)) . implode('/', $parameters);
@@ -377,7 +377,7 @@ function amazon_store_cache_search($parameters, $results) {
  * 	SimpleXML object or NULL if not found in cache
  */
 function amazon_store_retrieve_cached_search($parameters) {
-  $locale = variable_get('amazon_locale', 'US');
+  $locale = variable_get('amazon_default_locale', 'US');
 
   $xml = NULL;
   ksort($parameters);
@@ -730,7 +730,7 @@ function amazon_store_http_request($op, $parameters) {
  * 	SimpleXML result with search results
  */
 function _amazon_store_search($parameters = array()) {
-  $locale = variable_get('amazon_locale', 'US');
+  $locale = variable_get('amazon_default_locale', 'US');
   $response_groups = "Variations,Images,ItemAttributes,OfferFull";
   if ($parameters['SearchIndex'] != 'Apparel') {
     $response_groups .= ',EditorialReview,Similarities,AlternateVersions,Large';
@@ -766,7 +766,12 @@ function _amazon_store_search($parameters = array()) {
  * @return unknown_type
  */
 function _amazon_store_itemlist($parameters = array()) {
-  $parameters['ResponseGroup'] = 'Variations,ItemAttributes,Images,EditorialReview,OfferFull,Reviews,Similarities,AlternateVersions,Large';
+  $locale = variable_get('amazon_default_locale', 'US');
+  $response_groups = 'ItemAttributes,Images,EditorialReview,OfferFull,Reviews,Similarities,AlternateVersions,Large';
+  if ($locale == 'US') { // Variations not currently supported outside US
+    $response_groups .= ',Variations';
+  }
+  $parameters['ResponseGroup'] = $response_groups;
 
   if (! ($results = amazon_store_retrieve_cached_search($parameters))) {
     $results = amazon_store_http_request('ItemLookup', $parameters);
-- 
1.7.9.msysgit.0

