First of all, a big thanks for this module. It was a key ingredient in helping me try to convert an existing site to Drupal.

I'm still a rank beginner, but I was hoping you might point me in the right direction. I've got about 500 CCK nodes, each with between 3 and 7 related ASINS. Everything works great, and the related books appear at the top of the page in an unthemed output.

I would like to theme a related books block in the right sidebar. Is the "correct" way to do this:

1. Figure out how to extract and theme the fields from the Amazon Object from within my page Content -(if thats the correct terminology)
2. Use views to create a view of all the books, and them filter them down by writing a query within the args field of the view that would include only those ASINs that match the current NID in the amazonnode table.
3. Consider Amazon Filter or some other approach.

Sorry if this is basic stuff, but I'd like to learn the right way to do this so I don't have to do it again.
Thanks if you can help!

Comments

Prometheus6’s picture

Warning: I have not used CCK at all. the asin field is Jeff Eaton's work.

That said, I got an email from the Drupal Developer list that may help you.

To find the right table for a field for a SQL query, use the API, like this:

$db_info = content_database_info($field);
$table = $db_info['table'];

That will always return the right table for the requested field. 

$field needs to be the complete field array, not just the field name, so if you only have the field name, you would do:

$field = content_fields(my_field_name);
$db_info = content_database_info($field);
$table = $db_info['table'];

content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like:

Array (
    [table] => content_type_story
    [columns] => Array (
            [value] => Array  (
                    [type] => varchar
                    [length] => 50
                    [not null] => 1
                    [default] => ''
                    [sortable] => 1
                    [column] => field_phone_value
                )
            [value2] => Array (
                    [type] => int
                    [length] => 10
                    [unsigned] => 1
                    [not null] => 1
                    [default] => 0
                    [column] => field_phone_type
                )
        )
)

Once you get the ASINs you can use _amazon_product_db_data_by_ASIN() to get the actual data on each book. The function will accept a comma delimited string of ASINS or an array of ASINS.

herb’s picture

Thank you for the response.. It will certainly give me a bit to digest. However, I may have confused the question as I'm not using the asin field, and I don't think that CCK use is an issue here.

Maybe more directly... If I have a normal page, into which I've added 3 comma delimited "Related product(s)" asins, is there a simple way to get just these 3 related books output into a block? With or without Views?

Thanks again

Prometheus6’s picture

Oh, sorry. The fact that they are CCK nodes threw me.

$node->amazonnode_data

The bit about using _amazon_product_db_data_by_ASIN() still applies.

Prometheus6’s picture

Assigned: Unassigned » Prometheus6
Status: Active » Fixed
herb’s picture

OK - Thanks much. I think I've gotten something to work that presents the related book links in a block. I'm strictly an amateur, and 2 months ago could hardly spell PHP, but in case anyone else could use this, or there are any gross deficiencies this is what I used. (It's mostly derived from the amazon.module)

<?php 
   if (arg(0) == 'node' && is_numeric(arg(1))){
	  $nid = arg(1); 
          $ASINQuery = db_query("SELECT asin FROM {amazonnode} WHERE nid = %d", $nid); 
          while ($ASINRec = db_fetch_object($ASINQuery)) {
              $ASINList[] = $ASINRec->asin;
          }
     $amazondata = _amazon_product_db_data_by_ASIN($ASINList);
   }	
   if ($amazondata) {
            foreach($amazondata as $amazon_data) {
            $related_links .= theme('amazon_related_link', $amazon_data);
        }
          print $related_links;
   }
?>

PS - The links upon hovering show my Amazon ID, but when clicked the link visible on Amazon no longer shows my Amazon ID, and does show a SubscriptionId=1XFK01HK9NZWGPEN????. Is this the expected behavior? Thanks again!

Anonymous’s picture

Status: Fixed » Closed (fixed)