Skip to main content

Drupal Amazon_Store Module - Default Sorting by Relevance (instead of best selling)

Posted in

As I was working on Video Game Music, I ran into a problem with the Amazon Store module.

It default sorts by best selling when you search. Good in most cases, but in a small niche like video game music I was getting popular stuff showing up that was completely unrelated. I thought perhaps I was missing an easy setting (I may still be). Nothing in the admin lets me change a default sort for search.

So, the hack that fixed it for me:

Line 533 of amazon_store.module:

  // Grab the URL args that we'll allow and put them in as parameters for Amazon search
extract($_GET,EXTR_PREFIX_ALL,"get");
  if (!empty($get_SearchIndex)) { $parameters['SearchIndex']=check_plain($get_SearchIndex); }
  if (!empty($get_Keywords)) { $parameters['Keywords'] = ereg_replace('[\'\"]','',$get_Keywords); }
  if (!empty($get_ItemId)) { $parameters['ItemId'] = filter_xss($get_ItemId); }
  if (!empty($get_BrowseNode)) {$parameters['BrowseNode'] = intval($get_BrowseNode); }
  if (!empty($get_MinimumPrice)) {$parameters['MinimumPrice'] = intval($get_MinimumPrice); }
  if (!empty($get_MaximumPrice)) {$parameters['MaximumPrice'] = intval($get_MaximumPrice); }
  if (!empty($get_MerchantId)) {$parameters['MerchantId'] = check_plain($get_MerchantId); }
  if (!empty($get_Brand)) {$parameters['Brand'] = filter_xss($get_Brand); }
  if (!empty($get_Sort)) {$parameters['Sort'] = check_plain($get_Sort); }
  //hacks default sort mechanism if left empty, change relevancerank to whatever parameter you want to sort by
  if (empty($get_Sort)) {$parameters['Sort'] = "relevancerank"; }
  //endhack
  if (!empty($get_page)) {
    // Drupal pager is 0-based. Amazon is 1-based. Adjust for that.
    $parameters['ItemPage'] = intval($get_page) +1;
  } else {
    $get_page = 1;
  }