20 replies [Last post]
j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Was this information Helpful?

Posting to toot my own horn, but this might help someone.

My site sells fabric and the search results were only returning the short teaser text and a link to the product. Great if you already knew what you were looking for, but not so helpful if you were unsure. Who wants to click back and forth a bunch just to see it's not what you're looking for?

Now I know there are other ways of doing this, so I expect some better examples to follow. Until then, you can add a very short amount of code to the search-result.tpl.php from the search module folder and then put the new file in your template folder to override the Drupal default results. This was done on a D6.15 & U2.2 install.

Find, copy and open 'search-result-tpl.php' NOT 'search-results.tpl.php', and after all the commented text and the closing php tag paste you want this code in there.

<dt class="title">
<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 href="<?php print $url; ?>"><?php print $title; ?></a>
</dt>
<dd>
  <?php if ($snippet) : ?>
    <p class="search-snippet"><?php print $snippet; ?></p>
  <?php endif; ?>
  <?php if ($info) : ?>
  <p class="search-info"><?php print $info; ?></p>
  <?php endif; ?>
</dd>

My file had nothing but the default code so I just pasted all the above, replacing what was already there. If you already have customized this file then you probably know a lot more than I do so maybe just add the necessary line below.

The part that gave me the images, and in this case I'm using the product_list images under the imagecache folder, is this line here:

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

I haven't done any extra themeing other than the break tag so that my image sits above the title and text, as: 1. I don't know how to make things look nice very well and 2. this fits my needs as I wanted simple small images, and now I have them.

Obviously this is a very basic approach, and it currently only displays the main product image, but it does make the search results much more usable for my situation. I'd like to thank everyone that ever asked this or a similar question on either the Ubercart or the Drupal forums as I probably read your post and every response to it until I worked this out.

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

Old Man's picture
Offline
Joined: 02/23/2010
Juice: 22
Didn't work for me

What you described is exactly what I am trying to do - right down to displaying fabrics in my e-store. I just need the catalog product image to display in a search.

I tried this and couldn't get it to work. First of all, I am using Garland theme, and only changing the search-results.tpl.php in the main search module had any affect. Secondly, there is no search-result-tpl.php file, and creating this file didn't work either.

I tried changing the src directory, since I changed the default file system directory to use with dynamic display blocks, but that didn't work.

Any help or suggestions would be appreciated.

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: Didn't work for me

What you might try is getting the current default search-result.tpl.php file from http://api.drupal.org/api/drupal/modules--search--search-result.tpl.php/6. I posted the file below as well...

<?php
// $Id: search-result.tpl.php,v 1.1.2.1 2008/08/28 08:21:44 dries Exp $

/**
* @file search-result.tpl.php
* Default theme implementation for displaying a single search result.
*
* This template renders a single search result and is collected into
* search-results.tpl.php. This and the parent template are
* dependent to one another sharing the markup for definition lists.
*
* Available variables:
* - $url: URL of the result.
* - $title: Title of the result.
* - $snippet: A small preview of the result. Does not apply to user searches.
* - $info: String of all the meta information ready for print. Does not apply
*   to user searches.
* - $info_split: Contains same data as $info, split into a keyed array.
* - $type: The type of search, e.g., "node" or "user".
*
* Default keys within $info_split:
* - $info_split['type']: Node type.
* - $info_split['user']: Author of the node linked to users profile. Depends
*   on permission.
* - $info_split['date']: Last update of the node. Short formatted.
* - $info_split['comment']: Number of comments output as "% comments", %
*   being the count. Depends on comment.module.
* - $info_split['upload']: Number of attachments output as "% attachments", %
*   being the count. Depends on upload.module.
*
* Since $info_split is keyed, a direct print of the item is possible.
* This array does not apply to user searches so it is recommended to check
* for their existance before printing. The default keys of 'type', 'user' and
* 'date' always exist for node searches. Modules may provide other data.
*
*   <?php if (isset($info_split['comment'])) : ?>


*     <span class="info-comment">
*       <?php print $info_split['comment']; ?>
*     </span>
*   <?php endif; ?>
*
* To check for all available data within $info_split, use the code below.
*
*   <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
*
* @see template_preprocess_search_result()
*/
?>
<dt class="title">
  <a href="<?php print $url; ?>"><?php print $title; ?></a>
</dt>
<dd>
  <?php if ($snippet) : ?>
    <p class="search-snippet"><?php print $snippet; ?></p>
  <?php endif; ?>
  <?php if ($info) : ?>
  <p class="search-info"><?php print $info; ?></p>
  <?php endif; ?>
</dd>

Add the line of code into this, after the closing '?>' tag below all the comented text. Then the file needs to go into your garland theme folder to override any system defaults. after you've put in, you must clear the caches under the performance module in the admin/settings on your site.

The 'search-result.tpl.php' is what configures your individual items, the 'search-results.tpl.php' then aggregates all those into
the page that gets displayed to the user. I don't believe you need to touch the 'results' file, I didn't. Neither of these files typically exist in the Garland theme from what I see on my server.

