Multiple Associate Countries

cscc_leth - June 13, 2006 - 19:55
Project:Amazon associate tools
Version:5.x-1.5
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed
Description

It would be wonderful to have the option to select multiple countries with different associate ID's for use in this module. Using myself as an example, I have an associate ID from amazon.ca (since I'm from Canada) and also one from amazon.com (since most of my traffic comes from the US), and I would like users to be able to use their own store. Something like having a main store and then having country codes which link to the appropriate Amazon store (with the related associate ID embedded) would be useful to me.

My PHP and MySQL isn't very strong, otherwise I'd try to add this functionality myself. But if it would be useful to others (and I think it would), then I'd appreciate if you'd consider trying to add this functionality! Thanks.

#1

Prometheus6 - June 14, 2006 - 01:09

That's not something I would do for free. Not even Amazon.com runs their stores from a single database or software installation.

#2

llyra - July 20, 2006 - 17:50

I also have multiple Amazon associate accounts due to different countries (one account with US and one with UK). Just letting you know that there may be a need for this type of option for this mod.

#3

mariuss - August 10, 2006 - 01:06

Same here, adding multiple Amazon Associate IDs would be great. Each book can then be listed several times (the image/title/author probably only once), once for each country there is an associate ID.

Also, users could select which country they prefer and then only links for that country will show, or the other links are collapsed.

#4

bohemicus - September 7, 2006 - 21:58

just would like to add my vote in support of these suggestions - you say it's not something you'd do for free - maybe a bunch of us users could chip in on this feature - if you have established development rates

#5

bohemicus - January 16, 2007 - 20:37

