Zen Cart Logo
Forums / Addon Sideboxes / product filter module addon

product filter module addon

Views: 81,446

Results 101 to 120 of 169
19 Sep 2010, 5:21 AM
#101
xzaqus avatar

xzaqus

New Zenner

Join Date:
Sep 2010
Posts:
10
Plugin Contributions:
0

product filter module addon

Finally, I got it to work. I tested with my dummy data and it worked. I will not be able to answer questions as I do not code. The code to header_php.php is
(my last post with code had errors)

<?php /** * header_php.php * *Zen Cart product filter module *Johnny Ye, Oct 2007 * update by Jan Cabicar, Apr 2009 * update by Xzaqus, Sept 2010 */ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); $error = false; $missing_one_input = false; if (isset($_GET['categories_id']) && !is_numeric($_GET['categories_id'])){ $error = true; $messageStack->add_session('filter', ERROR_AT_LEAST_ONE_INPUT); } else { $categories_id =''; } $available = 'yes'; $option_ids = array(); $option_values = array(); foreach($_GET as $key => $value){ if(substr_count($key,'options')>0) { $option_ids[sizeof($option_ids)] = str_replace('options_','',$key); $option_values[sizeof($option_values)] = $value; } } if (isset($_GET['categories_id'])) { $categories_id = $_GET['categories_id']; } if (isset($_GET['price_range'])) { $price_range = $_GET['price_range']; } if (isset($_GET['available'])) { $available = $_GET['available']; } if (isset($_GET['sort'])) { $sort = $_GET['sort']; } $price_check_error = false; if (zen_not_null($pfrom)) { if (!settype($pfrom, 'float')) { $error = true; $price_check_error = true; $messageStack->add_session('filter', ERROR_PRICE_FROM_MUST_BE_NUM); } } $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_QUANTITY' => PRODUCT_LIST_QUANTITY, 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE); asort($define_list); $column_list = array(); reset($define_list); while (list($column, $value) = each($define_list)) { if ($value) $column_list[] = $column; } $select_column_list = ''; for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { if (($column_list[$col] == 'PRODUCT_LIST_NAME') || ($column_list[$col] == 'PRODUCT_LIST_PRICE')) { continue; } if (zen_not_null($select_column_list)) { $select_column_list .= ', '; } switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $select_column_list .= 'p.products_model'; break; case 'PRODUCT_LIST_MANUFACTURER': $select_column_list .= 'm.manufacturers_name'; break; case 'PRODUCT_LIST_QUANTITY': $select_column_list .= 'p.products_quantity'; break; case 'PRODUCT_LIST_IMAGE': $select_column_list .= 'p.products_image'; break; case 'PRODUCT_LIST_WEIGHT': $select_column_list .= 'p.products_weight'; break; } } // always add quantity regardless of whether or not it is in the listing for add to cart buttons if (PRODUCT_LIST_QUANTITY < 1) { if (empty($select_column_list)) { $select_column_list .= ' p.products_quantity '; } else { $select_column_list .= ', p.products_quantity '; } } if (zen_not_null($select_column_list)) { $select_column_list .= ', '; } // Notifier Point $select_str = "SELECT DISTINCT " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_price_sorter, p.products_qty_box_status "; $from_str = " FROM " . TABLE_PRODUCTS ." p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . znc_categories ." cat , " . TABLE_PRODUCTS_OPTIONS . " po , " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov "; $order_str=''; $listing_sql = $select_str . $from_str . $where_str . $order_str; $listing_sql = "select DISTINCT "; $listing_sql .= "p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, p.products_price_sorter, p.products_qty_box_status "; $where_str = " WHERE (p.products_status = 1 "; $enable_attribute_filter = false ; if(sizeof($option_ids)>0) { for($i=0;$i<sizeof($option_ids);$i++) { if(!(empty($option_values[$i]))) { $where_str .= " AND ((pa.products_id In (SELECT pa.products_id FROM znc_products_attributes pa WHERE ("; $where_str .= " pa.options_id = ".$option_ids[$i]; $where_str .= " AND pa.options_values_id = ".$option_values[$i]; $where_str .= " )))) "; $enable_attribute_filter = true; } } } if($enable_attribute_filter){ $where_str .= " AND p.products_id = pa.products_id "; } $enable_price_filter = true; switch($price_range){ case 0: $pfrom = MIN_PRICE; $pto = MAX_PRICE; break; case 1: $pfrom = PRANGE1_MIN; $pto = PRANGE1_MAX; break; case 2: $pfrom = PRANGE2_MIN; $pto = PRANGE2_MAX; break; case 3: $pfrom = PRANGE3_MIN; $pto = PRANGE3_MAX; break; case 4: $pfrom = PRANGE4_MIN; $pto = PRANGE4_MAX; break; case 5: $pfrom = PRANGE5_MIN; $pto = PRANGE5_MAX; break; } if(SHOW_SORT){ switch($sort){ case 0: $order_str = " order by p.products_date_added DESC, p.products_date_available DESC, products_price ASC "; break; case 1: $order_str = " order by p.products_date_added ASC, p.products_date_available ASC, products_price ASC "; break; case 2: $order_str = " order by p.products_price ASC, p.products_date_added DESC, p.products_date_available DESC "; break; case 3: $order_str = " order by products_price DESC, p.products_date_added DESC, p.products_date_available DESC "; break; $order_str = " order by p.products_date_added DESC, p.products_date_available DESC, products_price ASC "; } } if($categories_id !=''){ $where_str .=" AND ( p2c.categories_id = ".$categories_id; $where_str .=" OR cat.parent_id = ".$categories_id; $where_str .=" ) "; } if($enable_price_filter){ $where_str .= " AND p.products_price >= ".$pfrom; $where_str .= " AND p.products_price <= ".$pto; } /* $enable_attribute_filter = true ; if(sizeof($option_ids)>0){ for($i=0;$i<sizeof($option_ids);$i++){ if(!(empty($option_values[$i]))) { $where_str .= " AND pa.options_id = ".$option_ids[$i]; $where_str .= " AND pa.options_values_id = ".$option_values[$i]; } } } if($enable_attribute_filter){ $where_str .= " AND p.products_id = pa.products_id "; } */ if($available=='yes'){ $where_str .= " AND p.products_quantity > 0 "; } $where_str .=" AND p.products_id = pd.products_id"; $where_str .=" AND cat.categories_id = p2c.categories_id"; $where_str .=" AND p.products_id = p2c.products_id) "; $listing_sql .= $from_str; $listing_sql .= $where_str; $listing_sql .= $order_str; $listing_sql //$breadcrumb->add('title'); // This should be last line of the script: ?>
23 Sep 2010, 2:51 PM
#102
jabbawest avatar

