Пример:
Имеем фильтр, выбрали 2 бренда, выбрали 1 свойство. Но если я выберу ещё свойства, которые нету в товарах, то пишет Товары не найдены.
Сам фильтр:
Код: Выделить всё
{* Фильтр по свойствам *}
{if $features}
<form method=get enctype="multipart/form-data">
<table id="features">
{foreach $features as $f}
<tr>
<td class="feature_name">
{$f->name}:
</td>
<td>
<select class="feature_values" size="1" name="{$f->id}" >
<option value="">Выбрать</option>
{foreach $f->options as $o}
<option value="{$o->translit}" {if $fil[$f->id] == $o->translit}selected{/if}>{$o->value}</option>
{/foreach}
</select>
</td>
</tr>
{/foreach}
</table>
<input type="submit" value="Показать">
</form>
{/if}
{literal}
<script>
function clicker(that) {
var pick = that.options[that.selectedIndex].value;
location.href = pick;
}
function clickerb() {
var pick = getElementsByName("feature[]").options[getElementsByName("feature[]").selectedIndex].value;
}
</script>
{/literal}{* @END Фильтр по свойствам *}
ProductsView.php этот кусок играет роль какую?
Код: Выделить всё
// Свойства товаров
if(!empty($category)) {
$features = array();
foreach($this->features->get_features(array('category_id'=>$category->id, 'in_filter'=>1)) as $feature) {
$features[$feature->id] = $feature;
$this->features_urls[] = $feature->url;
if($val = $this->request->get($feature->id)) {
{
$filter['features'][$feature->id] = $val;
$fil[$feature->id] = $val;
}
}
}
$options_filter['visible'] = 1;
$features_ids = array_keys($features);
if(!empty($features_ids)) {
$options_filter['feature_id'] = $features_ids;
}
$options_filter['category_id'] = $category->children;{
// if(isset($filter['features']))
// $options_filter['features'] = $filter['features'];
}
if(!empty($brand)) {
$options_filter['brand_id'] = $brand->id;
} elseif(isset($filter['brand_id'])) {
$options_filter['brand_id'] = $filter['brand_id'];
}
$options = $this->features->get_options($options_filter);
foreach($options as $option) {
if(isset($features[$option->feature_id])) {
$features[$option->feature_id]->options[] = $option;
}
}
foreach($features as $i=>$feature) {
if(empty($feature->options)) {
unset($features[$i]);
}
}
$this->design->assign('features', $features);
$this->design->assign('fil', $fil);
}
// Постраничная навигация
$items_per_page = $this->settings->products_num;
// Текущая страница в постраничном выводе
$current_page = $this->request->get('page', 'integer');
// Если не задана, то равна 1
$current_page = max(1, $current_page);
$this->design->assign('current_page_num', $current_page);
// Вычисляем количество страниц
$products_count = $this->products->count_products($filter);
// Показать все страницы сразу
if($this->request->get('page') == 'all') {
$items_per_page = $products_count;
}
$pages_num = ceil($products_count/$items_per_page);
$this->design->assign('total_pages_num', $pages_num);
$this->design->assign('total_products_num', $products_count);
$filter['page'] = $current_page;
$filter['limit'] = $items_per_page;
if ($this->request->get('page') != 'all' && $current_page > 1 && $current_page > $pages_num) {
return false;
}
//lastModify
$last_modify = array();
$brand_id_filter = '';
$category_id_filter = '';
if(!empty($filter['brand_id'])) {
$brand_id_filter = $this->db->placehold('AND p.brand_id in(?@)', (array)$filter['brand_id']);
if(!empty($brand)){
$last_modify[] = $brand->last_modify;
}
}
if(!empty($filter['category_id'])) {
$category_id_filter = $this->db->placehold('INNER JOIN __products_categories pc ON pc.product_id = p.id AND pc.category_id in(?@)', (array)$filter['category_id']);
$last_modify[] = $category->last_modify;
}
$this->db->query("SELECT p.last_modify
FROM __products p
$category_id_filter
WHERE 1 $brand_id_filter
GROUP BY p.id");
$res = $this->db->results('last_modify');
if (!empty($res)) {
$last_modify = array_merge($last_modify, $res);
}
if ($this->page) {
$last_modify[] = $this->page->last_modify;
}
$this->setHeaderLastModify(max($last_modify));
//lastModify END