Редирект для карточки товара работает, но редирект для разделов и подразделов перенаправляет на одну и ту же страницу, не могу понять в чем проблема....
На сайте необходимо сменить ЧПУ для каталога.
Раньше был настроен #SECTION_CODE_PATH#/#ELEMENT_CODE#/
который изменяется на #SECTION_CODE#/#ELEMENT_CODE#/.
Пробовал делать как описано
здесь
1. В параметр SEF_URL_TEMPLATES добавил строку
"redirect" => "#SECTION_CODE_PATH#/#ELEMENT_CODE#/",
2. В своем шаблоне комплексного компонента catalog создал файл redirect.php (там где файлы типа section.php, element.php и т.д.)
3. В этом файле написал:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();?>
<?$this->setFrameMode(true);?>
<?
use Bitrix\Main\Loader;
use Bitrix\Main\ModuleManager;
Loader::includeModule("iblock");
Loader::includeModule("highloadblock");
global $OptimusSectionID;
$arElement = array();
if($arResult["VARIABLES"]["ELEMENT_ID"] > 0){
$arElement = COptimusCache::CIBLockElement_GetList(array('CACHE' => array("MULTI" =>"N", "TAG" => COptimusCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE"=>"Y", "ID" => $arResult["VARIABLES"]["ELEMENT_ID"]), false, false, array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PAGE_URL", "NAME"));
}
elseif(strlen(trim($arResult["VARIABLES"]["ELEMENT_CODE"])) > 0){
$arElement = COptimusCache::CIBLockElement_GetList(array('CACHE' => array("MULTI" =>"N", "TAG" => COptimusCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE"=>"Y", "=CODE" => $arResult["VARIABLES"]["ELEMENT_CODE"]), false, false, array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PAGE_URL", "NAME"));
}
//$OptimusSectionID = $arSection["ID"];
if($arElement['DETAIL_PAGE_URL']) {
LocalRedirect($arElement['DETAIL_PAGE_URL']);
}
global $OptimusSectionID;
$arSection = array();
if($arResult["VARIABLES"]["SECTION_ID"] > 0){
$arSection = COptimusCache::CIBlockSection_GetList(array('CACHE' => array("MULTI" =>"N", "TAG" => COptimusCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), array('GLOBAL_ACTIVE' => 'Y', "ID" => $arResult["VARIABLES"]["SECTION_ID"], "IBLOCK_ID" => $arParams["IBLOCK_ID"]), false, array("ID", "IBLOCK_ID", "UF_TIZERS", "IBLOCK_TYPE_ID", "IBLOCK_SECTION_ID", "CODE", "SECTION_ID", "SECTION_PAGE_URL", "NAME"));
}
elseif(strlen(trim($arResult["VARIABLES"]["SECTION_CODE"])) > 0){
$arSection = COptimusCache::CIBlockSection_GetList(array('CACHE' => array("MULTI" =>"N", "TAG" => COptimusCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), array('GLOBAL_ACTIVE' => 'Y', "=CODE" => $arResult["VARIABLES"]["SECTION_CODE"], "IBLOCK_ID" => $arParams["IBLOCK_ID"]), false, array("ID", "IBLOCK_ID", "UF_TIZERS", "IBLOCK_TYPE_ID", "IBLOCK_SECTION_ID", "CODE", "SECTION_ID", "SECTION_PAGE_URL", "NAME"));
}
$OptimusSectionID = $arSection["ID"];
if(strpos($arSection['SECTION_PAGE_URL'], '#SECTION_CODE_PATH#') !== true) {
$elementId = $arResult['VARIABLES']['SECTION_ID'];
$filter = ['IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ID' => $elementId];
$element = [];
$iterator = CIBlockSection::GetList([], $filter, false, false, ["IBLOCK_ID", "ID", "SECTION_PAGE_URL", "IBLOCK_TYPE_ID", "IBLOCK_SECTION_ID", "CODE", "SECTION_ID", "NAME"]);
if($row = $iterator->GetNext()) {
$element = $row;
}
if($element['SECTION_PAGE_URL']) {
LocalRedirect($element['SECTION_PAGE_URL']);
}
}
?>