M
M
Misha Vasilyev2013-05-13 11:50:47
1C-Bitrix
Misha Vasilyev, 2013-05-13 11:50:47

CNC 1C-Bitrix

Friends! There is such a problem.

I have an online store that uses a comprehensive catalog component that has NC support enabled. For some reason, it works as follows: if, for example, a product has the address /catalog/section/product.11111/, then the same product is available at /catalog/blah-blah-blah/tovar.11111/ while in blah -blah-blah can be anything. How can this be removed, or why can't it be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petr Zhuchkov, 2013-05-13
@vasilyev

Just a product can belong to several categories. This is how it is set up by default.
And If you are in the "blah-blah-blah" section, then the link will be from this section. For SEO, this is not very good.
This is solved by adding code to the result_modifier.php file in your catalog template (specifically catalog.section)

<?php
$iCnt = sizeof($arResult['ITEMS']);
for ($i=0; $i < $iCnt; $i++) { 
  $rsItem = CIBlockElement::GetByID($arResult['ITEMS'][$i]['ID']);//достаем данные элемента
  $arItem = $rsItem->GetNext();
  $rsSec = CIBlockSection::GetByID($arItem['IBLOCK_SECTION_ID']);//Достаем данные секции
  $arSec = $rsSec->GetNext();
  $arResult['ITEMS'][$i]['DETAIL_PAGE_URL'] = $arParams['DETAIL_URL'];//Параметры компонента
  $arResult['ITEMS'][$i]['DETAIL_PAGE_URL'] = str_replace('#SECTION_CODE#', $arSec['CODE'], $arResult['ITEMS'][$i]['DETAIL_PAGE_URL']);//Меняем код секциии
  $arResult['ITEMS'][$i]['DETAIL_PAGE_URL'] = str_replace('#ELEMENT_CODE#', $arItem['CODE'], $arResult['ITEMS'][$i]['DETAIL_PAGE_URL']);//Меняем код товара
}?>

The code was written on the knees, but because works and don't want to change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question