Opencart - Добавляем Сортировку По Производителю В Каталоге Товаров

Тема в разделе "Модули и дополнения", создана пользователем admin, 18 июн 2016.

  1. TopicStarter Overlay
    Offline

    admin Команда форума Администратор

    Сообщения:
    2.321
    Симпатии:
    76.775
    Репутация:
    170
    sort-pr-500x500.jpg
    Добавим в выпадающий список сортировку по производителю (от А до Я и наоборот). Почему-то разработчики этого не встроили...

    Примечание: сортировка не по имени, а по ID производителей: нам этого сейчас хватает.

    Чтобы сделать именно по названию, нужно ещё изменение.

    Изменяемые файлы:

    catalog/controller/product/category.php

    Код:
    'value' => 'p.model-DESC',
                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)
                 );
    +
    +            $this->data['sorts'][] = array(
    +                'text'  => $this->language->get('text_manufacturer_asc'),
    +                'value' => 'p.manufacturer_id-ASC',
    +                'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.manufacturer_id&order=ASC' . $url)
    +            );
    +
    +            $this->data['sorts'][] = array(
    +                'text'  => $this->language->get('text_manufacturer_desc'),
    +                'value' => 'p.manufacturer_id-DESC',
    +                'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.manufacturer_id&order=DESC' . $url)
    +            );
    +
                 
                 $url = '';
    catalog/language/russian/product/category.php

    Код:
    $_['text_rating_desc']  = 'Рейтинг (начиная с высокого)';
    $_['text_model_asc']    = 'Модель (А- Я)';
    $_['text_model_desc']   = 'Модель (Я - А)';
    +$_['text_manufacturer_asc']    = 'Производитель (А- Я)';
    +$_['text_manufacturer_desc']   = 'Производитель (Я - А)';
    $_['text_limit']        = 'Показать:';
    catalog/model/catalog/product.php

    Код:
    if (!$product_data) {
                //$sql = "SELECT p.product_id, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id)";
                //$sql = "SELECT p.product_id, p.manufacturer_id, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";
                $sql = "SELECT p.product_id, p.manufacturer_id, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id)";
               
               
                if (!empty($data['filter_tag'])) {
                    $sql .= " LEFT JOIN " . DB_PREFIX . "product_tag pt ON (p.product_id = pt.product_id)";           
                }
    'p.price',
                     'rating',
                     'p.sort_order',
    -                'p.date_added'
    +                'p.date_added',
    +                'p.manufacturer_id'
                 );   
                 
                 if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {