Very cool. Did you post instructions anywhere?
Printable View
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
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
2. modified the file my_template\includes\modules\pages\advanced_search\header_php.php to define the $sData fieldCode:<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>
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
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.Code:define('TEXT_SEARCH_IN_PATIENT', 'Search In Order for Patient Attribute');
define('PATIENT_FORMAT_STRING', 'patient');
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.
2. Added the new patient variable to the test if any search criteria was entered so I don't get the error message.Code:$_GET['keyword'] = trim($_GET['keyword']);
$_GET['patient'] = trim($_GET['patient']);
3. added variable to hold the contents of the new fiield on the page.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'])) ) {
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.
the else statement was added to use the original From_str if they don't search by patient.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');
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
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:$listing_sql = $select_str . $from_str . $where_str . $order_str;
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
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:
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
and these are the changes in the headersPHP 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>
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;
[...]
etc...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');
}
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....
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
Line 132 ishQuote:
if (isset($_GET['products_author'])) {
$products_author = $_GET['products_author'];
}
Line 189 ishQuote:
&& empty($products_author)
Quote:
case 'PRODUCTS_AUTHOR':
$select_column_list .= 'p.products_author';
break;
Line 236 ish
line 276 ishQuote:
LEFT JOIN " . TABLE_PRODUCTS_EXTRA_STUFF. " pu
ON pu.products_id= p2c.products_id
templates/YOUR TEMPLATE/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');
}
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
Cool fixed it.
pages/advanced_search_result/header_php
On this line you will have.
most people will have added there extra emptys ieQuote:
if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {
This is wrong you need to have it like this.Quote:
if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($products_author) && empty($products_publisher) && empty($products_isbn13) && empty($keywords)) {
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.
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?
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.