jabbawest

Zen Follower

Join Date:
Oct 2009
Location:
Texas
Posts:
197
Plugin Contributions:
0

Re: product filter module addon

xzaqus,
The first header_php.php edit worked like a charm!

The most recent one returned the following on my site.

1146 Table 'sterling_zencart.znc_categories' doesn't exist
in:
[select count(distinct p.products_id) as total FROM zen_products p, zen_products_description pd, zen_products_to_categories p2c, zen_products_attributes pa, znc_categories cat , zen_products_options po , zen_products_options_values pov WHERE (p.products_status = 1 AND p.products_price >= 100 AND p.products_price <= 299.99 AND p.products_quantity > 0 AND p.products_id = pd.products_id AND cat.categories_id = p2c.categories_id AND p.products_id = p2c.products_id) ]

This is awesome!

23 Sep 2010, 4:21 PM
#103
jabbawest avatar

jabbawest

Zen Follower

Join Date:
Oct 2009
Location:
Texas
Posts:
197
Plugin Contributions:
0

Re: product filter module addon

I've added 4 extra PRANGE_ values to the following in order to return a wider price range.
tpl_prodcut_filter.php
product_filter_defines.php
header_php.php

It returns price ranges flawlessly, even for products priced by attributes!
Excellent.

The only issue I need to work on is hiding the "Please Select" wording within the attribute dropdowns.

24 Sep 2010, 1:07 AM
#104
xzaqus avatar

xzaqus

New Zenner

Join Date:
Sep 2010
Posts:
10
Plugin Contributions:
0

Re: product filter module addon

jabbawest:

