Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Expanding search to work with my custom product-type

Expanding search to work with my custom product-type

Locked

Views: 4,699

Results 1 to 20 of 22
This thread is locked. New replies are disabled.
20 Feb 2008, 8:53 PM
#1
elastic avatar

elastic

New Zenner

Join Date:
Dec 2007
Location:
New Jersey
Posts:
76
Plugin Contributions:
0

Expanding search to work with my custom product-type

i have created new product type, based on the book, but very very different. I have added many fields to my product_type_XXXX_extra field and have that working perfectly, and even have added a filter similar to the author name in the book product. well and good, one filter down, and a process to continue adding (there are 30 criteria which can be filtered in this manner.) 30 drop down menus is a lot, and a lot of work to write session for all.

what i need: add each of the fields in the PRODUCT_TYPE_XXXX_EXTRA field i made into the standard search. i know text based searches are hard, i know it will take some php scripting, I am not afraid of that. but I do not know:

  1. which .php pages will i need to over-ride
  2. where are the search filter pages located in the ZC system

i think it has something to do with the alpha filter.... am I on right track?

by the way, kudos to the ZC team for making the over-ride system as proficient as it is. Nice work!

21 Feb 2008, 10:06 PM
#2
elastic avatar

elastic

New Zenner

Join Date:
Dec 2007
Location:
New Jersey
Posts:
76
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

is anyone out there interested in this question? am i asking it in the wrong place?

21 Feb 2008, 10:13 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

The search is largely handled by the files in the /includes/index_filters folder.
Check out the music-type filters present there for some examples of how the search was expanded for those purposes.

24 Feb 2008, 12:24 AM
#4
elastic avatar

elastic

New Zenner

Join Date:
Dec 2007
Location:
New Jersey
Posts:
76
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

ahh, yes. i understand this, because i was able to successfully create a drop down menu that returns a list of items with a single selector.

this is nice, and very useful. but i need to add a text based search, one where I can type contents of a new field, and have that field be indexed and searched just as all the others are.

i can pick from a drop down menu, and it makes its selection and it is lovely. but! if i type the exact same search criteria, this fails to return a result. it's not really a bug, of course, but it appears buggy to users who don't know.

i need to edit those SQL queries to include the new tables, but I don't know which ones to change....

24 Feb 2008, 1:01 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

It's going to take some time to figure out what you need and how to code it.
The search is handled by those files and the /includes/modules/pages/advanced_search_results/header_php.php file.

If you're not certain that you'll be able to figure it out yourself, I suggest posting an ad asking for paid help in the Commercial Help Wanted area so that you can get someone to spend focused time on rewriting the queries as you desire.

24 Feb 2008, 2:11 AM
#6
elastic avatar

elastic

New Zenner

Join Date:
Dec 2007
Location:
New Jersey
Posts:
76
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

thanks for pointing out the file i need to look at. I wasn't sure about the ZC system. i have spent the last several hours going through many of the posts in this forum requesting similar information, and i had just discovered that others have success in modifying includes/languages/english/advanced_search.php.

i am absolutely certain that I can rewrite the SQL queries to give me exactly what I am looking for. In fact, I have already planned out exacly what they should be.

It's not difficult, just joining additional table and columns to the original search. The trick is knowing where to place the query and have it show up!

2 Apr 2008, 5:29 AM
#7
elastic avatar

elastic

New Zenner

Join Date:
Dec 2007
Location:
New Jersey
Posts:
76
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

I have been working on a solution to the issue of not being able to do a search on text, specifically the book_author or whatever it may be for whatever custom product type you have.

I had two issues to contend with First was dealing with writing new search filters. I generated new pages in zen to deal with alternative search filters not included in core structure. Then I generated new product listings because I didn't like the variaton i was getting (the diff between all and category listing - i based new pages first on the products-all page). I am pleased that all my products are showing up with the grid layout, a preferable and cleaner look.

Then I got a bit creative. I have now a test site where I search on multiple specialized filters, using flash (and pure html in another test) to push variables to the filters, which will allow me to do multi-level searches on products.

in other words, now I can look for: BOOK TYPE & BOOK SIZE and only get returns that match both criteria. I can extend this to search for - for example -

SHOES >> WOMENS >> BLACK

and really drill down the results. It's a fun piece of code, and I may make a contribution if there is any interest.

oh, yeah, BTW - One Interesting Note - when I posted the question about which pages in the over-ride system to modify, no one even mentioned that you cannot override the advanced search pages. I guess that's what the wiki's for...

2 Jan 2009, 6:13 PM
#8
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

I have been working on the search in conjunction with the new product type I have added. I was successful within advanced search; however on my home page when someone attempts to do a basic text search, the systems takes forever now to return the search results. The results "are" returned, however someone with a slow connection could actually be timed out by this. I've looked at my code and I can't figure out what would be doing this.

