Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Redirecting to product page if only one search result.


Recommended Posts

I've search for this, but only found one post where no one had replied :(


It would seem logical that if you searched for something and there was only one product that matched, it would redirect you straight to the product info instead of having to wait for the search results page to load and then clicking another link to get to the info.


I've done some research and have figured you need a header(location=<url>) function in the code, so you would have to call this after getting for product url from the database, but by that time, you have already echoed the header and get an error as the header function must be called before outputing anything.


I have come to the conclusion that you would have to merge the advanced_search_results and modules/product_listing file and then rearrange these so that you can call the header function before output is made? However, doing it this way would first show the url of advanced_search_results in the address bar before redirection?


Also read something on Apache FORCETYPE...is this relavent? Am I way off? Anyone got a working solution? PLEASE!! :)


amazon.com and buy.com both have working examples of redirection without a results page being shown for one unique search result.


Hope that all makes sense!! :) Thanks for your help.

Link to comment
Share on other sites

That's a good idea. But would it not be confusing for the customer to sometimes get a list of items when they search and other times go directly to the product page ?


I guess you could write an extra piece of "heading_title" on product_info.php to combat this "Here is the result of your search"...


Yes, a good idea. if you get anywhere with it, be sure to post back.

Link to comment
Share on other sites

WOW!!! I got it to work!...and what a load of freaking hassle it was too!


Is is basically as I outlined above. Merge modules/product_lisiting and advanced_search_results, putting all the php at the top, making sure there is no output (echo commands) before querying the database for the number of rows ($listing_numrows). Here's the code for that below.


if ($listing_numrows==1) {

$listing = tep_db_fetch_array($listing_query);

header("Location: ".tep_href_link(FILENAME_PRODUCT_INFO, '&products_id=' . $listing['products_id']));




I will post a modified file when I get it cleaned up if there is enough demand for it...I was hoping more people would have come forward and helped already or at least given me some clues.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...