Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / How do I change the search feature to look through custom product-type fields?

How do I change the search feature to look through custom product-type fields?

Locked

Views: 979

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
11 May 2010, 1:30 AM
#1
ssmith_cp avatar

ssmith_cp

New Zenner

Join Date:
Apr 2010
Posts:
20
Plugin Contributions:
0

How do I change the search feature to look through custom product-type fields?

How do I change the search feature to look through custom product attributes?

For example: the music type custom product type included with ZC has an attribute "Recording Artist" and a value "System of a Down." If I type "System of a down" in the search bar on my homepage, this custom product won't show up.

I'd guess it is because the search feature needs to be modified to include these custom attributes. What files do I need to modify/overwrite to get the search to look through the custom attributes?

Thanks ZC crew!

11 May 2010, 1:50 AM
#2
ssmith_cp avatar

ssmith_cp

New Zenner

Join Date:
Apr 2010
Posts:
20
Plugin Contributions:
0

Re: How do I change the search feature to look through custom product-type fields?

My mistake, I can search for artist but I can not search for the "Record Company."

Thanks

20 May 2010, 4:02 PM
#3
ssmith_cp avatar

ssmith_cp

New Zenner

Join Date:
Apr 2010
Posts:
20
Plugin Contributions:
0

Re: How do I change the search feature to look through custom product-type fields?

Hey ZC crew.

There is a thread that answers my question I think: http://www.zen-cart.com/forum/showthread.php?p=517239

I'll post more details if I think it could help others when I figure it out for myself :cool:

20 May 2010, 6:28 PM
#4
ssmith_cp avatar

ssmith_cp

New Zenner

Join Date:
Apr 2010
Posts:
20
Plugin Contributions:
0

Re: How do I change the search feature to look through custom product-type fields?

Hey ZC crew,

The link to the post above does pretty much cover describe how to add custom search terms. Here is another explanation that may be helpful to some and probably redundant to most :D

I only had to edit one file: includes/modules/pages/advanced_search_result/header_php.php - this file generates a table of "search results."

Some other posts mention editing the includes/index_filters/default_filter.php. I am not sure what this file does at the moment and the search modification seemed to work without so I'm not going to worry about it.

When editing the header_php.php file, I echoed the search SQL query before it was executed. Here is the query when I searched for "123" (without quotes):

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, p.master_categories_id
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 '%test%' OR p.products_model LIKE '%test%' OR
m.manufacturers_name LIKE '%test%' OR (mtpd.metatags_keywords LIKE '%test%' AND
mtpd.metatags_keywords !='') OR (mtpd.metatags_description LIKE '%test%' AND
mtpd.metatags_description !='') OR pd.products_description LIKE '%test%') and
(pd.products_name LIKE '%123%' OR p.products_model LIKE '%123%' OR
m.manufacturers_name LIKE '%123%' OR (mtpd.metatags_keywords LIKE
'%123%' AND mtpd.metatags_keywords !='') OR (mtpd.metatags_description LIKE
'%123%' AND mtpd.metatags_description !='') OR pd.products_description LIKE '%123%') ))
order by p.products_sort_order, pd.products_name

If I were to summarize this query in human-speak, I'd say it: generates a table where each row contains all available text-descriptions of a product then filters the results by looking for "like (similar)" text, in this case "123."

To incorporate custom attributes in the search, I just modified the query. Lets say, for example I have a table in by database called product_custom with the attributes (products_id, language_id, model_information). I would join this new table (I used the p2c (products_to_categories) table for the join values, i could have used another table but this one seemed convenient)

 'LEFT JOIN product_custom pc on pc.products_id = p2c.products_id and pc.language_id = ' . $_SESSION['languages_id'] . '..'. 

select the attribute I want to search

select pc.model_information ...

and compare the search term to the attribute, add

OR (pc.model_information  LIKE '%:keywords%')

After re-reading the other post, I pretty much said the same thing but I hope this is helpful for some one :D