A further note: On the Advanced Search page - the text search works perfectly! So that must mean that the mods done to the advanced search results file were done correctly, but what is driving the search results specifically for the search box in the header of the site? I thought it would be the same files. I'm really baffled by this and my customer is less than thrilled to put it mildly.

Can anyone suggest a good way for me to track down exactly what is creating the delay created by the home page search box? I have the error details turned on and it doesn't return any errors - I've check my sql processes at the time I do the search and I just can't seem to identify which query is bogging down. :frusty:

I think I need a little push in the right direction here from the core developers. Any light at the end of the tunnel would be great.

Here is the link to the site -mysite Feel free to first search on the home page (use the box in the header - I have a Google search enabled to give folks an alternative till this is fixed). After trying your search on the home page - and do something really simple, like the name of a product, then go to the advanced search and try the exact same search. You will see my dilemma.

Thanks so much for any help or ideas anyone can lend my way.

Ruth

2 Jan 2009, 6:33 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

The header search box is very simple and only uses 2 parameters, ie:
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&search_in_description=1&keyword=leather

The advanced search adds several more parameters, like this:
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&keyword=leather&search_in_description=1&categories_id=&inc_subcat=1&manufacturers_id=&departments_id=&styles_id=&pfrom=&pto=&dfrom=&dto=

This is normal behavior.

However, if you start paring things down and removing parameters from the URL, you'll discover that something's amiss with how you're handling the blank departments_id parameter:
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&keyword=leather&search_in_description=1&departments_id=
vs
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&keyword=leather&search_in_description=1&categories_id=&inc_subcat=1&manufacturers_id=&styles_id=&pfrom=&pto=&dfrom=&dto=

I suspect you're including certain SQL search criteria if the departments_id parameter exists, but you're not first checking to see whether it's valid vs blank etc, thus throwing your SQL query into chaos.

2 Jan 2009, 6:51 PM
#10
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

DrByte:

The header search box is very simple and only uses 2 parameters, ie:
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&search_in_description=1&keyword=leather

The advanced search adds several more parameters, like this:
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&keyword=leather&search_in_description=1&categories_id=&inc_subcat=1&manufacturers_id=&departments_id=&styles_id=&pfrom=&pto=&dfrom=&dto=

This is normal behavior.

However, if you start paring things down and removing parameters from the URL, you'll discover that something's amiss with how you're handling the blank departments_id parameter:
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&keyword=leather&search_in_description=1&departments_id=
vs
http://www.onegoodpair.com/index.php?main_page=advanced_search_result&keyword=leather&search_in_description=1&categories_id=&inc_subcat=1&manufacturers_id=&styles_id=&pfrom=&pto=&dfrom=&dto=

I suspect you're including certain SQL search criteria if the departments_id parameter exists, but you're not first checking to see whether it's valid vs blank etc, thus throwing your SQL query into chaos.

If you were here I would kiss you!!! .:hug:..LOL - just for answering me. I can't tell you how bald I am trying to figure this out. I really believe it's the old... you can't see the forest for the trees. You work on something for so long... that it all blurs together. The baffling part is how great the text search works on the advanced page.. in a split second!

I will pull these files back down and take a look at what I've done and post the code.. the changes are minimal, but you're right.. I don't remember doing the "else if" - hopefully I can see what I need to do looking at it from this point of view.

Again.. thank you so much for being there!! I'm not the greatest PHP coder that's for sure, but most of the time, if I noodle with something long enough I can figure it out. That's what happens when you are totally self taught I guess.

Ruth

2 Jan 2009, 7:20 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

rwoody:

I'm not the greatest PHP coder that's for sure, but most of the time, if I noodle with something long enough I can figure it out. That's what happens when you are totally self taught I guess.Same here.

2 Jan 2009, 8:27 PM
#12
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

Here is the code that I have modified. It is just below the following code:```php
if (isset($_GET['dto']) && zen_not_null($_GET['dto']) && ($_GET['dto'] != DOB_FORMAT_STRING)) {

$where_str .= " and p.products_date_added <= :dateAdded";

$where_str = $db->bindVars($where_str, ':dateAdded', zen_date_raw($dto), 'date');

}


**My Code:**

```php
// added by rwoody

if (isset($_GET['departments_id']) && zen_not_null($_GET['departments_id'])) {

  $where_str .= " AND dp.departments_id = :departmentsID";

  $where_str = $db->bindVars($where_str, ':departmentsID', $_GET['departments_id'], 'integer');

}



// added by rwoody

if (isset($_GET['styles_id']) && zen_not_null($_GET['styles_id'])) {

  $where_str .= " AND dp.style_id = :styleID";

  $where_str = $db->bindVars($where_str, ':styleID', $_GET['styles_id'], 'integer');

}



