-
Advanced Search - customized product fields?
Hey Community!
I am trying do expand the advanced search feature so that it is capable of searching custom fields and tables i added to the database. I created some extra database tables that hold extra information about products by using this how to:
http://www.zen-cart.com/forum/showthread.php?t=120523
now i have - let`s say - one field called "class_of_absorbtion" in a table called "products_extra_stuff" and of course a products_id field in that same table so the extra information can be allocated easily to the product.
I figured out how to insert the field in the search tpl by editing:
/includes/templates/my_template/templates/tpl_advanced_search_default.php
i added this code to /tpl_advanced_search_default.php to generate a dropdown with the options from the database:
Quote:
<?php
$absorbtion_array = array(array('id' => '', 'text' => TEXT_NONE));
$abso = $db->Execute("select id, absorbtionclass from " . TABLE_ABSO . " order by id");
while (!$abso->EOF) {
$absorbtion_array[] = array('id' => $abso->fields['absorbtionclass'],
'text' => $abso->fields['absorbtionclass']);
$abso->MoveNext();
}
?>
and this where the form and the dropdown is created
Quote:
<fieldset>
<legend>Class of absorbtion</legend>
<?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_pull_down_menu('class_of_absorbtion', $absorbtion_array, $pInfo->class_of_absorbtion); ?>
<br class="clearBoth" />
</fieldset>
now i modified the
/include/modules/pages/advanced_search/header_php.php and added this code so the value of the input is processed in the search:
Quote:
$sData['class_of_absorbtion'] = (isset($_GET['class_of_absorbtion']) ? zen_output_string($_GET['class_of_absorbtion']) : '');
next step would be to modify the
/include/modules/pages/advanced_search_results/header_php.php
this is where the actual search is done, right?
Now i`m stuck :wacko: on how to edit the search query because i don`t know where to tell zen cart that it should also pick results where the "class_of_absorbtion" value from the products_extra_stuff table concurs in the value of the search query.
Any suggestion and hints would be highly appreciated!
Thank you very much!
-
Re: Advanced Search - customized product fields
well somehow i figured it out but get a strange error...
the search can be expanded to custom tables by adding this to your
/include/modules/pages/advanced_search_results/header_php.php
- assuming you have a field called extras_flammability_test
Quote:
if (isset($_GET['extras_flammability_test'])) {
$extras_flammability_test = $_GET['extras_flammability_test'];
}
then in the $define_list = array
i added something like
Quote:
'PRODUCT_EXTRAS_FLAMMABILITY_TEST' => PRODUCT_EXTRAS_FLAMMABILITY_TEST,
in the query i added
Quote:
LEFT JOIN " . TABLE_PRODUCTS_EXTRA_STUFF. " pu
ON pu.products_id= p2c.products_id
and did some other minor changes to the file. The search performs and gets the products where the criteria are matching, but somehow on every result i get there are 4 buttons to add the product to the shopping cart - i m looking at it for quite a time now but cannot find out what went wrong - has anyone a hint or point my stupid face to it so i can find the problem? thank you -
the advanced search can be found here
(the page is under developement right now and there are only test products included but for testing purposes it should be okay)
thanks for help!
-
Re: Advanced Search - customized product fields
okay found the problem - often it just helps to write it down and ask in the forums and then give the answer to it myself :D
if anyone is interested in the solution let me know
-
Re: Advanced Search - customized product fields
It is always helpful if you post the solution to any problem, even if you do work it out for yourself, so that others can be helped by your discoveries ... :smile:
-
Re: Advanced Search - customized product fields?
yeah - that`s what i want to do but ran into antother problem :frusty:
i want to select a value "class_of_absorbtion" which can be in three different tables (for each product). This value can be in one, two or three or neither of the tables. I have and sql statement like this:
Quote:
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 p.products_id = pu.products_id AND p.products_id = pac.products_id AND p.products_id = puc.products_id AND p.products_id = pic.products_id AND p2c.categories_id = c.categories_id AND (pac.class_of_absorbtion OR puc.class_of_absorbtion_second OR pic.class_of_absorbtion_third) ='B'
so there are three tables of class_of_absorbtion. Im confused about the OR and AND statement - my code doesn`t work so maybe i have again something wrong in my php or even in my logic.
If anyone could have a quick look at this would be very nice!
thank you!
-
Re: Advanced Search - customized product fields?
no one helping? what a bummer....:cry:
-
Re: Advanced Search - customized product fields?
Hi!
I`m really stuck over here so if anyone could help me that would be sooooooooo nice...:clap:
I'm trying to explain my problem again:
I have 3 Tables called:
products_acoustics
products_acoustics_second
products_acoustics_third
each table contains a field products_id and a field for the acoustics information which can be values from A to E.
the three fields for the acoustics information are called
class_of_absorbtion (for table products_acoustics)
class_of_absorbtion_second (for table products_acoustics_second)
class_of_absorbtion_third (for table products_acoustics_third)
so i think i need to "left join" these tables together so i can get the coresponding product with just one "where" clause, right?
I tried the following (from clause)
Quote:
$from_str = "FROM (" . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_MANUFACTURERS . " m
USING(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c )
LEFT JOIN " . TABLE_PRODUCTS_EXTRA_STUFF. " pu
ON pu.products_id= p2c.products_id
LEFT JOIN " . TABLE_PRODUCTS_ACOUSTICS. " pac
ON pac.products_id = p2c.products_id
LEFT JOIN " . TABLE_PRODUCTS_ACOUSTICS_SECOND. " puc
ON pac.products_id = puc.products_id
LEFT JOIN " . TABLE_PRODUCTS_ACOUSTICS_THIRD. " pic
ON pac.products_id = pic.products_id
LEFT JOIN " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd
ON mtpd.products_id= p2c.products_id
AND mtpd.language_id = :languagesID";
$from_str = $db->bindVars($from_str, ':languagesID', $_SESSION['languages_id'], 'integer');
and here the where clause
Quote:
if (isset($_GET['class_of_absorbtion']) && zen_not_null($_GET['class_of_absorbtion'])) {
$where_str .= " AND (pac.class_of_absorbtion
OR puc.class_of_absorbtion_second
OR pic.class_of_absorbtion_third) = :absoID";
$where_str = $db->bindVars($where_str, ':absoID', $_GET['class_of_absorbtion'], 'string');
}
I know i must have gotten something wrong, because still only the first table "class_of_absorbtion" and the field "class_of_absorbtion" is searched. If anyone could help me a little on this, would be sooo nice. Hope anyone does. Thank you!
-
Re: Advanced Search - customized product fields?
well now i solved it - was just a tiny little thing, but if no one helps these things are sometimes hard to find :blink:
here`s the code for the correct where clause
Code:
$where_str .= " AND (pac.class_of_absorbtion=:absoID
OR puc.class_of_absorbtion_second=:absoID
OR pic.class_of_absorbtion_third=:absoID)";
-
Re: Advanced Search - customized product fields?
Thanks for posting the update to the coding syntax error ... :smile:
-
Re: Advanced Search - customized product fields?
Hi Ajeh and Zvenson,
I'm having some similar problem with advanced search.
I've added a field called "products_author" in "products" table, and now I'm trying to edit the advanced search adding the research also in this new field.
Until now I have no result, I've looked for tutorials or hints on the web, but I can't find... can u give me some help, please?
Thank u very much,
Marco
-
Re: Advanced Search - customized product fields?
sure - what did you do til now?
The main two files to edit are theses two
/include/modules/pages/advanced_search_results/header_php.php
/include/modules/pages/advanced_search/header_php.php
and of course the template for the search site...
i think in this thread there is all the information you need, but not nicely structured - so if you post your changes to the 2 files above i`ll have a look at it!
-
Re: Advanced Search - customized product fields?
Hi Zvenson,
Thanks for the quick answer.
Actually I'm stucked, I understand that the answer I was looking for is in this thread but I can't extract it (as you said, you write during the process, so is not linear). Consider also that usually I work with xhtml, css and wordpress, so I'm not good in php.
Your case is different from mine because you have to search in new tables with new fields, while in my case I've to search in a new field (products_author) of an existing table (products).
It's not yet useful sending u my code because after some wrong attempts I bring back the code to the original.
If you have the time and the patience to show me how to procede, I'll be very grateful.
-
Re: Advanced Search - customized product fields?
Quote:
I can't extract it (as you said, you write during the process, so is not linear).
- sorry for that - but unfortunately this forum only allows edits 7 minutes after posting :) - and it`s not a tutorial ...
Quote:
while in my case I've to search in a new field (products_author) of an existing table (products).
Is this just a simple text input field where you type in some name and it looks this up in the database?
First you have to add a field to the advanced search form. Edit:
/includes/templates/YOUR-TEMPLATE/templates/tpl_advanced_search_default.php file
and add something like this:
Code:
<div class="centeredContent"><?php echo zen_draw_input_field('YOUR_NEW_FIELD', $sData['your_new_field'], 'onfocus="RemoveFormatString(this, \'' . KEYWORD_FORMAT_STRING . '\')"'); ?>
where you want the new field to appear in the search form.
Then edit the
/include/modules/pages/advanced_search/header_php.php
to "GET" the data from the field by adding something like this:
Code:
$your_new_field = (isset($_GET['your_new_field']) ? zen_output_string($_GET['your_new_field']) : '');
now you just (okay, this is the tricky part) need to tell zen-cart to search the new data when something is submitted:
edit:
/include/modules/pages/advanced_search_results/header_php.php
Code:
(look for similar looking lines to paste this somewhere in between)
(isset($_GET['your_new_field']) && !is_string($_GET['your_new_field'])) &&
(same thing here: look for similar lines and just paste:
if (isset($_GET['your_new_field'])) {
$your_new_field = $_GET['your_new_field'];
}
(now search for "if (empty($dfrom)" and add somewhere between the &&empty something like this:)
&& empty($your_new_field)
(search for similar and past:)
case 'YOUR_NEW_FIELD':
$select_column_list .= 'p.your_fieldname_in_db';
break;
(search for similar lines and paste:)
if (isset($_GET['your_new_field']) && zen_not_null($_GET['your_new_field'])) {
$where_str .= " AND p.your_new_fielname_inDB = :yourfieldnameID";
$where_str = $db->bindVars($where_str, ':yourfieldnameID', $_GET['your_field_name'], 'string');
}
of course you have to change your_field_name to the variable you want to search and change your_new_fildname_inDB as well.
well this should be it - but i`m totally not sure - im the trial and error kind as well :) just try it and tell me when you succeed - hope it helps somehow...
-
Re: Advanced Search - customized product fields?
Thanks for the detailed answer!
I've done the process but it doesn't work yet...
/tpl_advanced_search_default.php file
1) Ok, I've added:
Code:
<div class="centeredContent"><?php echo zen_draw_input_field('PRODUCTS_AUTHOR', $sData['products_author'], 'onfocus="RemoveFormatString(this, \'' . KEYWORD_FORMAT_STRING . '\')"'); ?>
/include/modules/pages/advanced_search/header_php.php
2) Ok, I've added:
Code:
$sData['products_author'] = (isset($_GET['products_author']) ? zen_output_string($_GET['products_author']) : '');
/include/modules/pages/advanced_search_results/header_php.php
3) added:
Code:
(isset($_GET['products_author']) && !is_string($_GET['products_author'])) &&
4) added
Code:
if (isset($_GET['products_author'])) {
$your_new_field = $_GET['products_author'];
}
5) added
Code:
&& empty($products_author)
6) added
Code:
case 'PRODUCT_LIST_AUTHOR':
$select_column_list .= 'p.products_author';
break;
7) added, but I'm not sure about the ID part...
Code:
if (isset($_GET['products_author']) && zen_not_null($_GET['products_author'])) {
$where_str .= " AND p.products_author = :productsauthorID";
$where_str = $db->bindVars($where_str, ':productsauthorID', $_GET['products_author'], 'string');
}
Where I'm wrong?
-
Re: Advanced Search - customized product fields?
would be nice if you would tell us what happens when you start the search. This would make things much easier - maybe you can .provide a link
-
Re: Advanced Search - customized product fields?
Actually I'm testing locally, I haven't put it on the web yet. As soon as I put it I'll tell you.
Thanks,
Marco
-
Re: Advanced Search - customized product fields?
well - you can tell us what the error message is - or what happens when you search - "it doesn`t work" is in most cases not helpful at all :huh: - but it`s not aleways necessary to upload the site to the web...
:)
-
Re: Advanced Search - customized product fields?
Sorry Zvenson,
you are right. That's the situation in advanced search:
- if I leave the search field "keywords" blank and i fill only the new search field with an author name (it is supposed to search in my new field "author"), zen cart tell me "You must fill at least one field of research"
- if i fill "keywords" with a word and the new field with an author name, zencart gives me back only the products that match the first criteria
So, Zenky seems to ignore my second search field...
-
Re: Advanced Search - customized product fields?
Hi Marco!
Well, my first thought is, that there must be something wrong in this line where you put this:
&& empty($products_author)
this line should check if the author (or any other field) is empty and if so - you get the error message that nothing has been entered. Well - the reason for this could be, that the "$products_author" variable is empty - try inserting an
Code:
echo $products_author;
above the line where all the "&& emptys" are - then enter a search word in the products author field - do a search and look if the $produts_author is "echoed" (printed) somewhere on your screen. if it is not - then there must be something wrong bevor the actuall search is done...
Hope this again helps a little!
-
Re: Advanced Search - customized product fields?
I'm now following this thread for my own reasons! I have added a new table of product details (e) instead of adding to the product table. All of possible search fields are boolean - either 1 or 0 which is served by checkboxes on the search form.
So looking at your code suggestion above,
1) (isset($_GET['dwarf']) && !is_numeric($_GET['dwarf'])) &&
2) && empty($dwarf)
3) case 'dwarf':
$select_column_list .= 'e.dwarf';
4) if (isset($_GET['dwarf']) && zen_not_null($_GET['dwarf'])) {
$where_str .= " AND e.dwarf = :dwarf";
$where_str = $db->bindVars($where_str, ':dwarf', $_GET['dwarf'], 'string');
}
this doesn't work - and I know the field isn't a string as in number 4.
When I say it doesn't work - the search page just refreshed itself and never goes to the results page.
I'm pretty sure I've got the table added correctly to the select statement and even if I didn't, I'm not getting that far!
What might be wrong?
-
Re: Advanced Search - customized product fields?
Hi!
If the search page doesn`t go to the result page there must be something wrong in your
tpl_advanced_search_default.php file
or the
/include/modules/pages/advanced_search/header_php.php
you didn`t post your changes there, right?
and if your sure about the value of "dwarf" isn`t string than string is def. not the right variable type - but string should work as well (i think).
these are the possible variable types in php (as far as i know):
"array"
"double"
"integer"
"object"
"resource"
"string"
"unknown type"
-
Re: Advanced Search - customized product fields?
found another issue while testing my advanced search in different languages -
if you just want to search on of your "advanced search features" without a searchterm in the keywords section and you are using a different language than english, you have to replace a value in
/includes/languages/YOUR_Language/advanced_search.php
Code:
from
define('KEYWORD_FORMAT_STRING', 'Schlüsselworte');
to
define('KEYWORD_FORMAT_STRING', 'keywords');
otherwise the shop searches for the search term "Schlüsselworte" (for the german example) and that leads to wrong results
hope this helps someone.
br
zvenson
-
Re: Advanced Search - customized product fields?
It may not be appropriate for everyone, but I think it can be very simple. Do not add any extra text boxes for custom fields for example products_author.
1. includes/modules/pages/advanced_search_result/header_php.php
Find:
$where_str .= "(pd.products_name LIKE '%:keywords%'
After:
OR p.products_model
LIKE '%:keywords%'
Add:
OR p.products_author
LIKE '%:keywords%'
2. includes/languages/your_template/advanced_search.php
Replace:
define('HEADING_SEARCH_CRITERIA', 'Choose Your Search Terms');
with:
define('HEADING_SEARCH_CRITERIA', 'Title, Author, ISBN/ISSN');
-
Re: Advanced Search - customized product fields?
Hi rajoo.sharma !
Thanks for this - it is a different attempt but should work as well for some people. In my case I needed a little more advanced search where you can specify different values and a description the same time without using the "AND" thing in the description field..
And I needed to search extra database tables.
But your solution is good and simple and should be much easier to implement then what i came up with...:bigups:
cheers!
-
Re: Advanced Search - customized product fields?
Hi Guys,
I've been playing with my advanced search file to see if I could just search categories meta tags and descriptions. I was following this post as well as this one...
http://www.zen-cart.com/forum/showthread.php?t=114787
I've made some changes and have run into this output
1146 Table 'lim0908902331618.TABLE_META_TAGS_CATEGORIES_DESCRIPTION' doesn't exist
in:
[select count(distinct p.products_id) as total FROM (zen_products p LEFT JOIN zen_manufacturers m USING(manufacturers_id), zen_products_description pd, zen_categories c, zen_products_to_categories p2c ) LEFT JOIN zen_meta_tags_products_description mtpd ON mtpd.products_id= p2c.products_id AND mtpd.language_id = 1 LEFT JOIN TABLE_META_TAGS_CATEGORIES_DESCRIPTION mtcd ON mtcd.categories_id= c.categories_id AND mtcd.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 c.categories_id = mtcd.categories_id AND ((pd.products_name LIKE '%boy%' OR p.products_model LIKE '%boy%' OR m.manufacturers_name LIKE '%boy%' OR (mtpd.metatags_keywords LIKE '%boy%' AND mtpd.metatags_keywords !='') OR (mtcd.metatags_keywords LIKE '%boy%' AND mtcd.metatags_keywords !='') OR (mtpd.metatags_description LIKE '%boy%' AND mtpd.metatags_description !='') OR pd.products_description LIKE '%boy%') ))]
I'm not an SQL girl so I'm not sure how to resolve this issue although I did confirm that the table META_TAGS_CATEGORIES_DESCRIPTION is there. I must be referencing / linking it wrong in the query code. Any ideas?
-
Re: Advanced Search - customized product fields?
The constant for that table is:
TABLE_METATAGS_CATEGORIES_DESCRIPTION
-
Re: Advanced Search - customized product fields?
Thank you! By the way how did you know that? Is it located in myphpadmin somewhere?
-
Re: Advanced Search - customized product fields?
oh gosh, could I bother you again...
I'm getting this result now...
1054 Unknown column 'cd.categories_id' in 'where clause'
in:
[select count(distinct p.products_id) as total FROM (zen_products p LEFT JOIN zen_manufacturers m USING(manufacturers_id), zen_products_description pd, zen_categories c, zen_products_to_categories p2c ) LEFT JOIN zen_meta_tags_products_description mtpd ON mtpd.products_id= p2c.products_id AND mtpd.language_id = 1 LEFT JOIN zen_meta_tags_categories_description mtcd ON cd.categories_id= c.categories_id AND dc.language_id = 1 WHERE (c.categories_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 c.categories_id = cd.categories_id AND c.categories_id = dc.categories_id AND ((cd.metatags_description LIKE '%infant%' OR cd.metatags_keywords LIKE '%infant%' OR dc.categories_name LIKE '%infant%' OR cd.metatags_title LIKE '%infant%' OR (mtpd.metatags_keywords LIKE '%infant%' AND mtpd.metatags_keywords !='') OR (mtpd.metatags_description LIKE '%infant%' AND mtpd.metatags_description !='') OR pd.products_description LIKE '%infant%') ))]
-
Re: Advanced Search - customized product fields?
OK this goes out to svenson as he seems one of the few to have mastered how to customise the product fields..
The site deals with downloadable items so I'm attempting to have a field for filesize on the advanced search.
I have followed your instructions in post #13 to the letter but I'm just getting a blank result screen.. -> here's what I did:
1) added the following in /public_html/includes/templates/template_default/templates/tpl_advanced_search_default.php:
PHP Code:
$products_filesize_arr = array(array('id' => '', 'text' => TEXT_NONE));
$products_filesize = $db->Execute("SELECT products_filesize from " . TABLE_PRODUCTS_DESCRIPTION . " GROUP BY products_filesize ORDER BY products_filesize");
while (!$products_filesize->EOF) {
$products_filesize_arr[] = array('id' => $products_filesize->fields['products_filesize'],
'text' => $products_filesize->fields['products_filesize']);
$products_filesize->MoveNext();
}
2) then this in the same file:
Code:
<fieldset>
<legend>Filesize Heading</legend>
<?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_pull_down_menu('products_filesize', $products_filesize_arr, $pInfo->products_filesize); ?>
<br class="clearBoth" />
</fieldset>
3) then I added the following in /public_html/includes/modules/pages/advanced_search/header_php.php:
PHP Code:
$sData['products_filesize'] = (isset($_GET['products_filesize']) ? zen_output_string($_GET['products_filesize']) : '');
4) Now in /public_html/includes/modules/pages/advanced_search_result/header_php.php I added the following on around line 24:
PHP Code:
(isset($_GET['products_filesize']) && !is_string($_GET['products_filesize'])) &&
5) in the same file I added on line 60:
PHP Code:
if (isset($_GET['products_filesize'])) {
$products_filesize = $_GET['products_filesize'];
}
..this is just below:
PHP Code:
if (isset($_GET['keyword']) && $_GET['keyword'] != HEADER_SEARCH_DEFAULT_TEXT && $_GET['keyword'] != KEYWORD_FORMAT_STRING) {
$keywords = $_GET['keyword'];
}
6) then I included this:
PHP Code:
'PRODUCTS_FILESIZE' => PRODUCTS_FILESIZE);
on line 153 (near the other similar statements).
7) then I added this:
PHP Code:
case 'PRODUCTS_FILESIZE':
$select_column_list .= 'pd.products_filesize';
break;
.. around line 90 (below the others)
8) then I have this around line 302:
PHP Code:
if (isset($_GET['products_filesize']) && zen_not_null($_GET['products_filesize'])) {
$where_str .= " AND pd.products_filesize = :products_filesizeID";
$where_str = $db->bindVars($where_str, ':products_filesizeID', $_GET['products_filesize'], 'string');
}
..just below these statements:
PHP Code:
$where_str = $db->bindVars($where_str, ':categoriesID', $_GET['categories_id'], 'integer');
$where_str = $db->bindVars($where_str, ':languagesID', $_SESSION['languages_id'], 'integer');
}
}
Well that's the 8 steps I followed. Perhaps I have positioned something wrongly or there is a typo - I can't see it though. My suspicions are with step 8 of the process. The data stored is in varchar - don't know if this makes a difference to the variable types as you were contemplating in post #21 of this thread.
Anyway I hope that you can offer some guidance after your success >> it would be greatly appreciated.
_thanks
-
Re: Advanced Search - customized product fields?
Hi gforce!
thanks for the flowers and sorry for not answering earlier - just discovered your post - did you find a solution yet? Blank page sounds like php syntax error to me - haven't found the time to look into your code yet but will do it soon!
cheers!
-
Re: Advanced Search - customized product fields?
Quote:
Originally Posted by
rajoo.sharma
It may not be appropriate for everyone, but I think it can be very simple. Do not add any extra text boxes for custom fields for example products_author.
1. includes/modules/pages/advanced_search_result/header_php.php
Find:
$where_str .= "(pd.products_name LIKE '%:keywords%'
After:
OR p.products_model
LIKE '%:keywords%'
Add:
OR p.products_author
LIKE '%:keywords%'
2. includes/languages/your_template/advanced_search.php
Replace:
define('HEADING_SEARCH_CRITERIA', 'Choose Your Search Terms');
with:
define('HEADING_SEARCH_CRITERIA', 'Title, Author, ISBN/ISSN');
I have tried this, and other things, but can't get it to work. I added a field named "item_number" to my products table, and just want to make that searchable - I am running v1.3.8a
Thanks
-
Re: Advanced Search - customized product fields?
z3n,
Quote:
I have tried this, and other things, but can't get it to work.
I didn't get that, you meant you searched for a value stored in the field you added? and it didn't return that?
Since it is simple and should work without any problem, I'm not able to guess what went wrong.
Please zip all the files in which you made changes with a comment and attach them here, I'll check it at my end.
Rajeev Sharma
-
Re: Advanced Search - customized product fields?
I have managed to implement custom advanced search which search to and from (like price), I had to add some additions to th JS file also to stop the popup message causing an error....
My problem is I have alot of custom fields and I need to implement an if or case statement that will prevent all of my new fields showing up if they are not there(empty). I have customized the product listing page to do this, but the header_php (advanced search result page) file is set up differently.
in the product listing i have achieved it like this
case 'PRODUCT_LIST_D':
if ($listing->fields['products_D']=='0') {
//hide image column
$lc_text = '';
$lc_align = '';
$params= 'class="productListing-invis"';
} else {
$lc_text = '<div title="D (mm)">' . $listing->fields['products_D'] . '</div>';
$lc_align = 'right';
$params= 'class="productListing-heading"';
$zc_col_count_description++;}
break;
however it is stuctured completly differently in header_php
case 'PRODUCT_LIST_D':
$order_str .= "p.products_D";
break;
etc
Has anyone customized the advanced search result to do this? EG not show empty custom fields/columns.....
-
Re: Advanced Search - customized product fields?
What I think I need to do is use the php unset function to take out fields from the array if the result has no value....
Below i am trying to take out AP
- Its not working
$define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
'PRODUCT_LIST_THREAD_M' => PRODUCT_LIST_THREAD_M,
'PRODUCT_LIST_D' => PRODUCT_LIST_D,
'PRODUCT_LIST_L' => PRODUCT_LIST_L,
'PRODUCT_LIST_H' => PRODUCT_LIST_H,
'PRODUCT_LIST_AP' => PRODUCT_LIST_AP,
'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE);
if ($listing->fields['AP']=='0')
{
unset($define_list ['PRODUCT_LIST_AP']);
}
- I think I need to change $listing->fields to something but dont know what - I know it is $product_info->fields on product info pages etc but dont know on this one. If there is a better way then, please let me know the solution...
-
Re: Advanced Search - customized product fields?
Has anyone managed to get this to work?
I have added a UPC, ASIN, PID, SKU & Even a Vendor SKU product field to my Products Info Page using custom fields.
Can see it here
My customers can search and get exact match for UPC, ASIN, PID, SKU and other hidden fields that I am testing to further categorize product without creating categories.
Is this what you are trying to do?
-
Re: Advanced Search - customized product fields?
I dont know if your question was addressed at me but I still would like any ideas regarding my situation.
I have successfully customized advanced search
http://www.fastenerforce.co.uk/
however the results page runs from the product listing template - which should display css-column collapse - it does in the product listing but the advanced search list columns arent registering it and displaying empty columns which is clunky......
-
Re: Advanced Search - customized product fields?
Hi
I am also trying to amend the search function. I am working on a site that sells tyres. Tyres have certain characteristics that are used when searching for the tyres for your vehicle:
Width
Profile
Wheel Size
Load Index
Speed Rating
I have created a new table PRODUCTS_TYRES with products_id as the key and then products_width, products_profile, products_wheel_size, products_load_index, products_speed_rating as fields within the table.
I do not want to search on any of the traditional search variables as these are not required.
I believe that I have created the correct result array and that the array is sorted alphabetically. I have created the SELECT, FROM and WHERE strings.
However when I try the page, using just the width search term (I will add the code for the other fields once I know that is working correctly) I get an error message that "At least one of the fields in the search form must be entered".
Here is the page:
http://www.tyrexchange.co.uk/index.p...dvanced_search
Has anybody got any ideas that may help me as I have been scratching my head on this for two days now?
Thanks in advance
Mike
-
Re: Advanced Search - customized product fields?
I had this problem, cant remember but think you add your fields at the top eg.
(isset($_GET['s_dfrom']) && !is_numeric($_GET['s_dfrom'])) &&
(isset($_GET['s_dto']) && !is_numeric($_GET['s_dto']))&&
think you add your code at the top. You could delete the message stack or add your own custom ones eg...
if (($L_D_check_error == false) && is_numeric($L_dto) && is_numeric($L_dfrom)) {
if ($L_dfrom >= $L_dto) {
$error = true;
$messageStack->add_session('search', " L (mm) From value should be less than L (mm) To value");
}
}
-
Re: Advanced Search - customized product fields?
help!:wacko:
I've followed zvenson code from earlier in this thread but it doesn't seem to be working for me.
The biggest issue seems to be the extra table I have isn't be included in the sql query (I'm echoing it to the page for testing).
I have an extra table with a product_id which matches products table id's, each record has an extra field called p_added_make which is what I'm searching against.
USING(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c )
LEFT JOIN " . TABLE_ADDED_FIELDS. " pu
ON pu.products_id= p2c.products_id
LEFT JOIN " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd
ON mtpd.products_id= p2c.products_id
AND mtpd.language_id = :languagesID";
on the site the extra table is not appearing in the query.
USING(manufacturers_id), z_table_products_description pd, z_table_categories c, z_table_products_to_categories p2c ) LEFT JOIN z_table_meta_tags_products_description mtpd ON mtpd.products_id= p2c.products_id AND mtpd.language_id = 1
the table prefix is correct (TABLE_ADDED_FIELDS) but am I missing something else.
Should there be something in the SELECT DISTINCT part of the query?
-
Re: Advanced Search - customized product fields?
Quote:
Originally Posted by
Bikeforce
I dont know if your question was addressed at me but I still would like any ideas regarding my situation.
I have successfully customized advanced search
http://www.fastenerforce.co.uk/
however the results page runs from the product listing template - which should display css-column collapse - it does in the product listing but the advanced search list columns arent registering it and displaying empty columns which is clunky......
Hy, indeed youhave customized advanced search.Can you share with us how this is done?
Thank you!:clap:
-
Re: Advanced Search - customized product fields?
Very cool. Did you post instructions anywhere?
Quote:
Originally Posted by
impalor
Hy, indeed youhave customized advanced search.Can you share with us how this is done?
Thank you!:clap:
-
Re: Advanced Search - customized product fields?
How difficult would it be to to change MANUFACTURERS to RECORD COMPANIES?
I don't use manufacturers, I use Distributors - which is actually an english renaming of Record Companies field. So in effect,
I would change the language to "Limit To Distributors" but would need the record companies in the drop down.
(I have to do it this way because I have music products, and that is the layout in the add product entries)
Thanks in advance.
Vin
-
Re: Advanced Search - customized product attribute fields
Zen Cart 1.3.8a
Site was updated from 1.3.7 back in 2008
I am not sure of any add-ins as I am the new webmaster for this site. I'm also new to Zen Cart. My background in php and mysql so learning a new tool is not very difficult.
My client has requested a change to the Advanced Search to allow customer to search past orders on a product attribute. I have followed the recommendations of this post and have modified 4 files to implement this change. I think I just need a few more tweaks, but am stuck.
Here are the changes I have made:
1. modified the file
\my_template\includes\templates\my_template\templates\tpl_advanced_search_defaul t.php by adding a new fieldset
Code:
<fieldset>
<legend>OR Search Past Orders by Patient Name</legend>
<div class="centeredContent"><?php echo zen_draw_input_field('patient', $sData['patient'], 'onfocus="RemoveFormatString(this, \'' . PATIENT_FORMAT_STRING . '\')"'); ?> <?php echo zen_draw_checkbox_field('search_in_patient', '1', $sData['search_in_patient'], 'id="search-in-patient"'); ?><label class="checkboxLabel" for="search-in-patient"><?php echo TEXT_SEARCH_IN_PATIENT; ?></label></div>
<br class="clearBoth" />
</fieldset>
2. modified the file my_template\includes\modules\pages\advanced_search\header_php.php to define the $sData field
Code:
$sData['patient'] = (isset($_GET['patient']) ? zen_output_string($_GET['patient']) : zen_output_string(PATIENT_FORMAT_STRING));
$sData['search_in_patient'] = (isset($_GET['search_in_patient']) ? zen_output_string($_GET['search_in_patient']) : 1);
3. modified the file my_template\includes\languages\english\advanced_search.php
Code:
define('TEXT_SEARCH_IN_PATIENT', 'Search In Order for Patient Attribute');
define('PATIENT_FORMAT_STRING', 'patient');
4. modified the file my_template\includes\modules\pages\advanced_search_result\header_php.php to adjust the from and where clause code. I'm only allowing them to search either by product description OR by past order product attritbute 'Patient. So this was a big code change to this file. I'm sure I haven't done it correctly and not gettting any result.
I will break the code down into places that I modified as this page has many lines.
1. added get my variable like the keyword search does.
Code:
$_GET['keyword'] = trim($_GET['keyword']);
$_GET['patient'] = trim($_GET['patient']);
2. Added the new patient variable to the test if any search criteria was entered so I don't get the error message.
Code:
if ( (isset($_GET['keyword']) && (empty($_GET['keyword']) || $_GET['keyword']==HEADER_SEARCH_DEFAULT_TEXT || $_GET['keyword'] == KEYWORD_FORMAT_STRING ) ) &&
(isset($_GET['dfrom']) && (empty($_GET['dfrom']) || ($_GET['dfrom'] == DOB_FORMAT_STRING))) &&
(isset($_GET['dto']) && (empty($_GET['dto']) || ($_GET['dto'] == DOB_FORMAT_STRING))) &&
(isset($_GET['pfrom']) && !is_numeric($_GET['pfrom'])) &&
(isset($_GET['pto']) && !is_numeric($_GET['pto'])) &&
(isset($_GET['patient]) && (empty($_GET['patient'])) ) {
3. added variable to hold the contents of the new fiield on the page.
Code:
if (isset($_GET['patient'])) {
$patients = $_GET['patient'];
}
4. Since my search needs to be on the orders_products_attributes table and having to link other tables to search by customer, I had to change the entire "from str" . So I'm creating my own From string.
Code:
if (isset($_GET['patient'])) {
$from_str = "FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " pat,
" . TABLE_ORDERS_PRODUCTS . " op,
" . TABLE_ORDERS . " o,
" . TABLE_PRODUCTS . " p,
" . TABLE_PRODUCTS_DESCRIPTION . " pd";
}
else
{
$from_str = "FROM (" . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_MANUFACTURERS . " m
USING(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c )
LEFT JOIN " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd
ON mtpd.products_id= p2c.products_id
AND mtpd.language_id = :languagesID";
}
$from_str = $db->bindVars($from_str, ':languagesID', $_SESSION['languages_id'], 'integer');
the else statement was added to use the original From_str if they don't search by patient.
5. Same for the Where String since I have different tables to join.
Code:
if (isset($_GET['patient'])) {
$where_str = " WHERE (p.products_status = 1
AND p.products_id = pd.products_id
AND pat.orders_id = o.orders_id
AND op.orders_id = o.orders_id
AND op.products_id = p.products_id
AND pat.products_options = 'Patient'
AND pd.language_id = :languagesID
AND o.customers_id = :customerID
AND pat.products_options_values LIKE '%:patient%'";
$where_str = $db->bindVars($where_str, ':customerID', $_SESSION['customers_id'], 'integer');
}
else
{
$where_str = " WHERE (p.products_status = 1
AND p.products_id = pd.products_id
AND pd.language_id = :languagesID
AND p.products_id = p2c.products_id
AND p2c.categories_id = c.categories_id ";
}
$where_str = $db->bindVars($where_str, ':languagesID', $_SESSION['languages_id'], 'integer');
6. I didn't change the Select or Sort order string because I want the same fields selected for display and assume it will continue sorting by product name. That is why I joined the Products_Description table.
So my question is now that I have my SQL statement constructed with the from, where and sort which I assume happens in this line
Code:
$listing_sql = $select_str . $from_str . $where_str . $order_str;
how does it call the database and execute the search. Here is the remaining code in this page, but not sure what it is calling.
Code:
$zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING', $listing_sql);
$breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_ADVANCED_SEARCH));
$breadcrumb->add(NAVBAR_TITLE_2);
$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')));
}
// This should be last line of the script:
$zco_notifier->notify('NOTIFY_HEADER_END_ADVANCED_SEARCH_RESULTS', $keywords);
As I said I'm a newbie to Zen Cart. It is hard to follow at times, but I was able to figure out where to change the code, just need a little push to get it working.
Thanks,
Marnie
-
Re: Advanced Search - customized product fields?
ANother thing to add to my post above. I noticed when I click on search the url address that it builds still contains the other two search fields.
I don't understand what the x=24&y=3 means.:frusty:
-
Re: Advanced Search - customized product fields?
hello again,
I need help. I managed to create a search box that searches the right column (extra fields in products table). It works
but ...
if I have two search boxes like this it is capable to process the search of one...and not the other (it says that there are no products matching the criteria...but in reality there are...) or BOTH at the same time (that works no problem).
if I add one more it either searches one or all the columns at the same time. what should I do to make it search by field 1, 2 or three or any other combination of the three?
actually, if you just click in the search box and leave it black it will do the search correctly. what did I miss? it seems like that it takes either PRODUCTS_COLOR_FORMAT_STRING or any other xx_format_string as the search value. (if you click on the advanced search in my shop..I left there only one search box - by color). but the remove string should work??
this is my template file...or at least the relevant part
PHP Code:
<fieldset>
<legend><?php echo HEADING_SEARCH_CRITERIA; ?></legend>
<div class="forward"><?php echo '<a href="javascript:popupWindow(\'' . zen_href_link(FILENAME_POPUP_SEARCH_HELP) . '\')">' . TEXT_SEARCH_HELP_LINK . '</a>'; ?></div>
<br class="clearBoth" />
<div class="centeredContent"><?php echo zen_draw_input_field('keyword', $sData['keyword'], 'onfocus="RemoveFormatString(this, \'' . KEYWORD_FORMAT_STRING . '\')"'); ?> <?php echo zen_draw_checkbox_field('search_in_description', '1', $sData['search_in_description'], 'id="search-in-description"'); ?><label class="checkboxLabel" for="search-in-description"><?php echo TEXT_SEARCH_IN_DESCRIPTION; ?></label></div>
<br class="clearBoth" />
</fieldset>
<!-- search by color -->
<fieldset class="floatingBox back">
<legend>Vyhledávání podle barvy</legend>
<br class="clearBoth" />
<?php echo zen_draw_input_field('products_color', $sData['products_color'], 'onfocus="RemoveFormatString(this,
\'' . PRODUCTS_COLOR_FORMAT_STRING . '\')"'); ?>
</fieldset>
<!-- konec search by color -->
</P>
and these are the changes in the headers
PHP Code:
if [blabla] (isset($_GET['products_color']) && !is_string($_GET['products_typemtg'])) && [...]
} else {
$products_color = '';
if (isset($_GET['products_color'])) {
$products_color= $_GET['products_color'];
}
PHP Code:
if (empty($dfrom) && empty($products_edition) && empty($products_typemtg) && empty($products_rarity) && empty($products_color) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {
$error = true;
PHP Code:
switch ($column_list[$col]) {
[..]
case 'PRODUCTS_COLOR':
$select_column_list .= 'p.products_color';
break;
[...]
PHP Code:
if (isset($_GET['products_color']) && zen_not_null($_GET['products_color'])) {
$where_str .= " AND p.products_color = :products_colorID";
$where_str = $db->bindVars($where_str, ':products_colorID', $_GET['products_color'], 'string');
}
etc...
-
Re: Advanced Search - customized product fields?
it does not seem that I can edit the previous post.
my shop is located at outcast.cz
in the end I would need a search engine that uses checkboxes. so the customer could filter the products by color, rarity, type etc. but for the time being I'm trying to get this to work. It would work if not for removing the initial string from the box....
-
Re: Advanced Search - customized product fields?
Ok I got this working but the downside is only works with one extra search field not sure why working on this problem now on local server but the live server is running.
www.jazmin-books.co.uk
This is all linking to a extra table created products_extra_stuff.
pages/advanced_search/header_php
at the end add
Quote:
$products_author = (isset($_GET['products_author']) ? zen_output_string($_GET['products_author']) : '');
pages/advanced_search_result/header_php
Line 27 ish
Quote:
(isset($_GET['products_author']) && (empty($_GET['products_author']))) &&
Line 56 ish
Quote:
if (isset($_GET['products_author'])) {
$products_author = $_GET['products_author'];
}
Line 132 ish
Quote:
&& empty($products_author)
Line 189 ish
Quote:
case 'PRODUCTS_AUTHOR':
$select_column_list .= 'p.products_author';
break;
Line 236 ish
Quote:
LEFT JOIN " . TABLE_PRODUCTS_EXTRA_STUFF. " pu
ON pu.products_id= p2c.products_id
line 276 ish
Quote:
if (isset($_GET['products_author']) && zen_not_null($_GET['products_author'])) {
$where_str .= " AND products_author = : products_author";
$where_str = $db->bindVars($where_str, ': products_author', $_GET['products_author'], 'string');
}
templates/YOUR TEMPLATE/
Quote:
<fieldset>
<legend>Search by Author</legend>
<div class="centeredContent"><?php echo zen_draw_input_field('products_author', $sData['products_author'], 'onfocus="RemoveFormatString(this, \'' . KEYWORD_FORMAT_STRING . '\')"'); ?>
<br class="clearBoth" />
</fieldset>
Don`t for get to add your database table to the list of database.
hope this helps people out
p.s. this is working on a server with 562911 products
-
Re: Advanced Search - customized product fields?
Cool fixed it.
pages/advanced_search_result/header_php
On this line you will have.
Quote:
if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {
most people will have added there extra emptys ie
Quote:
if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($products_author) && empty($products_publisher) && empty($products_isbn13) && empty($keywords)) {
This is wrong you need to have it like this.
Quote:
if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {
} else if (empty($products_author) && empty($products_publisher) && empty($products_isbn13)){
Now you can have multiple search fields that can be empty.
Hope this helps you all.
-
Re: Advanced Search - customized product fields?
klevans: doing exactly what you did results in zencart telling me that at least on of the search conditions has to be filled in.
i don't know what to do. if I remove the keyword_format_string from the search box it does the search. but otherwise it will take the translated keyword_format_string as a value.
I have to be overlooking something somewhere...anyone had the same problem?
-
2 Attachment(s)
Re: Advanced Search - customized product fields
Hi Zvenson,
May I ask how did you resolve the following problem? Mine has 2 buttons on every product result.
Quote:
Originally Posted by
zvenson
The search performs and gets the products where the criteria are matching, but somehow on every result i get there are 4 buttons to add the product to the shopping cart
My custom advanced search changes are still on my Local PC so I won't be able to share you a link. But I am providing screenshots of the search result for your reference.
Attachment 11857
Attachment 11856
Zen Cart version: 1.5.1
Modified files (all changes I made came from this thread):
\includes\templates\template_default\templates\tpl_advanced_search_default.php
\includes\modules\pages\advanced_search\header_php.php
\includes\modules\pages\advanced_search_result\header_php.php
I am using 1 extra table so in the LEFT JOIN part, I only added this:
Code:
LEFT JOIN " . TABLE_PRODUCT_EXTRA_FIELDS . " pe
ON pe.products_id= p2c.products_id
@All, appreciate your feedback as well. Thank you.
-
Re: Advanced Search - customized product fields
I've just finished making my advanced search work with all sorts of custom fields and I thought this small piece of info may help someone who is having trouble with the empty keywords on search:
You dont need to check for an empty anything (there is even a comment stating the check can safely be removed), I started putting all sort of checks for empty against my various fields, but actually if you just remove all the checks and search on nothing it just returns all products... which I think is just fine. Obviously you will still need to apply format checks.
So there are two places you need to look for these checks:
There is a client side (js) check in includes/modules/pages/advanced_search/jscript_main.php:
Code:
//if ( ((keyword == '') || (keyword.length < 1)) && ((dfrom == '') || (dfrom == '<?php echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) ) {
// error_message = error_message + "* <?php// echo ERROR_AT_LEAST_ONE_INPUT; ?>\n";
// error_field = document.advanced_search.keyword;
// error_found = true;
//}
as you can see all commented out.
Then there is a server side check in includes/modules/pages/advanced_search_result/header_php.php:
Code:
/*
if ( (isset($_GET['keyword']) && (empty($_GET['keyword']) || $_GET['keyword']==HEADER_SEARCH_DEFAULT_TEXT || $_GET['keyword'] == KEYWORD_FORMAT_STRING ) ) &&
(isset($_GET['dfrom']) && (empty($_GET['dfrom']) || ($_GET['dfrom'] == DOB_FORMAT_STRING))) &&
(isset($_GET['dto']) && (empty($_GET['dto']) || ($_GET['dto'] == DOB_FORMAT_STRING))) &&
(isset($_GET['pfrom']) && !is_numeric($_GET['pfrom'])) &&
(isset($_GET['pto']) && !is_numeric($_GET['pto']))) {
$error = true;
$missing_one_input = true;
$messageStack->add_session('search', ERROR_AT_LEAST_ONE_INPUT);
} else {
*
*/
also need to comment out the close to that else statement;
Another thing that I found was it was quite easy to integrate the dynamic filter plugin with the advance search form - this plugin already allows you to search on any attributes you have. You will need to take out price and category options from here to avoid conflicts with the advanced search.
-
Re: Advanced Search - customized product fields
Quote:
Originally Posted by
bb21
Hi Zvenson,
May I ask how did you resolve the following problem? Mine has 2 buttons on every product result.
My custom advanced search changes are still on my Local PC so I won't be able to share you a link. But I am providing screenshots of the search result for your reference.
Attachment 11857
Attachment 11856
Zen Cart version: 1.5.1
Modified files (all changes I made came from this thread):
\includes\templates\template_default\templates\tpl_advanced_search_default.php
\includes\modules\pages\advanced_search\header_php.php
\includes\modules\pages\advanced_search_result\header_php.php
I am using 1 extra table so in the LEFT JOIN part, I only added this:
Code:
LEFT JOIN " . TABLE_PRODUCT_EXTRA_FIELDS . " pe
ON pe.products_id= p2c.products_id
@All, appreciate your feedback as well. Thank you.
Hi,
I have got the advanced search results working fine, all except I have 4 prices and cart showing on each product result, May I ask how did you resolve the problem of having 2 buttons on every product result.? I have looked through the threads but can not see any mention of a fix.
Using 1.5.1
Thank you in advance.