If you're using Firefox with Firebug installed you can get it to display which directory an image is being served up from. for my site I wanted the product thumbnails that are displayed in the catalog grid file. Or try viewing the page source and see if that will tell you which image location is used so you can change to the directory in the code

If you're running an older version of Drupal or Ubercart then it might not work, my site is running the current release of D6 U2.2 I haven't done a lot major customizing to the site, at least not anything beyond CSS and the theme installed doesn't touch anything deeper than the most basic display.

my site is located at http://www.sew-la-fabric.com, but I'm not sure you'll be able to get much from it if you try the above changes. Again there's probably a other ways to do this, and what I accomplished was using very basic default modules as this was the first time I've used Drupal or Ubercart. But it does show that an inexperienced person can do it.

Good luck.

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

Zalatar's picture
Offline
Joined: 01/27/2009
Juice: 86
Works Great!

Thank you very much. I just added the one line and it worked perfect.
I will mention that the search-result.tpl.php may be located in your theme folder: sites/all/themes/YOUR THEME NAME

Again thanks much,
Z

Old Man's picture
Offline
Joined: 02/23/2010
Juice: 22
AH HAH...

I have my online store in a subdomain. The code for the picture worked after I added the subdomain directory to the beginning of the image src:
src="/sales/sites/default/files/imagecache/product_list/

Now it works! Thank you for the reply!

Old Man's picture
Offline
Joined: 02/23/2010
Juice: 22
Any way to print the sell_price in the Search results?

Now that I have the image working, I want to print the sell price from the product node in my search results. I believe it is "sell_price" that I want to print right after the title, but when I try that I only get a zero or no value at all. I tried printing from the search-result.tpl.php file with this code:

< a href="< ?php print $url; ? >">< ?php print $title; ? ><?php print $sell_price; ? >< /a >

No luck. Any idea?

Stephen Winters's picture
Offline
Joined: 02/16/2010
Juice: 46
subscribe

subscribe

Old Man's picture
Offline
Joined: 02/23/2010
Juice: 22
I like the Views Search for products much better

After some fiddling with the results, I like a search created by Views much better. You don't get an "Add To Cart" button with the standard search, and the formatting isn't that great. The only problem I have with the Views Search is that the search term is specific.

Here is the link to the instructions on how to create the Views search:
http://www.ubercart.org/forum/support/14278/figured_out_how_make_custom_...

Attached is a picture of the result.

AttachmentSize
Product Search View-2.jpg 128.37 KB
j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: I like the Views Search for products much better

I don't have any advice on the formatting or the views search results, but I'm glad that you were able to get even further results with search. My needs are usually fairly simple, but I originally posted what I found so as to get more people to involved that others might then benefit from their work. Thanks for continuing in this direction.

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

buysnakewine's picture
Offline
Joined: 03/31/2009
Juice: 105
Last version of Ubercart ?

Hi,

Does your custom catalog product search works with latest Drupal 6 and Ubercart ?

Thanks.

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: Last version of Ubercart ?

it does work with the latest versions, and it continued to work when I used the custom search module and then again when I switched over to the lucene search modules. I can't remember if I had to do any thing more for those module as it's been a while since I made the changes, but it was fairly simple and while there are many other ways to do this, I was very happy at the time I made the original post as I was still very new to Drupal and Ubercart.

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

joeredhat's picture
Offline
Joined: 12/29/2009
Juice: 65
Another method

Thanks so much for sharing this!

Here's the way we did it so that our thumbnails would be themed. Insert the following code in search-result.tpl.php:

<?php
// get the first thumbnail image
   
$uc_thumbnail_image = $result['node']->field_image_cache[0];
// get the thumbnail image
    
$thumbnail = theme('imagecache', 'uc_thumbnail', $uc_thumbnail_image['filepath'], $uc_thumbnail_image['data']['alt'], $uc_thumbnail_image['data']['title']);
?>

And then after the DD tag

<dd>
<a href="<?php print $url; ?>"><?php print $thumbnail; ?></a>...

The CSS I used to theme the thumbnail looked like this:

dd img{float:left;border:0;margin-right:10px}

And attached is a screen capture of the result.

LDS Book Store | LDS Baptism Gift

AttachmentSize
ctr-ring.png 24.47 KB
rickh's picture
Offline
Joined: 09/09/2010
Juice: 19
Re: I got PICTURES in my search results.

hey guys, sorry but i'm not getting this. I'm using a combining of Acquia prosper and Fusion core and i've tried to apply the code to both, even though i'm pretty sure it's Acquia Prosper. I've flushed the cache, but still not results. I even copied it directly from above with no results. joeredhat, if you could elaborate on what you'cve done, then maybe I can figure this out, but at the moment i'm stuck. any help guys would be seriously helpful.

thanks in advance

rick

James Peck's picture
Offline
Joined: 10/20/2010
Juice: 51
Subscribing

I've the same set up as rickh and having no luck with this.

This link maybe of help to you Rick, but I haven't been able to progress successfully...

http://network.acquia.com/node/1601750

joeredhat's picture
Offline
Joined: 12/29/2009
Juice: 65
Pictures

I'm afraid I'm no longer running Prosper/Fusion, so I can't help much.