xzaqus,
The first header_php.php edit worked like a charm!

The most recent one returned the following on my site.

This is awesome!

The earlier one has problems. The latest works but you will need to change znc_ prefix to your tables.
I did not know how to make it general to all tables. So, I had znc (prefix for my tables). Replace znc with the prefix that your tables have. ou should be able to find that through myPhpAdmin

24 Sep 2010, 5:23 PM
#105
jabbawest avatar

jabbawest

Zen Follower

Join Date:
Oct 2009
Location:
Texas
Posts:
197
Plugin Contributions:
0

Re: product filter module addon

xzaqus:

The earlier one has problems. The latest works but you will need to change znc_ prefix to your tables.
I did not know how to make it general to all tables. So, I had znc (prefix for my tables). Replace znc with the prefix that your tables have. ou should be able to find that through myPhpAdmin
Using the new header_php.php with the correct table prefix now.

Go to my site and use the mod to search this range $500 - $700.
Only one item will be found.
Now click on All SLJ Jewelry and you'll see that there are 3 additional items within that price range but they are priced by attributes.
sigh

25 Sep 2010, 9:19 AM
#106
bonnit avatar

bonnit

Zen Follower

Join Date:
Jun 2009
Location:
Kent, UK
Posts:
350
Plugin Contributions:
0

Re: product filter module addon

hi, i just installed this on 1.3.8a and am very hapy with it, although i would like to remove the entry in the dropdown list that reads "items starting with"

is this possible? thanks

27 Sep 2010, 5:27 PM
#107
jjrmy1 avatar

jjrmy1

New Zenner

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

Re: product filter module addon

spazem:

make it only filter results based on what catorgry you have selected and are currently in. this takes the need for it.

any help would be appriciated.

I too would like to get rid of the category filter and have the attribute filters applied to just the currently selected category. If anyone has been able to do this then please advise.

Thanks in advance

28 Sep 2010, 12:48 AM
#108
jabbawest avatar

jabbawest

Zen Follower

Join Date:
Oct 2009
Location:
Texas
Posts:
197
Plugin Contributions:
0

Re: product filter module addon

jjrmy1:

I too would like to get rid of the category filter and have the attribute filters applied to just the currently selected category. If anyone has been able to do this then please advise.

Thanks in advance
The first part is easy.
includes/languages/english/extra_definitions/product_filter_defines.php
set to false the very first entry

