Zen Cart Logo
Forums / General Questions / Search based on category you are in

Search based on category you are in

Views: 1,304

Results 1 to 14 of 14
13 Jun 2014, 2:21 AM
#1
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Search based on category you are in

Lets say I have multiple products for different categories, I was thinking this would be cool to have it so when you search for something it looks only in the category you are in or if you are not in a category it will make you select the category you wan't to search in.

13 Jun 2014, 3:22 AM
#2
yaritai avatar

yaritai

Zen Follower

Join Date:
Apr 2014
Posts:
154
Plugin Contributions:
0

Re: Search based on category you are in

StoreOwner:

Lets say I have multiple products for different categories, I was thinking this would be cool to have it so when you search for something it looks only in the category you are in or if you are not in a category it will make you select the category you wan't to search in.

Have you ever considered test driving your site to see what functional capabilities zencart has? I say this as the advanced search already HAS this function to filter out categories and subcategories.

But if you are speaking not using the advanced search and just the search box, then sure you could implement the search box to limit the results to the current category. However, is this really neccesary from a customer standpoint? I would not go this route but instead include a mod like dynamic filter as it has sorting capabilities on that is dependent on the category you are in to show the selections.

13 Jun 2014, 6:17 PM
#3
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

yaritai:

Have you ever considered test driving your site to see what functional capabilities zencart has? I say this as the advanced search already HAS this function to filter out categories and subcategories.

But if you are speaking not using the advanced search and just the search box, then sure you could implement the search box to limit the results to the current category. However, is this really neccesary from a customer standpoint? I would not go this route but instead include a mod like dynamic filter as it has sorting capabilities on that is dependent on the category you are in to show the selections.

I would like it because for a shop like mine it would slim things down for customers, instead of having to search nonstop + see what products I have it would make things way easier..

Searching is used very often in my store..

13 Jun 2014, 8:30 PM
#4
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,777
Plugin Contributions:
21

Re: Search based on category you are in

I definitely agree with yaritai that this is not an option I'd like seeing - advanced search already has an option to search in specific category. The results might come out confusing, or even worse, you might not get the results that might lead to a sale...

But, it's your site and you decide if you want to have it. I'll assume you want this for your header search box. Unless it was previously customized or replaced with another mod, you could try the following:
includes/templates/YOUR_TEMPLATE/sideboxes/tpl_search_header.php
Find:

$content .= zen_draw_hidden_field('search_in_description', '1') . zen_hide_session_id();

and replace with:

// BOF search in current category only
  $content .= zen_draw_hidden_field('search_in_description', '1');
  if($current_category_id) {
	  $content .= zen_draw_hidden_field('categories_id', $current_category_id);
	  $content .= zen_draw_hidden_field('inc_subcat', '1');
  }
  $content .=  zen_hide_session_id();
  // EOF search in current category only

Please note that I advise against doing this, but I don't know your specific requirements nor your site and products so this might actually be a good idea in some specific cases.

Regards,
Leonard

13 Jun 2014, 10:56 PM
#5
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

balihr:

I definitely agree with yaritai that this is not an option I'd like seeing - advanced search already has an option to search in specific category. The results might come out confusing, or even worse, you might not get the results that might lead to a sale...

But, it's your site and you decide if you want to have it. I'll assume you want this for your header search box. Unless it was previously customized or replaced with another mod, you could try the following:
includes/templates/YOUR_TEMPLATE/sideboxes/tpl_search_header.php
Find:

$content .= zen_draw_hidden_field('search_in_description', '1') . zen_hide_session_id();

