I have a problem with my autocomplete result suggestions. I like to place a product image in the search result suggestion. Right now I have the following code:

function genesis_studion_finder_autocomplete_suggestion($option, $finder_element) {
return $option->{$option->field_product_afbeelding};
$node = node_load($option->nid);
$teaser = node_view($node, $teaser = TRUE);
return $teaser;
}

field_product_afbeelding is the name of the cck image field //

The above code I always get an HTTP 500 error. It seems that it does not find field_product_afbeelding.

Comments

danielb’s picture

You will need to debug the $node to find the data you're looking for

<?php
function genesis_studion_finder_autocomplete_suggestion($option, $finder_element) {
// Load the node.
$node = node_load($option->nid);

// Debug your $node object here to find the data of your cck field - these will show up on the next page load.
drupal_set_message("<pre>".htmlspecialchars(print_r($node,1))."</pre>");

// Return the HTML you find in there.
return $node->field_product_afbeelding[0]['view'];  // something like that
}
?>

Don't add the field to your finder element, btw, unless you want people to search for the path of the image

danielb’s picture

Status: Active » Fixed
frankspin’s picture

Status: Fixed » Active

Unfortunately it still does not work properly.

I've tried different things

1. Teaser with the following code:

function cube_finder_autocomplete_suggestion($option, $finder_element) {
// return $option->{$option->field_name};
$node = node_load($option->nid);
$teaser = node_view($node, $teaser = TRUE);
return $teaser;
}

* Yes, i use a different theme.

With this code I get only a blank node. This option respects not my .tpl structure. I have a product (node product.tpl.php) and an accompaning product teaser (node-product--teaser.tpl.php). Views2 respects this structure can and show the teasers properly.

I then tried to put in my node.tpl.php a reference to the right .tpl file. I did this with the following code:

<?php if($teaser || $node->type == 'product'): ?>
<?php include 'node-product--teaser.tpl.php'; return; ?>
<?php endif; ?>

This seems to work, the tpl file is loaded. Only there is a weird problem.

It looks like the contents of the tpl file is completely thrown away. Therefore I tried a static text at the top in my node-product--teaser.tpl.php file, insert between the h1 tags. (<h1> This is a test title </ h1>) To my surprise I get results now with the autocomplete finder.

When I search on the title of my node, in my case: Red Car. The autocomplete popup box shows the text "This is a test title" see. When I click on I get the result: Red Car.

I'm actually completely lost.

Edit.

This is the content of my node-product--teaser.tpl.php file.

<h1><?php print $title; ?> test</h1>

If I import a search term into the AutoComplete box finder I only get to see the word test. If I click on the word test, I will be referred to the correct result.

frankspin’s picture

More information

I now have the following code in my tpl file.

<h1><?php print $title; ?> test</h1>
<?php print drupal_set_message("<pre>".htmlspecialchars(print_r($node,1))."</pre>"); ?> -
<?php print $field_test[0]['view']; ?>

If I am using the finder (url: finder/3/Red car )

I get this result:

Red car test
Array - A nice red car with big weels

But through the auto complete box I get this result:

test
Array - 
frankspin’s picture

Is there someone who want to install this feature for a small fee?

danielb’s picture

Status: Active » Fixed

Sorry mate, I've given all the help I can. It should be possible to do if you understand the data in the node object. You might find more help from the community with theming.

Status: Fixed » Closed (fixed)

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

kaido.toomingas’s picture

Thats how I did :)
Put this code to your template.php file and replace MyTemplateName with YourTemplateName and field_MyImage with your cck field name. This code will als include node title after this image. And links the whole stuff the this node.

function MyTemplateName_finder_autocomplete_suggestion($option, $finder_element) {
// return $option->{$option->field_name};
$node = node_load($option->nid);
  $output = '<div class="whatever"><a href="/node/'. $node->nid. '">'; 
      if ($node->field_MyImage[0]['filepath']) {                                             
  $output .= theme('imagecache', '170x123', $node->field_MyImage[0]['filepath']);
    }
  $output .= '</div>'. $node->title. '</a>';
  return $output;
}
vlooivlerke’s picture

I like this last bit of code but I use a view.

how will it work on a view finder?