Здравствуйте! Думаю для тех кто разбирается в Opencart труда не составит. Нужно переделать запрос в базу данных для фильтра. Сейчас он сумирует выборку, допустим по двум критериям. Напримар если задать размер 36 и цвет белый, фильтр выдаст все модели 36(любого цвета) и все белые (любого размера). А нужно чтоб выборка была перекрестная, те только 36 и белые модели. И на последок кнопка сброс фильтра.
catalog/controller/module/filter.php
<?php
class ControllerModuleFilter extends Controller {
public function index() {
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
$category_id = end($parts);
$this->load->model('catalog/category');
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$this->load->language('module/filter');
$data['heading_title'] = $this->language->get('heading_title');
$data['button_filter'] = $this->language->get('button_filter');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['action'] = str_replace('&', '&', $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url));
if (isset($this->request->get['filter'])) {
$data['filter_category'] = explode(',', $this->request->get['filter']);
} else {
$data['filter_category'] = array();
}
$this->load->model('catalog/product');
$data['filter_groups'] = array();
$filter_groups = $this->model_catalog_category->getCategoryFilters($category_id);
if ($filter_groups) {
foreach ($filter_groups as $filter_group) {
$childen_data = array();
foreach ($filter_group['filter'] as $filter) {
$filter_data = array(
'filter_category_id' => $category_id,
'filter_filter' => $filter['filter_id']
);
$childen_data[] = array(
'filter_id' => $filter['filter_id'],
'name' => $filter['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : '')
);
}
$data['filter_groups'][] = array(
'filter_group_id' => $filter_group['filter_group_id'],
'name' => $filter_group['name'],
'filter' => $childen_data
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/filter.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/filter.tpl', $data);
} else {
return $this->load->view('default/template/module/filter.tpl', $data);
}
}
}
}
}
вывод в шаблон:
<div class="box-category">
<div class="strip-line"></div>
<div class="box-content">
<ul class="box-filter" style="padding:10px 0;">
<?php foreach ($filter_groups as $filter_group) { ?>
<select style="border: 1px #bababa solid;width: 100%;background-color: white;
">
<option><?php echo $filter_group['name']; ?></option>
<?php foreach ($filter_group['filter'] as $filter) { ?>
<?php if (in_array($filter['filter_id'], $filter_category)) { ?>
<option value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" selected>
<?php echo $filter['name']; ?>
</option>
<?php } else { ?>
<option value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>">
<?php echo $filter['name']; ?>
</option>
<?php } ?>
<?php } ?>
</select>
</li>
<?php } ?>
</ul>
<a id="button-filter" class="button"><?php echo $button_filter; ?></a>
</div>
</div>
<script type="text/javascript"><!--
$('#button-filter').bind('click', function() {
filter = [];
$('.box-filter select option:selected').each(function(element) {
filter.push(this.value);
});
location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
//--></script>