Initially, however, I couldn't get mine to display because I was naming the file search-results.tpl.php (with the 's') instead of search-result.tpl.php. Hope that helps.

daamy's picture
Offline
Joined: 02/07/2011
Juice: 24
thank you for this tip. this

thank you for this tip.
this is really a great post.

daamy's picture
Offline
Joined: 02/07/2011
Juice: 24
hi I m little bit confuse

hi

I m little bit confuse about
field_image_cache[0]['filepath'];
I know this gives the path of the image.

but how do I know the id of the different image size?
I mean what to put in the field_image_cache first array.

i.e.
field_image_cache[id]['filepath'];

thank you

bozboz's picture
Offline
Joined: 03/06/2009
Juice: 3
Re: hi I m little bit confuse

You need to use something like this:

<?php
$filepath
= $node->field_image_cache[0]['filepath'];
$preset = 'my_image_cache_preset';
$alt = $node->field_image_cache[0]['data']['alt'];
print
theme('imagecache', $preset, $filepath, $alt, $title, $attributes = array('class' => 'main-product-image'));
?>
bnryzombie's picture
Offline
Joined: 03/30/2012
Juice: 6
Fix for all

all you have todo is edit your search-result.tpl.php if you are using a theme that doesn't come with this file look for it parent theme. I use acquia_prosper the parent theme is fusion. In the Fusion core folder there is your file.
This is mine:

<?php

/**
* @file search-result.tpl.php
* Default theme implementation for displaying a single search result.
*
* This template renders a single search result and is collected into
* search-results.tpl.php. This and the parent template are
* dependent to one another sharing the markup for definition lists.
*
* Available variables:
* - $url: URL of the result.
* - $title: Title of the result.
* - $snippet: A small preview of the result. Does not apply to user searches.
* - $info: String of all the meta information ready for print. Does not apply
*   to user searches.
* - $info_split: Contains same data as $info split into a keyed array.
* - $type: The type of search, e.g., "node" or "user".
*
* Default keys within $info_split:
* - $info_split['type']: Node type.
* - $info_split['user']: Author of the node linked to users profile. Depends
*   on permission.
* - $info_split['date']: Last update of the node. Short formatted.
* - $info_split['comment']: Number of comments output as "% comments", %
*   being the count. Depends on comment.module.
* - $info_split['upload']: Number of attachments output as "% attachments", %
*   being the count. Depends on upload.module.
*
* Since $info_split is keyed, a direct print of the item is possible.
* This array does not apply to user searches so it is recommended to check
* for their existance before printing. The default keys of 'type', 'user' and
* 'date' always exist for node searches. Modules may provide other data.
*
*   <?php if (isset($info_split['comment'])) : ?>

*     <span class="info-comment">
*       <?php print $info_split['comment']; ?>
*     </span>
*   <?php endif; ?>
*
* To check for all available data within $info_split, use the code below.
*
*   <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
*
* @see template_preprocess_search_result()
*/
?>
<div class="search-result <?php print $search_zebra; ?>">
  <a href="<?php print $url; ?>">
  <dt class="title"><h3>
    <?php print $title; ?>
  </h3></dt>
  <dd>
    <?php if ($snippet) : ?>
<table><tr>
<td><img src="/sites/ccjdmotorsports.com/files/imagecache/product/<?php print $result['node']->field_image_cache[0]['filepath']; ?>" /></td>
<td><p class="search-snippet"><?php print $snippet; ?></p></td>
</tr></table>
    <?php endif; ?>
</a>
   
    <?php if ($info_split) : ?>
    <p class="search-info">
      <?php $info_separator = ''; ?>
     
      <?php if (isset($info_split['type'])) : ?>
      <span class="search-info-type"><?php print $info_split['type']; ?></span>
        <?php $info_separator = ' - '; ?>
      <?php endif; ?>
       
      <?php if (isset($info_split['user'])) : ?>
      <span class="search-info-user"><?php print $info_separator . $info_split['user']; ?></span>
        <?php $info_separator = ' - '; ?>
      <?php endif; ?>
       
      <?php if (isset($info_split['date'])) : ?>
      <span class="search-info-date"><?php print $info_separator . $info_split['date']; ?></span>
        <?php $info_separator = ' - '; ?>
      <?php endif; ?>
       
      <?php if (isset($info_split['comment'])) : ?>
      <span class="search-info-comment"><?php print $info_separator . $info_split['comment']; ?></span>
        <?php $info_separator = ' - '; ?>
      <?php endif; ?>
     
      <?php if (isset($info_split['upload'])) : ?>
      <span class="search-info-upload"><?php print $info_separator . $info_split['upload']; ?></span>
      <?php endif; ?>
    </p>
    <?php endif; ?>
  </dd>
  <hr />
</div><!-- /search-result -->

Below is a picture of a search:

AttachmentSize
post.jpg 82.82 KB
bnryzombie's picture
Offline
Joined: 03/30/2012
Juice: 6
location

Mine is located at:

/sites/all/themes/fusion/fusion_core
or
/themes/fusion/fusion_core

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 511
Easier to use Google...

Hello,

Are you still using this ?

It seems so much easier to use google Google search..

Thanks anyway.