if (isset($_GET['styles_id']) or isset($_GET['departments_id'])) $where_str .= " AND dp.products_id = p.products_id";
// eoa rwoody

Note that I have asked the code to check "if not null", which is what I'm sure you were referring to in checking to see if the field is blank (by the way.. every product in the system has these parameters defined) -

What I don't understand is why the calls are different in the two search boxes. As you stated the search on the header is simple -

Let's say I'm searching for black - the header search is sending this request based on the url - index.php?main_page=advanced_search_result&search_in_description=1&keyword=black

But.. if you ask for the same search in the text search box on the advanced search page without adding any parameters - the call is this:

index.php?main_page=advanced_search_result&keyword=black&search_in_description=1&categories_id=&inc_subcat=1&manufacturers_id=&departments_id=&styles_id=&pfrom=&pto=&dfrom=&dto=&x=0&y=0

My question is Why? If I understand where the header search is getting its call from, then I can possibly figure out what I need to edit to make it work the same way. I'm sorry if I seem dense on this - Is there a way I can get both boxes to pull the text search the same way?

Ruth

2 Jan 2009, 9:05 PM
#13
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

Ok, in trying to track this down - I found the code that "may" be the issue, and has not been touched.

In templates/sideboxes/tpl_search_header.php is the following:

$content = "";
  $content .= zen_draw_form('quick_find_header', zen_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get');
  $content .= zen_draw_hidden_field('main_page',FILENAME_ADVANCED_SEARCH_RESULT);
  $content .= zen_draw_hidden_field('search_in_description', '1') . zen_hide_session_id();

Can you assist me in modifying this so it will call that search in the same fashion as it is called in the text box on the advanced search page. I'm really drawing a blank on what I should try here. What parameters can we add that will give the snappy result that the adv. search text returns.

2 Jan 2009, 9:13 PM
#14
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

One more note - in modules/pages/advanced_search/header.php at the end of the file I added - (almost forgot about this one)

$sData['departments_id'] = (isset($_GET['departments_id']) ? zen_output_string($_GET['departments_id']) : 0);

  $sData['styles_id'] = (isset($_GET['styles_id']) ? zen_output_string($_GET['styles_id']) : 0);

Now I've even tried totally removing that code, to see if it made any difference and it did not. The header search is still timing out.

2 Jan 2009, 10:37 PM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

rwoody:

What I don't understand is why the calls are different in the two search boxes. As you stated the search on the header is simple -

Let's say I'm searching for black - the header search is sending this request based on the url - index.php?main_page=advanced_search_result&search_in_description=1&keyword=black

But.. if you ask for the same search in the text search box on the advanced search page without adding any parameters - the call is this:

index.php?main_page=advanced_search_result&keyword=black&search_in_description=1&categories_id=&inc_subcat=1&manufacturers_id=&departments_id=&styles_id=&pfrom=&pto=&dfrom=&dto=&x=0&y=0

My question is Why?

The header search is supposed to be simple.
The solution for your problem is not related to the header search box. Your problem is in how you're handling a defined-but-blank value for departments_id

2 Jan 2009, 10:43 PM
#16
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

I'm sorry.. I must be totally thick headed on this one, as I just can't see what I need to do.

I think I'm going to kill the header search and replace it with a link to the adv. search page. That works perfectly and really fast no matter what the parameters are. I just can't come up with a better solution right now that doesn't kill the site.

Thanks for trying to help me. I'll will dig into it further over the weekend and see how I can re-write the code to address this, right now I just don't have a clue.:blink:

Ruth

2 Jan 2009, 11:03 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

Your problem is likely in this line:```
if (isset($_GET['styles_id']) or isset($_GET['departments_id'])) $where_str .= " AND dp.products_id = p.products_id";


Try changing it to:```
if ((isset($_GET['styles_id']) && $_GET['styles_id'] != '') or (isset($_GET['departments_id']) && $_GET['departments_id'] != '')) $where_str .= " AND dp.products_id = p.products_id"; 
2 Jan 2009, 11:19 PM
#18
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

Now its just hanging -no result bring given in the search now, but it did not effect the advanced search page.

Thanks for that try - but no joy.:no:

2 Jan 2009, 11:26 PM
#19
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

Re: Expanding search to work with my custom product-type

It did finally return a result...but hung for a long time.

2 Jan 2009, 11:33 PM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Expanding search to work with my custom product-type

Okay. While this is more of a bandage than a real "fix" (since your bug is in your header_php.php edits), you could try editing your /includes/templates/YOUR_TEMPLATE/sideboxes/tpl_search_header.php as follows. Find this line:

  $content .= zen_draw_hidden_field('search_in_description', '1') . zen_hide_session_id();
```Add this below it:

$content .= zen_draw_hidden_field('departments_id', '');