Forums / General Questions / Need search to return items for empty/blank keyword

Need search to return items for empty/blank keyword

Locked

Views: 1,269

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
31 Aug 2007, 5:25 AM
#1
davidnash avatar

davidnash

New Zenner

Join Date:
Aug 2007
Posts:
3
Plugin Contributions:
0

Need search to return items for empty/blank keyword

I want search to return all items when no keyword is entered (the default behaviour is to return no items).

I'd like to be able select a category from the drop-down on the advanced search page, not enter a search term, click search and see all the items in that category.

You can do this manually by entering '%' into the keyword field (it's the mysql wildcard). However if I try to override $_GET['keyword'] to be '%' when it is empty, zen cart redirects to advanced_search instead of advanced_search_result.

Any suggestions?

31 Aug 2007, 3:17 PM
#2
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Need search to return items for empty/blank keyword

How are you doing the over-ride? If you're doing it properly, ZenCart should not be able to determine a difference between your over-ride and someone typing it in.

BrandTim

31 Aug 2007, 11:04 PM
#3
davidnash avatar

davidnash

New Zenner

Join Date:
Aug 2007
Posts:
3
Plugin Contributions:
0

Re: Need search to return items for empty/blank keyword

Thanks Tim. I'm new to zencart and I'm not sure if I'm doing it correctly.

In includes/templates/mysite/common/tpl_main_page.php I have:

if( $current_page_base == 'index' && isset($_GET['cat']) )
	require(DIR_WS_TEMPLATE . "templates/tpl_category.php");
else if( file_exists(DIR_WS_TEMPLATE . "templates/tpl_$current_page_base.php") )
	require(DIR_WS_TEMPLATE . "templates/tpl_$current_page_base.php");
else
	require(DIR_WS_TEMPLATE . "templates/tpl_not_found.php");

My search forms all have ```
action="index.php?main_page=advanced_search_result"


Is this the information you're after?
1 Sep 2007, 2:59 PM
#4
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Need search to return items for empty/blank keyword

Ok ... you totally lost me on what that code is supposed to do. :blink:

If your goal is just to search for '%' when the search field is left blank, I'd think this would be an easier way:

In includes/modules/pages/advanced_search_result/header_php.php, after this line:

$_GET['keyword'] = trim($_GET['keyword']);

add this:

if (empty($_GET['keyword']) || $_GET['keyword']==HEADER_SEARCH_DEFAULT_TEXT || $_GET['keyword'] == KEYWORD_FORMAT_STRING) {$_GET['keyword']='%';}

BrandTim

1 Sep 2007, 11:52 PM
#5
davidnash avatar

davidnash

New Zenner

Join Date:
Aug 2007
Posts:
3
Plugin Contributions:
0

Re: Need search to return items for empty/blank keyword

Thanks! That works perfectly!

I'm not sure if it's the "correct" way to do it as I'll lose those changes if I update zencart in the future... but I can't see any other way to get the override system to do what I want.

This is why I don't think it's "correct", if you're interested.
The override system really simplified

Thanks again, I appreciate it.

28 Mar 2010, 12:01 PM
#6
adi2009 avatar

adi2009

New Zenner

Join Date:
Dec 2009
Location:
Sarajevo
Posts:
80
Plugin Contributions:
0

Re: Need search to return items for empty/blank keyword

searching trough forum I found this topic and it helped me a lot because I needed same solution on my site, so thank you!

Cheers:wink:

MY Website
The best of the best: Zen Cart