Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1
    Join Date
    Nov 2007
    Posts
    18
    Plugin Contributions
    0

    help question Search Redirect if only one result found

    If someone uses the search function and only one matching product is found, can the search result redirect to that product's page automatically?

    I've searched around a bit, but can't find how to do this.

    Thanks in advance!!!!

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,655
    Plugin Contributions
    25

    Default Re: Search Redirect

    At the very bottom of includes/modules/pages/advanced_search_result/header_php.php is a piece of code that redirects visitors abck to the advanced search page if there are no products found. You would want to add a similar redirect that says "Aha, only one? then go to the product info page instead!" (but in PHP)
    See and test drive Zen Cart's free templates at zencarttemplates.info

    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  3. #3
    Join Date
    Nov 2007
    Posts
    18
    Plugin Contributions
    0

    Default Re: Search Redirect

    Yeah, except I don't know very much php. I see the file you're talking about, but I don't know how to modify it to do what you said.

  4. #4
    Join Date
    Jan 2004
    Posts
    58,249
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Search Redirect

    At the bottom of that file, you have a section of code similar to the following.
    Simply add the additional lines highlighted here:
    Code:
    $result = new splitPageResults($listing_sql, MAX_DISPLAY_PRODUCTS_LISTING, 'p.products_id', 'page');
    if ($result->number_of_rows == 0) {
      $messageStack->add_session('search', TEXT_NO_PRODUCTS, 'caution');
      zen_redirect(zen_href_link(FILENAME_ADVANCED_SEARCH, zen_get_all_get_params('action')));
    }
    // if only one product found in search results, go directly to the product page, instead of displaying a link to just one item:
    if ($result->number_of_rows == 1 && SKIP_SINGLE_PRODUCT_CATEGORIES == 'True') {
      $result = $db->Execute($listing_sql);
      zen_redirect(zen_href_link(zen_get_info_page($result->fields['products_id']), 'cPath=' . zen_get_product_path($result->fields['products_id']) . '&products_id=' . $result->fields['products_id']));
    }
    
    
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS', $keywords);
    //EOF
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Nov 2007
    Posts
    18
    Plugin Contributions
    0

    Default Re: Search Redirect if only one result found

    That didn't quite work. I have ZenCart 1.3.7.1. The heading of the file (/includes/modules/pages/advanced_search_result/header_php.php) says:

    Code:
     @version $Id: header_php.php 4857 2006-10-28 17:40:08Z ajeh $
    and the end of the file's code is as follows:

    Code:
    $listing_sql = $select_str . $from_str . $where_str . $order_str;
    // Notifier Point
    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING');
    $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_ADVANCED_SEARCH));
    $breadcrumb->add(NAVBAR_TITLE_2);
    
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS');
    ?>
    Am I looking at the wrong file?

    Thanks again for your help!!!

  6. #6
    Join Date
    Jan 2004
    Posts
    58,249
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Search Redirect if only one result found

    Sorry, that was based on 1.3.8

    Just put it above the last notifier section:
    Code:
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS', $keywords);
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Nov 2007
    Posts
    18
    Plugin Contributions
    0

    help question Re: Search Redirect if only one result found

    if I add only the lines that are in red, I get this:

    Home :: Advanced Search :: Search Results :: Advanced Search :: Search Results
    Advanced Search
    1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by p.products_sort_order, pd.products_name limit 0, 10' at
    in:
    [SELECT DISTINCT p.products_image, p.products_quantity , m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_price_sorter, p.products_qty_box_status FROM (products p LEFT JOIN manufacturers m USING(manufacturers_id), products_description pd, categories c, products_to_categories p2c ) LEFT JOIN meta_tags_products_description mtpd ON mtpd.products_id= p2c.products_id AND mtpd.language_id = 1 WHERE (p.products_status = 1 AND p.products_id = pd.products_id AND pd.language_id = 1 AND p.products_id = p2c.products_id AND p2c.categories_id = c.categories_id AND ((pd.products_name LIKE '%hp%' OR p.products_model LIKE '%hp%' OR m.manufacturers_name LIKE '%hp%' OR (mtpd.metatags_keywords LIKE '%hp%' AND mtpd.metatags_keywords !='') OR (mtpd.metatags_description LIKE '%hp%' AND mtpd.metatags_description !='') OR pd.products_description LIKE '%hp%') )) order by p.products_sort_order, pd.products_name order by p.products_sort_order, pd.products_name limit 0, 10]
    (I included the breadcrumbs in hopes that it might help in figuring out what's wrong.)

    If I add everything in the box (replacing the last line - this line is still slightly different than what you indicate it should be), it works when only one product is returned, but gives the error message when multiple products should be returned.

    I'm still stuck...

  8. #8
    Join Date
    Jan 2004
    Posts
    58,249
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Search Redirect if only one result found

    For 1.3.7.1, change this:
    Code:
    $listing_sql = $select_str . $from_str . $where_str . $order_str;
    // Notifier Point
    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING');
    $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_ADVANCED_SEARCH));
    $breadcrumb->add(NAVBAR_TITLE_2);
    
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS');
    ?>
    to this:
    Code:
    $listing_sql = $select_str . $from_str . $where_str . $order_str;
    // Notifier Point
    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING');
    $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_ADVANCED_SEARCH));
    $breadcrumb->add(NAVBAR_TITLE_2);
    
    
    // if only one product found in search results, go directly to the product page, instead of displaying a link to just one item:
    $result = new splitPageResults($listing_sql, MAX_DISPLAY_PRODUCTS_LISTING, 'p.products_id', 'page');
    if ($result->number_of_rows == 1 && SKIP_SINGLE_PRODUCT_CATEGORIES == 'True') {
      $result = $db->Execute($listing_sql);
      zen_redirect(zen_href_link(zen_get_info_page($result->fields['products_id']), 'cPath=' . zen_get_product_path($result->fields['products_id']) . '&products_id=' . $result->fields['products_id']));
    }
    
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS');
    ?>
    Last edited by DrByte; 21 Jan 2008 at 09:21 AM. Reason: added missing top code block
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Nov 2007
    Posts
    18
    Plugin Contributions
    0

    Default Re: Search Redirect if only one result found

    You didn't indicate what to change, so I just added the code. This resulted in the same error.

    Can we try one more time?

    I really appreciate all of your help!

  10. #10
    Join Date
    Nov 2007
    Posts
    18
    Plugin Contributions
    0

    Default Re: Search Redirect if only one result found

    If it helps, my site is: VictoryToner.com/catalog

    Search for C6656AN to return 1 product (redirect works)

    Search for HP toner to return multiple products (error message)

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. problem with search result
    By maxus in forum General Questions
    Replies: 0
    Last Post: 25 Apr 2007, 05:28 PM
  2. hide product from the search Result
    By hossam in forum General Questions
    Replies: 0
    Last Post: 14 May 2006, 07:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •