Is there a way to add a new display format, without editing the module itself? What I want is to have the choice of the output only show as a text link to Amazon. Just like the show title as a link one does now, but have it just say "Purchase at Amazon" or something like that. I would rather find a way to do this, if it can be done, by only changing theme folder files, and not the module's.

CommentFileSizeAuthor
#5 lotr.txt1.83 KBAnonymous (not verified)

Comments

wxman’s picture

Status: Fixed » Active

I think I figured it out. I added this to my template.php file in my theme called tlt:

function tlt_amazon_inline_item($item) {
  $alt_theme = 'amazon_inline_item_' . _amazon_clean_type($item['producttypename']);
  if ($output = theme($alt_theme, $item)) {
    return $output;
  }
  else {
    $output = '<span class="'. _amazon_item_classes($item) .' amazon-item-inline">';
    $output .= l('See this item at Amazon', $item['detailpageurl']);
    //$output .= l($item['title'], $item['detailpageurl']);
    $output .= '</span>';
    return $output;
  }
}

Now instead of the book title, the link just shows 'See this item at Amazon'. Of course now I can't use the title text link option. Ideally I would like to add it as another option for the fields display.

Anonymous’s picture

Status: Active » Fixed

Well, just to add another way for people who want to use this (poorly documented but otherwise very nice) module:

Add a CCK-Field "asin" (don't bother using the Amazon-module field, at least in my case its not working 9/10 times, and yes, I will write a bug report). You can get all the information you want by calling:

amazon_item_lookup(_amazon_clean_type($node->asin[0]));

in your node-whatever.tpl.php. (assuming only one is is submitted and the field is named asin). It will return you a very nice array of stuff you always wanted to know ;)

wxman’s picture

Thanks. I'll try that too.

drurian’s picture

Status: Active » Fixed

tirsales's method didn't work for me.

Anonymous’s picture

Status: Fixed » Active
StatusFileSize
new1.83 KB

Well, perhaps I should go into more detail:

Content-Type and theme

I just added field 'field_asin' (type: text, textfield) to the content-type xyz. In my "node-xyz.tpl.php" I inserted the following code:

$asin    = _amazon_clean_type($node->field_asin[0]['safe']);
$_amazon = amazon_item_lookup($asin);
$amazon  = $_amazon[$asin];

Now $amazon contains either null (ASIN is invalid) or the corresponding Amazon-information, one example of a random book is attached.
I've printed the array using

print "<pre>" . print_r($amazon,true) . "</pre><br>";

Now to e.g. print the Title from Amazon:

print $amazon['title'];

etc:

Now, an example code to print the content of the node (in your node-xyz.tpl.php) with the cover-image and some basic-information:

$img     = $amazon['imagesets']['mediumimage'];
$height  = $img['height'];
$width   = $img['width'];
$imgh    = "<img id=\"cover\" style='float: right;' title=\"" . $amazon['title'] . " cover\" src=\"" . $img['url'] . "\" width=\"$width\" height=\"$height\">";
print l($imgh,"node/".$node->nid,array('html'=>true)); 
print "<h1>$title</h1>";
print $content;
print implode(',',$amazon['author']) . ": <b>".$amazon['title']."</b><br>";
print $amazon['publisher'] . "; " . t(date("F",$amazon['timestamp'])) . " " . date("Y",$amazon['timestamp'])  . "<br>";
print $amazon['numberofpages'] . " Seiten, " . $amazon['binding'] . ", " . $amazon['listpriceformattedprice'] . "<br>";
$imgurl = base_path() . path_to_theme() . "/logo_amazon_90.gif";
print l("Additional information - <img style=\"vertical-align: middle;\" src=\"$imgurl\" width=\"90\" height=\"45\" title=\"Amazon Logo\">",$amazon['detailpageurl'],array('html'=>true));

Validation

As my content-type is only worth something, if Amazon-Content could be collected, I've added a validator (using http://drupal.org/project/validation_api ) using a PHP-validator:

$asin    = _amazon_clean_type($value);
$_amazon = amazon_item_lookup($asin);
$amazon  = $_amazon[$asin];
if ( ! $amazon && $value != '---' ) { return false; }
return true;

but this is optional. The check fails if a) the ASIN is invalid (no Amazon-content could be retrieved) and b) the ASIN is not '---'. If the
check fails, "preview" or "save" on a node fails with an error-message.

Nodetitle

I'm using http://drupal.org/project/auto_nodetitle to set the node-title to something like "Author - Book", but this is optional too:

  $asin    = _amazon_clean_type($node->field_asin[0]['value']);
  $_amazon = amazon_item_lookup($asin);
  $amazon  = $_amazon[$asin];
  $autor = implode(',',$amazon['author']);
  if ( strlen($amazon) > 40 && count($amazon['author']) > 1 ) {
    $autor = $amazon['author'][0] . "...";
  }
  $ownTitle .= "$autor - ".$amazon['title'];
  print $ownTitle;

System

I'm using Drupal-6.10, Content 6.x-2.1, Amazon API 6.x-1.0-beta5 and Validation API 6.x-1.0 and Automatic Nodetitle 6.x-1.1

I do believe that there are better ways to display this information, but this approach works (for me) and allows me to adjust what information is visible. In fact it allows to integrate with Validation API etc to avoid potential misspellings or problems. I did not check whether this uses the caching mechanism of the Amazon API, but I believe so.

drurian’s picture

Thanks, tirsales, for spelling it out for the dummies :)
Did you think about adding it to the handbook? I think it will be very helpful indeed.

Anonymous’s picture

I didn't even know that the Amazon API has a handbook page/area?

wxman’s picture

I just wanted to add that tirsales method has worked great for me. I even customized the tpl file so the medium book cover shows, and if you click it, Lightbox2 kicks in showing the Amazon large cover.

drurian’s picture

I think I figured out how to change display of inline items using input format. It's in the filter.module, but not documented.
Obviously, if you use fields you can modify default template for specific field.

Anonymous’s picture

That's very nice for you drupal librarian - could you elaborate on your method?

drurian’s picture

Sure, that's what I do
* Note I'm talking about Amazon inline filter, not Amazon CCK fields.

Basically, amazon module uses one theme_amazon_item function and different variations of it.
In the case of filter.module it will theme the output depending on what the third word in the input string is.
If you use [amazon ASIN] or [amazon ASIN inline] it will use the default theme_amazon_inline_item function (note that in Amazon media module DVD, software and videogames have their own additional inline theme formatting, but not books). If the third word is 'details' or 'thumbnail' it will use amazon-item-details or amazon-item-thumbnail templates included in the module (again, amazon media module will use its own templates). If it can't match the third word, it will simply use amazon-item template.

Now, to implement custom input format theming, create amazon-item-example template in your theme directory and then you can use [amazon ASIN example] format in your nodes.

For example, if you want to print the large image, create amazon-item-largeimage.tp.php, add

<?php print $largeimage; ?> (or whatever you want)

Then [amazon ASIN largeimage] will call this template.

Don't forget to copy amazon-item to your theme directory, or it's going to use the module's templates instead.

rfay’s picture

Status: Active » Fixed

Excellent work in this thread.

The handbook page for Amazon Module now exists, and if you folks can help add to it, that would be much appreciated.
http://drupal.org/node/595464

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rfay’s picture

There are an enormous number of new filter options available to you as of tomorrow's dev release, soon to be a beta. See the docs at http://drupal.org/node/595464 and this issue: http://drupal.org/node/598588