S
S
Sergey Karpin2020-08-31 16:36:05
1C-Bitrix
Sergey Karpin, 2020-08-31 16:36:05

How to make an alternative CNC smart filter?

Hello everybody!

I want to make an alternative CNC smart filter, so that instead of "site.ru/catalog/filter/brand-is-makita/apply/" there is a beautiful "site.ru/catalog/makita/" tell me how to implement it. Perhaps someone has already done this and will throw a thought in which direction to pick. I can roughly imagine the implementation options, for example, changing the url, but in theory it should work out a 301 redirect, or maybe it shouldn’t. In any case, I appeal to you more experienced colleagues.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-09-02
@carpin

Remove filter and apply Replace
the line in the bitrix:catalog component with :

"smart_filter" => "#SECTION_CODE_PATH#/#SMART_FILTER_PATH#/",

In the catalog.smart.filter filter, change the settings to the following:
<?
                $res = CIBlockSection::GetByID($arCurSection['ID']);
                if($ar_res = $res->GetNext())
                $url = "/catalog/".$ar_res[CODE]."/#SMART_FILTER_PATH#/";
    $APPLICATION->IncludeComponent("bitrix:catalog.smart.filter", "bootstrap_v4", array(
                "CACHE_GROUPS" => "N",	// Учитывать права доступа
    "CACHE_TIME" => "3600",	// Время кеширования (сек.)
    "CACHE_TYPE" => "A",	// Тип кеширования
    "COMPOSITE_FRAME_MODE" => "N",
    "COMPOSITE_FRAME_TYPE" => "AUTO",
    "CONVERT_CURRENCY" => "N",	// Показывать цены в одной валюте
    "DISPLAY_ELEMENT_COUNT" => "N",	// Показывать количество
    "FILTER_NAME" => "arrFilter",	// Имя выходящего массива для фильтрации
    "FILTER_VIEW_MODE" => "vertical",
    "HIDE_NOT_AVAILABLE" => "Y",	// Не отображать товары, которых нет на складах
    "IBLOCK_ID" => $arParams["IBLOCK_ID"],	// Инфоблок
    "IBLOCK_TYPE" => "catalog",	// Тип инфоблока
    "PAGER_PARAMS_NAME" => "arrPager",	
    "SAVE_IN_SESSION" => "N",	// Сохранять установки фильтра в сессии пользователя
    "SECTION_CODE" => "",	// Код раздела
    "SECTION_DESCRIPTION" => "-",	// Описание
    "SECTION_ID" => $arCurSection['ID'],	// ID раздела инфоблока
    "SECTION_TITLE" => "-",	// Заголовок
    "SEF_MODE" => "Y",	// Включить поддержку ЧПУ
    "TEMPLATE_THEME" => "blue",	// Цветовая тема
    "XML_EXPORT" => "N",	// Включить поддержку Яндекс Островов
    "COMPONENT_TEMPLATE" => "",
    "POPUP_POSITION" => "left",
    "SECTION_CODE_PATH" => "",	// Путь из символьных кодов раздела
    "SEF_RULE" => $url,	// Правило для обработки
    "SMART_FILTER_PATH" => $_REQUEST["SMART_FILTER_PATH"],	// Блок ЧПУ умного фильтра
    "SHOW_ALL_WO_SECTION" => "Y",
    "PRICE_CODE" => "",	// Тип цены
    "PREFILTER_NAME" => "smartPreFilter",	// Допфильтрация элементов
            ),
           false);
     ?>

You need to add one rule to urlrewrite.php, it will not be overwritten in the future, and the general view will be something like this:
<?php
$arUrlRewrite=array (
  1 => 
  array (
    'CONDITION' => '#^/catalog/([a-z0-9_\\-\\/]+)/#',
    'RULE' => 'SMART_FILTER_PATH=$1&',
    'ID' => '',
    'PATH' => '/catalog/index.php',
    'SORT' => 100,
  ),
  2 => 
  array (
    'CONDITION' => '#^/catalog/\\??(.*)#',
    'RULE' => 'SMART_FILTER_PATH=$1&$2',
    'ID' => 'bitrix:catalog.smart.filter',
    'PATH' => '/catalog/index.php',
    'SORT' => 100,
  ),
  3 => 
  array (
    'CONDITION' => '#^/catalog/#',
    'RULE' => '',
    'ID' => 'bitrix:catalog',
    'PATH' => '/catalog/index.php',
    'SORT' => 100,
  )
);

Removing IS and OR
To remove -is-, you need to replace the values ​​in SMART_FILTER_PATH, and then make a 301 redirect from the original address to the custom one.
How you will do the substitution - I don't know (with loops, arrays, and other "pehepish things"), but the substitution should be higher than the filter code. It is necessary to check the occurrences, the correctness of the substitutions, add error handling, use 301 redirects so as not to produce duplicates, of which there are already many without filter refinement.
Here is an example:
$_REQUEST[SMART_FILTER_PATH] = str_replace("red/brown", "colors-is-brown-or-red/", $_REQUEST[SMART_FILTER_PATH]);

As a result, instead of the line
https://test.ru/catalog/pants/filter/color_ref-is-green/apply/

we get the line:
https://test.ru/catalog/pants/green/
5f4fd8c4caad8356011565.jpeg
5f4fd8cf127cb908819760.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question