7 replies [Last post]
livewire1337's picture
Offline
Joined: 06/04/2009
Juice: 37
Was this information Helpful?

So I'm looking for a way to add product images to the Drupal search. I am currently using the theme search function, theme_search_item($item, $type), to display the information I want in the search, however, I don't know how to get the image from the product.

I would like to use the product_list imagecache preset for Drupal search results.

How do I go about getting this image of the product using imagecache so that I can put it in the Drupal Search results?

wbclassics's picture
Offline
Joined: 01/25/2009
Juice: 55
Re: Adding Product Images to Drupal Search

Something like this http://drupal.org/project/finder ? (see image on linked project page)

livewire1337's picture
Offline
Joined: 06/04/2009
Juice: 37
Re: Re: Adding Product Images to Drupal Search

Yes, the product search image is my goal.

I have looked at the source code for the Ubercart pictured cart block module: http://drupal.org/project/uc_pic_cart_block, which gets the image of the product and adds it to a cart block, however its functions use variables that I don't know how to get using the Drupal search such as $node_id, $preset, $path_module, $product and various others.

this is a code snippet from the Ubercart pictured cart block module that shows how it gets the images from the products and uses a predefined imagecache preset to add it t the cart block:

/**
* Getting picture of product.
*
* @param $node_id
*   ID of product node.
* @param $preset
*   The name of ImageCache preset.
* @param $path_module
*   Path to this module.
* @return
*   Themed image (linked to node if can view).
*
* @see uc_product_get_picture()
*/
function uc_pic_cart_block_get_picture($node_id, $preset, $path_module) {
  $img = '';
 
  $product = node_load($node_id);
  $field = variable_get('uc_image_'. $product->type, '');

  if (isset($product->$field)) {
    $image = $product->{$field}[0];
    $path = $image['filepath'];
    if (file_exists($path)) {
      $img = theme('imagecache', $preset, $path, $image['data']['alt'], $image['data']['title']);
    }
  }
 
  if (empty($img)) {// theming default image
    $img = theme('imagecache', $preset, $path_module .'/img/no_image.gif', t('No pic'), check_plain($product->title) .' ('. t('no picture available') .')');
  }
 
  if (node_access('view', $product)) {
    $output = l($img, 'node/'. $product->nid, array('html' => TRUE));
  }
  else {
    $output = $img;
  }
 
  return $output;
}

How can I use this to help me in getting pictures in the Drupal search?

johngflower's picture
Offline
Joined: 01/04/2009
Juice: 88
Images in Drupal Search

*bump*

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 163
Re: Adding Product Images to Drupal Search

Did you ever find a solution to this? I'm looking to implement the same functionality also.

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
If you want simple try this

A very simple approach I just used and which I just posted in the how-to's which can be found
at http://www.ubercart.org/forum/tutorials/15568/i_got_pictures_my_search_r...

It was done by simply adding one line of code and overriding the default file.

add this to your search-result.tpl.php file and put the new copy in your theme folder...

<a href="<?php print $url; ?>"><img src="/sites/default/files/imagecache/product_list/<?php print $result['node']->field_image_cache[0]['filepath']; ?>"/></a>><br>

a bit more of an explanation is at my other post, put the above is all you need for a basic image in the search.

the sites i'm always breaking.... www.sew-la-fabric.com
http://lostpetsla.com (though i hope i never break this one too bad)

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Hi, Will try this! Greetings,

Hi,
Will try this! Greetings, Martijn

amitks05's picture
Offline
Joined: 08/04/2011
Juice: 11
how i add product image in drupal search

tell me