Also es gibt einen Attributfilter.
Wenn ich den aber nehme dann kommt eine Auswahl der Optionen wie Größe,Farbe etc.
Wenn ich aber dann was auswähle geschieht nichts.
// option filter join sql
$option_filter_join = '';
$option_filter_ids = array();
// collect non-empty option filters
foreach ($_GET as $key => $value)
if ((substr($key, 0, 9) == 'optfilter') && !empty($value))
$option_filter_ids[] = $value;
$option_filter_ids = implode(',', $option_filter_ids);
// build filter sql to use in product queries and dropdown calculation as additional join part
if (!empty($option_filter_ids)) {
$option_filter_join = 'join (select p.products_id
from '.TABLE_PRODUCTS.' p
join '.TABLE_PRODUCTS_ATTRIBUTES.' pa on pa.products_id = p.products_id
join '.TABLE_PRODUCTS_OPTIONS_VALUES.' pv on pv.products_options_values_id = pa.options_values_id
where pa.options_values_id in (' . $option_filter_ids . ')
and pv.language_id = '.(int) $_SESSION['languages_id'].'
group by 1
having count(p.products_id) = (select count(products_options_values_id)
from '.TABLE_PRODUCTS_OPTIONS_VALUES.'
where language_id = '.(int) $_SESSION['languages_id'].'
and products_options_values_id in (' . $option_filter_ids . '))) x on x.products_id = p.products_id';
}
//
##########################################################################
// options filter for dropdowns
// $excluded_options = '10'; // comma-separated list of excluded option ids
if (!empty($excluded_options))
$excluded_options_condition = 'and po.products_options_id not in (' . $excluded_options . ')';
// modify options filter join to connect to products_attributes instead of products
$option_filter_join = str_replace('x.products_id = p.products_id', 'x.products_id = pa.products_id', $option_filter_join);
// 1. get options and values for this catgory
$filter_sql = 'select po.products_options_id options_id,
po.products_options_name options_name,
pv.products_options_values_id options_values_id,
pv.products_options_values_name options_values_name,
count(pa.products_id) option_values_count
from '.TABLE_PRODUCTS_OPTIONS.' po
join '.TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS.' pv2po on pv2po.products_options_id = po.products_options_id
join '.TABLE_PRODUCTS_OPTIONS_VALUES.' pv on pv.products_options_values_id = pv2po.products_options_values_id
join '.TABLE_PRODUCTS_ATTRIBUTES.' pa on pa.options_id = po.products_options_id and
pa.options_values_id = pv.products_options_values_id
join '.TABLE_PRODUCTS_TO_CATEGORIES.' p2c on p2c.products_id = pa.products_id
join '.TABLE_PRODUCTS.' p on p.products_id = pa.products_id
'. $option_filter_join .'
where p2c.categories_id = ' . $current_category_id . '
and po.language_id = '.(int) $_SESSION['languages_id'].'
and pv.language_id = '.(int) $_SESSION['languages_id'].'
and p.products_status = 1
'. $excluded_options_condition .'
group by 1, 2, 3, 4
order by 1, 4';
// echo $filter_sql;
$filter_query = xtDBquery($filter_sql);
// 2. group result set in array
$option_id = 0;
while ($rec = xtc_db_fetch_array($filter_query, true)) {
// new option?
if ($option_id != $rec['options_id'])
{
$option_id = $rec['options_id'];
$filter[$option_id]['id'] = $rec['options_id'];
$filter[$option_id]['name'] = $rec['options_name'];
}
$option_values = array('id' => $rec['options_values_id'],
'name' => $rec['options_values_name'],
'count' => $rec['option_values_count']);
$filter[$option_id]['values'][] = $option_values;
}
// 3. collect url params
$url_params = $_GET;
// reset session
$url_params[xtc_session_name()] = xtc_session_id();
// remove empty params
foreach ($url_params as $key => $value)
if (empty($value)) unset($url_params[$key]);
// 4. build dropdowns
if (!empty($filter))
{
foreach ($filter as $optid => $option)
{
// init form
$dropdown = xtc_draw_form('filter'. $optid, FILENAME_DEFAULT, 'get');
// url params as hidden fields
$url_param_fields = '';
foreach ($url_params as $key => $value)
if ($key != 'optfilter'. $optid)
$url_param_fields .= xtc_draw_hidden_field($key, $value);
$dropdown .= $url_param_fields;
// init dropdown
$options = array (array ('text' => '-- ' . $option['name'] . ' --'));
foreach ($option['values'] as $key => $rec)
$options[] = array ('id' => $rec['id'], 'text' => $rec['name']);
$dropdown .= xtc_draw_pull_down_menu('optfilter'. $optid, $options, $_GET['optfilter'. $optid], 'style="float:left; width:150px; margin:5px;" onchange="this.form.submit()"');
$dropdown .= '</form>'."\n";
$option_dropdowns[] = $dropdown;
}
// add separator
$option_dropdowns[] = '<div style="clear: left;"></div>';
}
// ##########################################################################
// optional Product List Filter
if (PRODUCT_LIST_FILTER > 0) {
if (isset ($_GET['manufacturers_id'])) {
$filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name from ".TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_TO_CATEGORIES." p2c, ".TABLE_CATEGORIES." c, ".TABLE_CATEGORIES_DESCRIPTION." cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '".(int) $_SESSION['languages_id']."' and p.manufacturers_id = '".(int) $_GET['manufacturers_id']."' order by cd.categories_name";
} else {
$filterlist_sql = "select distinct m.manufacturers_id as id, m.manufacturers_name as name from ".TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_TO_CATEGORIES." p2c, ".TABLE_MANUFACTURERS." m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '".$current_category_id."' order by m.manufacturers_name";
}
$filterlist_query = xtDBquery($filterlist_sql);
if (xtc_db_num_rows($filterlist_query, true) > 1) {
$manufacturer_dropdown = xtc_draw_form('filter', $_REQUEST['linkurl'], 'get');
if (isset ($_GET['manufacturers_id'])) {
$manufacturer_dropdown .= xtc_draw_hidden_field('manufacturers_id', (int)$_GET['manufacturers_id']);
$options = array (array ('text' => TEXT_ALL_CATEGORIES));
} else {
$manufacturer_dropdown .= xtc_draw_hidden_field('cat', $_GET['cat']);
$options = array (array ('text' => TEXT_ALL_MANUFACTURERS));
}
$manufacturer_dropdown .= xtc_draw_hidden_field('sort', $_GET['sort']);
$manufacturer_dropdown .= xtc_draw_hidden_field(xtc_session_name(), xtc_session_id());
while ($filterlist = xtc_db_fetch_array($filterlist_query, true)) {
$options[] = array ('id' => $filterlist['id'], 'text' => $filterlist['name']);
}
$manufacturer_dropdown .= xtc_draw_pull_down_menu('filter_id', $options, $_GET['filter_id'], 'onchange="this.form.submit()"');
$manufacturer_dropdown .= '</form>'."\n";
}
//sorting_dropdown BEGINS
$sorting_dropdown = xtc_draw_form('sorting', $_REQUEST['linkurl'], 'GET') . ' ';
if (isset($cPath)) $sorting_dropdown.= xtc_draw_hidden_field('cat', $_GET['cat']);
if (isset($cPath))
$sorting_dropdown.= xtc_draw_hidden_field('cPath', $cPath);
if (isset($_GET['filter_id']))
$sorting_dropdown.= xtc_draw_hidden_field('filter_id', $_GET['filter_id']);
if (isset($_GET['manufacturers_id']))
$sorting_dropdown.= xtc_draw_hidden_field('manufacturers_id', $_GET['manufacturers_id']);
$options_sort = array(array('text' => 'Sortierung wählen'));
$options_sort[] = array('id' => '1', 'text' => 'A bis Z');
$options_sort[] = array('id' => '2', 'text' => 'Z bis A');
$options_sort[] = array('id' => '3', 'text' => 'Preis - aufsteigend');
$options_sort[] = array('id' => '4', 'text' => 'Preis - absteigend');
$options_sort[] = array('id' => '5', 'text' => 'Hersteller - aufsteigend');
$options_sort[] = array('id' => '6', 'text' => 'Hersteller - absteigend');
$options_sort[] = array('id' => '7', 'text' => 'Neue Produkte');
$options_sort[] = array('id' => '8', 'text' => 'Bestseller');
$options_sort[] = array('id' => '9', 'text' => 'Meist gesehen');
$sorting_dropdown.= xtc_draw_pull_down_menu('sorting_id', $options_sort, $_GET['sorting_id'], 'onchange="this.form.submit()" style="width: 170px;"');
$sorting_dropdown.= '</form>' . "\n";
//sorting_dropdown END
}
// ##########################################################################
// options filter for dropdowns
// $excluded_options = '10'; // comma-separated list of excluded option ids
if (!empty($excluded_options))
$excluded_options_condition = 'and po.products_options_id not in (' . $excluded_options . ')';
// modify options filter join to connect to products_attributes instead of products
$option_filter_join = str_replace('x.products_id = p.products_id', 'x.products_id = pa.products_id', $option_filter_join);
// 1. get options and values for this catgory
$filter_sql = 'select po.products_options_id options_id,
po.products_options_name options_name,
pv.products_options_values_id options_values_id,
pv.products_options_values_name options_values_name,
count(pa.products_id) option_values_count
from '.TABLE_PRODUCTS_OPTIONS.' po
join '.TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS.' pv2po on pv2po.products_options_id = po.products_options_id
join '.TABLE_PRODUCTS_OPTIONS_VALUES.' pv on pv.products_options_values_id = pv2po.products_options_values_id
join '.TABLE_PRODUCTS_ATTRIBUTES.' pa on pa.options_id = po.products_options_id and
pa.options_values_id = pv.products_options_values_id
join '.TABLE_PRODUCTS_TO_CATEGORIES.' p2c on p2c.products_id = pa.products_id
join '.TABLE_PRODUCTS.' p on p.products_id = pa.products_id
'. $option_filter_join .'
where p2c.categories_id = ' . $current_category_id . '
and po.language_id = '.(int) $_SESSION['languages_id'].'
and pv.language_id = '.(int) $_SESSION['languages_id'].'
and p.products_status = 1
'. $excluded_options_condition .'
group by 1, 2, 3, 4
order by 1, 4';
// echo $filter_sql;
$filter_query = xtDBquery($filter_sql);
// 2. group result set in array
$option_id = 0;
while ($rec = xtc_db_fetch_array($filter_query, true)) {
// new option?
if ($option_id != $rec['options_id'])
{
$option_id = $rec['options_id'];
$filter[$option_id]['id'] = $rec['options_id'];
$filter[$option_id]['name'] = $rec['options_name'];
}
$option_values = array('id' => $rec['options_values_id'],
'name' => $rec['options_values_name'],
'count' => $rec['option_values_count']);
$filter[$option_id]['values'][] = $option_values;
}
// 3. collect url params
$url_params = $_GET;
// reset session
$url_params[xtc_session_name()] = xtc_session_id();
// remove empty params
foreach ($url_params as $key => $value)
if (empty($value)) unset($url_params[$key]);
// 4. build dropdowns
if (!empty($filter))
{
foreach ($filter as $optid => $option)
{
// init form
$dropdown = xtc_draw_form('filter'. $optid, FILENAME_DEFAULT, 'get');
// url params as hidden fields
$url_param_fields = '';
foreach ($url_params as $key => $value)
if ($key != 'optfilter'. $optid)
$url_param_fields .= xtc_draw_hidden_field($key, $value);
$dropdown .= $url_param_fields;
// init dropdown
$options = array (array ('text' => '-- ' . $option['name'] . ' --'));
foreach ($option['values'] as $key => $rec)
$options[] = array ('id' => $rec['id'], 'text' => $rec['name']);
$dropdown .= xtc_draw_pull_down_menu('optfilter'. $optid, $options, $_GET['optfilter'. $optid], 'style="float:left; width:150px; margin:5px;" onchange="this.form.submit()"');
$dropdown .= '</form>'."\n";
$option_dropdowns[] = $dropdown;
}
// add separator
$option_dropdowns[] = '<div style="clear: left;"></div>';
}
// ##########################################################################
?>
Alles anzeigen
Es wird mir zwar in den Reitern die Vorschläge angezeigt, aber es wird nicht gefiltert.
Wo könnte das Problem liegen?