D
D
Darklt2022-03-27 16:19:08
1C-Bitrix
Darklt, 2022-03-27 16:19:08

How to display the article first?

Registered in init.php search by article, when replacing places with the name stops working? you need the Article to be before the name in the search results.

// Поиск только по названию товара и артикулу
AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler");
 // создаем обработчик события "BeforeIndex"
function BeforeIndexHandler($arFields)
{
   if(!CModule::IncludeModule("iblock")){
      return $arFields;
   }
   if($arFields["MODULE_ID"] == "iblock" && $arFields["PARAM2"] == 17){ // ID инфоблока
      $db_props = CIBlockElement::GetProperty(                        // Запросим свойства индексируемого элемента
                                    $arFields["PARAM2"],         // BLOCK_ID индексируемого свойства
                                    $arFields["ITEM_ID"],          // ID индексируемого свойства
                                    array("sort" => "asc"),       // Сортировка (можно упустить)
                                    Array("CODE"=>"CML2_ARTICLE")); // CODE свойства (в данном случае артикул)
      if($ar_props = $db_props->Fetch()){
         $arFields["TITLE"] .= " ".$ar_props["VALUE"];   // Добавим свойство в конец заголовка индексируемого элемента
      }
      $arFields["BODY"] = "";
   }
   return $arFields;
}


I change places here and it stops working completely. There are no errors.
$ar_props["VALUE"] .= " ".$arFields["TITLE"];

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question