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!!!!
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!!!!
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)
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.![]()
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.
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:
and the end of the file's code is as follows:Code:@version $Id: header_php.php 4857 2006-10-28 17:40:08Z ajeh $
Am I looking at the wrong file?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'); ?>
Thanks again for your help!!!
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.
if I add only the lines that are in red, I get this:
(I included the breadcrumbs in hopes that it might help in figuring out what's wrong.)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]
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...
For 1.3.7.1, change this:
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); // This should be last line of the script: $zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS'); ?>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.
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!
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)
Bookmarks