define('SHOW_CATEGORIES',true);
define('SHOW_ATTRIBUTES',true);
define('SHOW_PRICE_RANGE',true);
define('SHOW_AVAILABLE',true);
define('SHOW_SORT',true);
```As for the second part, someone smarter than I will need to assist.
3 Oct 2010, 4:06 AM
#109
jjrmy1 avatar

jjrmy1

New Zenner

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

Re: product filter module addon

jabbawest:

The first part is easy.
includes/languages/english/extra_definitions/product_filter_defines.php
set to false the very first entry

define('SHOW_CATEGORIES',true);
define('SHOW_ATTRIBUTES',true);
define('SHOW_PRICE_RANGE',true);
define('SHOW_AVAILABLE',true);
define('SHOW_SORT',true);


I got he first part, thanks though.

Well... someone smarter??
8 Oct 2010, 2:29 AM
#110
xzaqus avatar

xzaqus

New Zenner

Join Date:
Sep 2010
Posts:
10
Plugin Contributions:
0

Re: product filter module addon

The code I posted allows you to select the category and other criterion.

13 Oct 2010, 4:44 PM
#111
jjrmy1 avatar

jjrmy1

New Zenner

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

Re: product filter module addon

That's the problem... I would like the category to be pre-selected and based on the category that the user is currently in. If the user is in a top level category, then it would filter based on all the products down the chain.

13 Oct 2010, 6:41 PM
#112
xzaqus avatar

xzaqus

New Zenner

Join Date:
Sep 2010
Posts:
10
Plugin Contributions:
0

Re: product filter module addon

I wish I could help. I am no programmer but I kow SQL. Using that i was able to fix the logic in the code earlier. But for you problem someone who knows php will have to help. Good luck!!

14 Oct 2010, 9:00 PM
#113
fontaholic avatar

fontaholic

Zen Follower

Join Date:
Jun 2008
Posts:
111
Plugin Contributions:
0

Re: product filter module addon

maybe i don't understand what this addon does, but i installed it (on my local setup) and i can't see the change any where... where is it supposed to show up (search results? a sidebox?) the readme file included in the download only had instructions of what to add to the english.php and maybe were incomplete?

i'm hoping it allows search results or product list to be filtered by cateogories. i don't use attributes, but i suppose price would be a nice thing to be able to filter on too...

is there something i'm supposed to turn on in the admin?

thanks.

18 Oct 2010, 12:39 PM
#114
jabbawest avatar

jabbawest

Zen Follower

Join Date:
Oct 2009
Location:
Texas
Posts:
197
Plugin Contributions:
0

Re: product filter module addon

fontaholic:

maybe i don't understand what this addon does, but i installed it (on my local setup) and i can't see the change any where... where is it supposed to show up (search results? a sidebox?) the readme file included in the download only had instructions of what to add to the english.php and maybe were incomplete?

i'm hoping it allows search results or product list to be filtered by cateogories. i don't use attributes, but i suppose price would be a nice thing to be able to filter on too...

is there something i'm supposed to turn on in the admin?

thanks.
it's a sidebox named product_filter.php and, if installed correctly, should have red text since it overrides the search sidebox you currently have.
You can see it in action on my site, although I've disabled a few of its options.

20 Oct 2010, 5:49 AM
#115
adam2020 avatar

adam2020

New Zenner

Join Date:
Nov 2009
Posts:
33
Plugin Contributions:
0

Re: product filter module addon

I have this addon working well locally with several attributes such as Size, Color etc.

Instead of showing the Attribute title at the top of the Attribute drop down lists my client wants to show Please Select.

Can someone please help and show me what I need to edit to make these changes.

20 Oct 2010, 11:51 AM
#116
aozhaver avatar

aozhaver

Zen Follower

Join Date:
Sep 2010
Posts:
121
Plugin Contributions:
0

Re: product filter module addon

Hi everyone!

What a buggy add on!

I got it to work fine, that is until I add some more price ranges with extra PRANGE statements.

I amended 3 files and added more PRANGE statements

My header_php.php was amended with:

$enable_price_filter = true;
switch($price_range){
case 0:
$pfrom = MIN_PRICE;
$pto = MAX_PRICE;
break;
case 1:
$pfrom = PRANGE1_MIN;
$pto = PRANGE1_MAX;
break;
case 2:
$pfrom = PRANGE2_MIN;
$pto = PRANGE2_MAX;
break;
case 3:
$pfrom = PRANGE3_MIN;
$pto = PRANGE3_MAX;
break;
case 4:
$pfrom = PRANGE4_MIN;
$pto = PRANGE4_MAX;
break;
case 5:
$pfrom = PRANGE5_MIN;
$pto = PRANGE5_MAX;
break;
$pfrom = PRANGE6_MIN;
$pto = PRANGE6_MAX;
break;

My product_filter_defines.php amended:

define('MIN_PRICE','0');
define('MAX_PRICE','1000000');

define('PRANGE1_WORD','Below 10');
define('PRANGE1_MIN',MIN_PRICE);
define('PRANGE1_MAX',9.99);

define('PRANGE2_WORD','10 -- 20');
define('PRANGE2_MIN',10.00);
define('PRANGE2_MAX',19.99);

define('PRANGE3_WORD','20 -- 30');
define('PRANGE3_MIN',20.00);
define('PRANGE3_MAX',29.99);

define('PRANGE4_WORD','30 -- 40');
define('PRANGE4_MIN',30.00);
define('PRANGE4_MAX',39.99);

define('PRANGE5_WORD','40 -- 50');
define('PRANGE5_MIN',40.00);
define('PRANGE5_MAX',49.99);

define('PRANGE6_WORD','Over 50');
define('PRANGE6_MIN',50.00);
define('PRANGE6_MAX',MAX_PRICE);

And finally my tpl_product_filter.php:

if(SHOW_PRICE_RANGE){
		$prices =  array (array("id"=> 0, "text" => PRODUCT_FILTER_TEXT_ALL_PRICE),
				array("id"=> 1, "text" => PRANGE1_WORD),
				array("id"=> 2, "text" => PRANGE2_WORD),
				array("id"=> 3, "text" => PRANGE3_WORD),
				array("id"=> 4, "text" => PRANGE4_WORD),
				array("id"=> 5, "text" => PRANGE5_WORD),
                                array("id"=> 6, "text" => PRANGE6_WORD));
		$content .= zen_draw_pull_down_menu('price_range', $prices, (isset($_GET['price_range']) ? $_GET['price_range'] : ''), '') . zen_hide_session_id();
	}

Whenever I search based on the original 5 PRANGE I have no issues its when I try the range specified by the new 6th PRANGE that I get this error:

1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND p.products_price <= AND p.products_quantity > 0 AND p.products_id = pd.pro' at line 1
in:
[select count(distinct p.products_id) as total FROM products p, products_description pd, products_to_categories p2c, products_attributes pa, categories cat , products_options po , products_options_values pov WHERE (p.products_status = 1 AND p.products_id = pa.products_id AND p2c.categories_id = 66 AND p.products_price >= AND p.products_price <= AND p.products_quantity > 0 AND p.products_id = pd.products_id AND p.products_id = p2c.products_id) ]

Also if you look at my page https://www.majesticsilver.co.uk/store
you will see that the drop down fields for the filter search are all different sizes and spill over to my center column.

So any Ideas how I can edit the PRONGE properly, what am I doing wrong, cant be an issue with the rest of the code because if I dont add extra PRANGE everything works great. Even with the new PRANGE the original 5 work fine! just the extra one makes an error.

And which file to edit to control the width of the drop down fields..

Kindly assist me on this :smile:

P.S. Anyone posting some examples of working code would be really nice- Cheers!

20 Oct 2010, 1:08 PM
#117
aozhaver avatar

aozhaver

Zen Follower

Join Date:
Sep 2010
Posts:
121
Plugin Contributions:
0

Re: product filter module addon

P.S. JABBAWEST

I just took a look at your amazing website so pretty! and what beautiful jewelry you have!

Myself im more into the silver/budget range.:P

I see on your website the filter choices dont include any price ranges. Did you simply give up on that due to the PRONGE issue? I thought you had it sorted... please let me know :bigups:

20 Oct 2010, 1:33 PM
#118
aozhaver avatar

aozhaver

Zen Follower

Join Date:
Sep 2010
Posts:
121
Plugin Contributions:
0

Re: product filter module addon

Update: I sorted out the form field spilling over to the center column issue. All it was a bit of CSS tinkering.

I found the ====forms==== section of my stylesheet and I made the following change/addition to this line

input, select, textarea{ font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#f42fdb; line-height:normal; width:80%;}

Also width:120px; worked the same for my page... so GREAT! :clap:

But what about the PRONGE issue, jabba? anyone?:dontgetit

20 Oct 2010, 8:07 PM
#119
aozhaver avatar

aozhaver

Zen Follower

Join Date:
Sep 2010
Posts:
121
Plugin Contributions:
0

Re: product filter module addon

Another thing...

Im trying to change the submit button....

I defined

define('BUTTON_IMAGE_PRODUCT_FILTER', 'button_search.gif');

In both

/includes/languages/english/button_names.php

AND

includes/languages/english/extra_definitions/template29011/product_filter_defines.php

but then I need to edit this code in :

includes/templates/template29011/sideboxes/tpl_product_filter.php

$content .= '<br /><input type="submit" value="' . BUTTON_IMAGE_PRODUCT_FILTER . '"  />';

Im no programmer :(

I tried putting a reference to the image but i see other templates use something like

<div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_LOGIN, BUTTON_LOGIN_ALT); ?></div>

I tried many combinations and nothing works how do I incorporate a Div Class into the $.content statement. or is there a better way to do it :lookaroun

Ahhh the life of a zenner aint an easy one :no:

20 Oct 2010, 9:03 PM
#120
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,771
Plugin Contributions:
9

Re: product filter module addon

Wouldn't it be simpler to save the new button_names.php to includes/languages/english/template29011/button_names.php?

That's what the override system is all about.:yes: