Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Фильтр производителей в категориях товара


Recommended Posts

Добрый гдень
Есть тема

тут

Но по ходу она умерла.
Есть нужда сгделать фильтр производителей только по включенным товарам

Фильтр выводит все производители к которым закреплены товары данной категории.

Но если товары данной категории, прикреплённые к производителю, выключены, то производитель всё равно выводится. И получается если в категории товары имеют 20 производителей и только 3 производителя имеют включенные товары, то покупателю приходится бестолково клацать по осильным пустым производителям. Что приводит к уходу покупателя с сайи.

Как сгделать ик чтоб выводились производители только те у которых товар включён?
Прошу помощи!

Link to comment
Share on other sites


2 часа назад, Prooksius сказал:

Каким фильтром пользуетесь - непонятно.

им не модуль
 я же ссылку дал на тему
Вот код фильтра

<modification>
    <id>Filter by manufacturers</id>
    <version>1.0</version>
    <vqmver>2.1.5</vqmver>
    <author>Denisov Konstantin</author>
    <website>http://www.grissoft.com.ua</website>
    <email>[email protected]</email>
        <file name="catalog/controller/product/category.php">
            <operation>
                <search position="after">
                    <![CDATA[
                        $category_info = $this->model_catalog_category->getCategory($category_id);
                    ]]>
                </search>
                <add>
                    <![CDATA[
                        //Manufacturers
                       $manufacturers = $this->model_catalog_category->getManufacturers($category_id,true);
                       $this->data['manufacturers'] = array();
                       $this->data['all_manufacturers'] = $this->url->link('product/category', 'path=' . $category_id);
                       foreach ($manufacturers as $manufacturer) {
                           $this->data['manufacturers'][] = array (
                               'manufacturer_id' => $manufacturer['manufacturer_id'],
                               'name' => $manufacturer['name'],
                               'href' => $this->url->link('product/category', 'path=' . $category_id . '&manufacturer_id=' . $manufacturer['manufacturer_id'])
                           );
                       }
                       if (isset($this->request->get['manufacturer_id'])) {
                           $manufacturer_id = $this->request->get['manufacturer_id'];
                           $this->data['manufacturer_id'] = $manufacturer_id;
                       } else {
                           $manufacturer_id = false;
                           $this->data['manufacturer_id'] = 0;
                       }
                        //---------------
                    ]]>
                </add>
            </operation>

            <operation>
                <search position="after">
                    <![CDATA[
                        $url = '';
                    ]]>
                </search>
                <add>
                    <![CDATA[    
                        //Manufacturers
                        if (isset($this->request->get['manufacturer_id'])) {
                            $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
                        }
                        //----------------
                    ]]>
                </add>
            </operation>
            
            <operation>
                <search position="before">
                    <![CDATA[
                        'filter_category_id' => $category_id,
                    ]]>
                </search>
                <add>
                    <![CDATA[    
                        'filter_manufacturer_id'  => $manufacturer_id,
                    ]]>
                </add>
            </operation>
            
            
        </file>
        
        <file name="catalog/model/catalog/category.php">
            <operation>
                <search position="after">
                    <![CDATA[
                        class ModelCatalogCategory extends Model {
                    ]]>
                </search>
                <add>
                    <![CDATA[
                        //Manufacturers
                       public function getManufacturers($filter_category_id = 0, $filter_sub_category = false) {

                        if($filter_category_id == 0) $filter_sub_category = true;
                        
                        $sql = "SELECT m.name, m.manufacturer_id ";
                        $sql .= " FROM " . DB_PREFIX . "manufacturer m ";

                        $sql .= " INNER JOIN " . DB_PREFIX . "product p ON (p.manufacturer_id=m.manufacturer_id)";
                            if ($filter_sub_category == true) {
                                $implode_data = array();
                                $categories = $this->getCategoriesByParentId($filter_category_id);
                                $categories[]=$filter_category_id;
                                $implode_data = implode(',',$categories);
                                $sql .= " INNER JOIN " . DB_PREFIX . "product_to_category p2c ON (p.`product_id`=p2c.`product_id`) and p2c.`category_id` in (".$implode_data.")";
                            } else {
                                $sql .= " INNER JOIN " . DB_PREFIX . "product_to_category p2c ON (p.`product_id`=p2c.`product_id`) and p2c.`category_id`=".$filter_category_id."";
                            }
                        $sql .= " GROUP BY p.manufacturer_id";

                        
                        $query = $this->db->query($sql);
                        return $query->rows;
                   
                    }
                        //---------------
                    ]]>
                </add>
            </operation>
            
        </file>
        <file name="catalog/view/theme/default/template/product/category.tpl">
            <operation>
                <search position="before">
                    <![CDATA[
                        <?php if ($products) { ?>
                    ]]>
                </search>
                <add>
                    <![CDATA[
                        <!-- Manufacturers -->
                       <?php if ($manufacturers) { ?>
                       <div class="manufacturers">
                            <?php if ($manufacturer_id==0) { ?>
                            <span>Все производители</span>
                            <?php } else { ?>
                            <a href="<?php echo $all_manufacturers; ?>">Все производители</a>
                            <?php } ?>
                            <?php foreach ($manufacturers as $manufacturer) { ?>
                            <?php if($manufacturer['manufacturer_id']==$manufacturer_id) { ?>
                            <span><?php echo $manufacturer['name'] ?></span>
                            <?php } else {?>
                            <a href="<?php echo $manufacturer['href'] ?>"><?php echo $manufacturer['name'] ?></a>
                            <?php }?>
                            
                            <?php } ?>
                        </div>
                        <?php } ?>
                        <!-- End of Manufacturers -->
                    ]]>
                </add>
            </operation>
            
        </file>
</modification>

 

Link to comment
Share on other sites


16 часов назад, Allaur сказал:

им не модуль
 я же ссылку дал на тему

Мне кажется вам бы лучше купить нормальный фильтр и пользоваться. А это костыли, как по мне.
Но рилиить должно, в принципе

  • +1 1
Link to comment
Share on other sites

16 часов назад, Prooksius сказал:

перед строкой

$sql .= " GROUP BY p.manufacturer_id";

всивьте следуюещёе:

$sql .= " WHERE p.status = 1";

 

 

Отлично всё рилииет
Спасипотому что :)

 

25 минут назад, Prooksius сказал:

Мне кажется вам бы лучше купить нормальный фильтр и пользоваться. 

Стоит фильтр-про, но хозяин хочет ещё над сортировкой отгдельно по производителям сортировать.
У каждого свои ираканы в голове. :)

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.