Фильтр товаров по категорям

  • Фильтр товаров по категорям

Позволяет выводить в лист товаров записи принадлежащие к определенной кактегории, что облегчает выбор нужного товара при большом количестве товаров и категорий.

Список вносимых изменений:

файл
admin/controller/catalog/product.php" error="log

перед
if (isset($this->request->get['filter_name'])) {

добавить
if (isset($this->request->get['filter_category_id'])) {
                $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
            }
            
после
private function getList() {

добавить
 if (isset($this->request->get['filter_category_id'])) {
            $filter_category_id = $this->request->get['filter_category_id'];
                } else {
                    $filter_category_id = null;
                }
                        $url = '';
                        
перед
'filter_name'      => $filter_name,

добавить
'filter_category_id' => $filter_category_id,

после
$this->data['pagination'] = $pagination->render();

добавить
$this->load->model('catalog/category');

                        $this->data['categories'] = $this->model_catalog_category->getCategories(0);
                        $this->data['filter_category_id'] = $filter_category_id;
                        
файл
admin/view/template/catalog/product_list.tpl

заменить
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>

на
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?>:&nbsp;
         <select name="filter_category_id" onchange="filter();">
            <option value="">&nbsp;</option>
            <?php foreach($categories as $c) { ?>
            <option value="<?php echo $c['category_id']?>" <?php echo ($c['category_id'] == $filter_category_id ? 'selected' : '') ?>><?php echo $c['name'] ?></option>
            <?php } ?>
         </select></h1>
        
перед
var filter_name = $('input[name=\'filter_name\']').attr('value');

добавить
var filter_category_id = $('select[name=\'filter_category_id\']').attr('value');

    if (filter_category_id) {
        url += '&filter_category_id=' + encodeURIComponent(filter_category_id);
    }