I solved this problem at the theme level thanks to the fact that Amazon uses a unified ASIN-based link structure over their sites. I got the nodes from the US site simply because it typically has the best editorial reviews and then used Contemplate (just for ease of modification) to create links to all Amazon countries (even those where I don't have associate accounts. So far, even the more obscure publications were found on all of them. Here's the theme code for the links:

| <a href="http://www.amazon.com/gp/product/<?php print $node->asin ?>?ie=UTF8&tag=bohemicacom">Amazon.com</a> |
<a href="http://www.amazon.co.uk/gp/product/<?php print $node->asin ?>?ie=UTF8&tag=bohemicacom0d">Amazon.co.uk</a> |
<a href="http://www.amazon.ca/gp/product/<?php print $node->asin ?>?ie=UTF8&tag=bohemicacom00-20">Amazon.ca</a> |

I enclose my complete theme file if anyone's interested that themes the whole Amazon Node.

AttachmentSize
amazon-node-contemplate-file.txt 2.13 KB

#6

bohemicus - January 16, 2007 - 20:39

BTW: You can see the files above at work for example at http://www.conceptualmetaphor.net/metaphorbookstore.

#7

solipsist - February 5, 2007 - 12:13

Nice work bohemicus, and a nice site too! Always cool to see cog sci sites! I think I'll do that same for my own fantasy author focused site!

#8

csc4 - February 25, 2007 - 14:18

I put the amazon-node-contemplate-file.txt code into the contemplate node template but it doesn't seem to be picking up the variables - is there something else I need to do?

#9

cpelham - April 13, 2007 - 00:33
Version:4.7.x-1.x-dev» 5.x-1.5

That's super...but what if a book is available only on one of the foreign amazon stores and not on amazon.com? At present, if I try to make a new node for a foreign-language edition, for example, whose ASIN is listed on amazon.co.jp but not on amazon.com, then drupal will not make the node.

I am trying to make a node for ASIN 4309230784 for the Japanese-language edition of Disappearance of the Universe (in case anyone else wants to give it a try), and I get the error:

No product: %asin exists at Amazon.com

Is there away around this? Perhaps I can just modify the lookup code, wherever it is, to try another store if it does not find the asin in the amazon.com store. I'm not sure where in the module that code is, but I'll take a look...has anyone else already done this?

#10

Riccardo83 - December 11, 2007 - 10:42

sorry, dumm question. where can i change that node template ?
amazon-node-contemplate-file.txt ????

#11

bohemicus - December 11, 2007 - 23:24

You need to install the contemplate module and then follow the instructions. You could also create a .tpl.php file with that code.

re 9: I noticed that it always picks up the ASIN from the .com bookstore in the non.com stores. No idea what happens the other way around. It may be beyond the capabilities of this simple workaround.

#12

Riccardo83 - December 12, 2007 - 04:20

thank you so much. did anyone figure out how to add those patches since the module was updated and the patches dont work?
http://drupal.org/node/151637

Or could anyone help me?

#13

BradM - February 6, 2008 - 05:31

Seeing as this module isn't being updated, I have on occasion hacked the source code rather than fiddle with themes or other areas ... a cardinal sin, to be sure, but what the heck. ;)

Anyway, I've implemented a similar thing as outlined by bohemicus, except my version requires modification of the amazon.module file, so only do this if you feel comfortable in doing it... and only if you've made a backup! This version will display flags underneath the price listing when viewing an amazon node (US-based associate). These additional product links are for amazon.co.uk and amazon.ca -- see the attached screen shot for details.

Around line 1488 in amazon.module, you should see something like this:

if ($node->formattedprice) {
    $output .= "amazon price: $node->formattedprice $node->currencycode<br /><br clear=\"all\" />";
  }

Replace that code above with the following:
if ($node->formattedprice) {
    $output .= "amazon price: $node->formattedprice $node->currencycode<br />";
  }
  // provide links to products in other countries
  if ($node->asin) {
  $output .= "<br />other availability:<br />";
  // get rid of useless search terms
$skip = array(" the ", " an ", " a ", " of ", " in ", " and ", "The ", "An ", " A ", "Of ", "In", "And");
$trimmed = str_replace($skip, " ", $node->product_title);
// clean up whitespace
$trimmed = trim($trimmed);
$trimmed = ereg_replace(' +', ' ', $trimmed);
  // remove odd characters from title but keep spaces
  $trimmed = ereg_replace("[^A-Za-z0-9\s\']", " ", $trimmed); 
  // take only first x-number words if it's a long title
  $limit = 3; // set this to the number of terms you want
  $searchterms = implode(" ", array_slice(preg_split("/\s+/", $trimmed), 0, $limit));
  // get surname of first author listed
if ($node->author) {
$names = explode(' ', $node->author[0]);
$surname = end($names);
}
// add format to search terms if DVD, VHS or CD to help narrow results
if (($node->binding == 'DVD') || ($node->binding == 'VHS Movie') || ($node->binding == 'Audio CD')) {
$binding = $node->binding;
// amazon.co.uk and amazon.ca tend to put numbers in the title for DVDs of TV shows (seasons)
// rather than words (1 vs. One) -- so filter words into numbers
$numwords = array('One','Two','Three','Four','Five','Six','Seven','Eight');
$numnums = array('1','2','3','4','5','6','7','8');
$searchterms = str_replace($numwords,$numnums,$searchterms);
}
  // uncomment the line for each country based on desired SEARCH or PRODUCT link (default is search)
  // amazon.co.uk //
  $output .= "<a href=\"http://www.amazon.co.uk/gp/search?ie=UTF8&keywords=" . drupal_urlencode($searchterms) . " " . $surname . " " . $binding . "&tag=YOUR_UK_ID&index=blended&linkCode=ur2&camp=1634&creative=6738\"><img src=\"$module_dir/images/uk.gif\" alt=\"search for this " . $node->binding . " at Amazon.co.uk\" /></a>&nbsp;";
        //$output .= "<a href=\"http://www.amazon.co.uk/gp/product/" . $node->asin . "?ie=UTF8&tag=YOUR_UK_ID&linkCode=as2&camp=1634&creative=6738&creativeASIN=" . $node->asin . "\"><img src=\"$module_dir/images/uk.gif\" alt=\"search for this " . $node->binding . " at Amazon.co.uk\" title=\"search for this " . $node->binding . " at Amazon.co.uk\" /></a>&nbsp;";
        // amazon.ca //
        $output .= "<a href=\"http://www.amazon.ca/gp/search?ie=UTF8&keywords=" . drupal_urlencode($searchterms) . " " . $surname . " " . $binding . "&tag=YOUR_CA_ID&index=blended&linkCode=ur2&camp=1634&creative=6738\"><img src=\"$module_dir/images/canada.gif\" alt=\"search for this " . $node->binding . " at Amazon.ca\" title=\"search for this " . $node->binding . " at Amazon.ca\" /></a>&nbsp;";
        //$output .= "<a href=\"http://www.amazon.ca/gp/product/" . $node->asin . "?ie=UTF8&tag=YOUR_CA_ID&linkCode=as2&camp=1634&creative=6738&creativeASIN=" . $node->asin . "\"><img src=\"$module_dir/images/canada.gif\" alt=\"search for this " . $node->binding . " at Amazon.ca\" title=\"search for this " . $node->binding . " at Amazon.ca\" /></a>&nbsp;";
        $output .= "<br clear=left />";
  }

Things you need to know:

  • Replace YOUR_UK_ID in the links with your amazon.co.uk associates ID.
  • Replace YOUR_CA_ID in the links with your amazon.ca associates ID.
  • By default, each link will search the site in question using keywords based on the title of the product, the author's surname (if applicable) and the binding (for DVDs, VHS Movies and Audio CDs only). I found this to be the most effective in my tests. There is still the option to attempt to link to the exact product at the other sites using the ASIN, you just need to comment out the default, and enable the other one by removing the two forward slashes at the start of the line.
  • The keyword search filters out "useless" words from the title (the, a, an, of, in, and) and then only uses the first 3 remaining "good" words; it then tacks on the surname of the first author listed, in order to narrow the search results. For example, the book "Horror Readers' Advisory: The Librarian's Guide to Vampires, Killer Tomatoes, and Haunted Houses (Ala Readers' Advisory Series)" by Becky Siegel Spratford would return the following search terms: Horror Readers' Advisory Spratford. You have the option of changing the number of title words to use; just change the $limit value.
  • you'll need to place a graphic in your /modules/amazontools/images directory called "uk.gif"
  • you'll need to place a graphic in your /modules/amazontools/images directory called "canada.gif"

Well I hope this all makes sense; I'm no expert coder but I might be able to answer your questions.

Brad

AttachmentSize
multiple_amazon_associates.jpg 13.52 KB

#14

wayland76 - February 14, 2008 - 02:13

If the issue http://drupal.org/node/221525 ever gets implemented, it might be possible to use this code without hardcoding the associate ID in the code.

#15

wayland76 - February 14, 2008 - 02:14
Status:active» postponed

#16

joel_guesclin - January 22, 2009 - 20:52

I'm trying to do something like this using ASIN CCK fields. I posted an issue for the ASIN module on this very topic - and was wondering if it were possible to integrate this patch with the ASIN module, and if so how? Any help would be very welcome.

 
 

Drupal is a registered trademark of Dries Buytaert.