> and replace with:
> ```
// BOF search in current category only
  $content .= zen_draw_hidden_field('search_in_description', '1');
  if($current_category_id) {
	  $content .= zen_draw_hidden_field('categories_id', $current_category_id);
	  $content .= zen_draw_hidden_field('inc_subcat', '1');
  }
  $content .=  zen_hide_session_id();
  // EOF search in current category only

Please note that I advise against doing this, but I don't know your specific requirements nor your site and products so this might actually be a good idea in some specific cases.

Regards,
Leonard

Thanks again Leonard, one more thing and I think my store looks complete

Can I add a search bar in product listing page above product image product name price and centered?

or is this a pain to do?

13 Jun 2014, 11:22 PM
#6
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,777
Plugin Contributions:
21

Re: Search based on category you are in

StoreOwner:

Can I add a search bar in product listing page above product image product name price and centered?

To be perfectly honest - I have no idea. I've never had any similar requests...

You might give this a try, although I have no idea if it'll work:
edit your includes/templates/YOUR_TEMPLATE/template/tpl_index_categories.php, add a new div above the pagination and then require tpl_search_header.php (which you'll need to modify a bit to echo the $content so it would be best to duplicate the file and rename it). You would do the same for tpl_index_product_list.php. Oh, and you'll need to exclude the code based on $current_page_base because, for example, advanced_search_results uses tpl_index_product_list.php for the results...

This is just an idea which I haven't tested, although I don't see a reason why it wouldn't work. Unfortunately, I don't have the time to go play with it right now, sorry.

13 Jun 2014, 11:32 PM
#7
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

Alright thx again, I will just leave it for now maybe mess with it later :)

18 Jun 2014, 5:59 AM
#8
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

Alright so I started messing with it again and It doesn't seem to work right, just displays the code in the categories

at the top of tpl_index_categories.php I add this

<div class="searchListing" id="indexCategories"> require($template->get_template_dir('tpl_search_header.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_search_header.php'); }
29 Jun 2014, 4:16 AM
#9
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

Bumpity bump bump

30 Jun 2014, 12:02 AM
#10
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,777
Plugin Contributions:
21

Re: Search based on category you are in

StoreOwner:

Alright so I started messing with it again and It doesn't seem to work right, just displays the code in the categories

at the top of tpl_index_categories.php I add this

<div class="searchListing" id="indexCategories"> require($template->get_template_dir('tpl_search_header.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_search_header.php'); }

If this is the EXACT code you added, then of course it's not working - you need to wrap the php code inside php tags... Something like this:

<div id="categorySearch">
<?php require($template->get_template_dir('tpl_search_header.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_search_header.php'); ?>
</div>

Keep in mind this WON'T work unless you modify the tpl_search_header.php file as well and echo the content, but if you do that in the same file, you'll mess it up for the header... The best solution would be to create a clone of the header search box and then use that for listing pages, but you could always use the hillbilly method like this:

<div id="categorySearch">
<?php require($template->get_template_dir('tpl_search_header.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_search_header.php');
echo $content; ?>
</div>

Just don't tell anyone you heard this from me... :wink:

Regards,
L.

30 Jun 2014, 6:23 AM
#11
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

balihr:

If this is the EXACT code you added, then of course it's not working - you need to wrap the php code inside php tags... Something like this:

<div id="categorySearch"> <?php require($template->get_template_dir('tpl_search_header.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_search_header.php'); ?> </div> ``` > > Keep in mind this WON'T work unless you modify the tpl_search_header.php file as well and echo the content, but if you do that in the same file, you'll mess it up for the header... The best solution would be to create a clone of the header search box and then use that for listing pages, but you could always use the hillbilly method like this: > ``` <div id="categorySearch"> <?php require($template->get_template_dir('tpl_search_header.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_search_header.php'); echo $content; ?> </div> ``` > Just don't tell anyone you heard this from me... :wink: > > Regards, > L.

hehe ur secrets safe with me, can't believe it was that simple _

now for css to align center it would look something similar like this? but this ones not working for some reason.

.categorySearch
align-content: center;
}

also noticed something else when you search it, it works fine but when you type in another search it shows for all categories not just the one your in

30 Jun 2014, 7:02 AM
#12
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

Also I changed the name of the shopping cart to this

define('BOX_HEADING_SHOPPING_CART', 'Shopping Cart');

and its showing up this:
Shopping Cart -

how would I go about removing the dash -

30 Jun 2014, 11:02 AM
#13
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,777
Plugin Contributions:
21

Re: Search based on category you are in

The CSS - my example is using div id, not class. So, if you copied that code, your CSS would have to look like this:

#categorySearch {
	text-align:center;
}

Another search - where are you using it? On the results page? That's what I tried to explain in post #6 - you'll need to disable the search box based on current page base. The search works based on current category id which means that it searches the category you're currently browsing - if you're on the results page, then you're not browsing a category...

The dash in shopping cart - I've no idea. Must be somewhere in the sidebox module, but it's not a normal part of the template, someone probably added it so I can't tell...

30 Jun 2014, 1:05 PM
#14
storeowner avatar

storeowner

New Zenner

Join Date:
Jun 2014
Location:
United States
Posts:
60
Plugin Contributions:
0

Re: Search based on category you are in

worked but its not lined up well :P

thx

Can I make the search box bigger so it shows more in it?