Forums / Templates, Stylesheets, Page Layout / Advanced Search - customized product fields?

Advanced Search - customized product fields?

Started by zvenson on 2 Jul 2009, 3:34 AM · Views: 17,571

Results 41 to 52 of 52
17 Jan 2011, 7:16 PM
#41
ksoup avatar

ksoup

Zen Follower

Join Date:
Jan 2004
Posts:
413
Plugin Contributions:
1

Advanced Search - customized product fields?

Very cool. Did you post instructions anywhere?

impalor:

Hy, indeed youhave customized advanced search.Can you share with us how this is done?
Thank you!:clap:

3 Mar 2011, 8:03 PM
#42
notset4life avatar

notset4life

Zen Follower

Join Date:
Sep 2004
Posts:
177
Plugin Contributions:
0

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

9 Mar 2011, 4:20 PM
#43
marnieg avatar

marnieg

New Zenner

Join Date:
Feb 2011
Posts:
4
Plugin Contributions:
0

Re: Advanced Search - customized product 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_default.php by adding a new fieldset
<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>
  1. modified the file my_template\includes\modules\pages\advanced_search\header_php.php to define the $sData field
  $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);
  1. modified the file my_template\includes\languages\english\advanced_search.php
define('TEXT_SEARCH_IN_PATIENT', 'Search In Order for Patient Attribute');
 define('PATIENT_FORMAT_STRING', 'patient');
  1. 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.
$_GET['keyword'] = trim($_GET['keyword']);

$_GET['patient'] = trim($_GET['patient']);
  1. Added the new patient variable to the test if any search criteria was entered so I don't get the error message.
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'])) ) {
  1. added variable to hold the contents of the new fiield on the page.
 if (isset($_GET['patient'])) {

    $patients = $_GET['patient'];

  }
  1. 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.
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.

  1. Same for the Where String since I have different tables to join.
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');
  1. 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

$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.

$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

9 Mar 2011, 4:25 PM
#44
marnieg avatar

marnieg

New Zenner

Join Date:
Feb 2011
Posts:
4
Plugin Contributions:
0

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.

http://rxnations.com/vetorders/index.php?main_page=advanced_search_result&keyword=keywords&categories_id=&patient=premier&search_in_patient=1&x=24&y=3

I don't understand what the x=24&y=3 means.:frusty:

11 Sep 2011, 5:40 PM
#45
stsung avatar

stsung

New Zenner

Join Date:
Aug 2011
Posts:
21
Plugin Contributions:
0

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

<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

if  [blabla] (isset($_GET['products_color']) && !is_string($_GET['products_typemtg'])) &&  [...]
 
 
} else {
  $products_color = '';

if (isset($_GET['products_color'])) {
    $products_color= $_GET['products_color'];
  }
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;
switch ($column_list[$col]) {
  [..]
  case 'PRODUCTS_COLOR':
    $select_column_list .= 'p.products_color';
    break; 
[...]
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...

the shop I'm working on now...
http://outcast.cz/

11 Sep 2011, 6:07 PM
#46
stsung avatar

stsung

New Zenner

Join Date:
Aug 2011
Posts:
21
Plugin Contributions:
0

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....

the shop I'm working on now...
http://outcast.cz/

25 Oct 2011, 1:48 PM
#47
klevans avatar

klevans

New Zenner

Join Date:
Jul 2011
Posts:
27
Plugin Contributions:
0

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.

https://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

$products_author = (isset($_GET['products_author']) ? zen_output_string($_GET['products_author']) : '');

pages/advanced_search_result/header_php

Line 27 ish

(isset($_GET['products_author']) && (empty($_GET['products_author']))) &&

Line 56 ish

if (isset($_GET['products_author'])) {
$products_author = $_GET['products_author'];
}

Line 132 ish

&& empty($products_author)

Line 189 ish

case 'PRODUCTS_AUTHOR':
$select_column_list .= 'p.products_author';
break;

Line 236 ish

LEFT JOIN " . TABLE_PRODUCTS_EXTRA_STUFF. " pu
ON pu.products_id= p2c.products_id

line 276 ish

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/

<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

25 Oct 2011, 3:48 PM
#48
klevans avatar

klevans

New Zenner

Join Date:
Jul 2011
Posts:
27
Plugin Contributions:
0

Re: Advanced Search - customized product fields?

Cool fixed it.

pages/advanced_search_result/header_php

On this line you will have.

if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {

most people will have added there extra emptys ie

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.

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.

26 Jan 2012, 10:38 PM
#49
stsung avatar

stsung

New Zenner

Join Date:
Aug 2011
Posts:
21
Plugin Contributions:
0

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?

the shop I'm working on now...
http://outcast.cz/

29 Jan 2013, 12:38 PM
#50
bb21 avatar

bb21

New Zenner

Join Date:
Jan 2013
Posts:
1
Plugin Contributions:
0

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.

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:

LEFT JOIN " . TABLE_PRODUCT_EXTRA_FIELDS . " pe
             ON pe.products_id= p2c.products_id

@All, appreciate your feedback as well. Thank you.

10 Feb 2013, 7:28 PM
#51
webweaverd avatar

webweaverd

New Zenner

Join Date:
Jan 2013
Posts:
7
Plugin Contributions:
0

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:

//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:

/*
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.

26 May 2014, 3:12 PM
#52
modweb avatar

modweb

New Zenner

Join Date:
May 2014
Location:
Sheffield
Posts:
1
Plugin Contributions:
0

Re: Advanced Search - customized product fields?

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:

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.