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