D
D
Darklt2022-04-17 17:43:26
1C-Bitrix
Darklt, 2022-04-17 17:43:26

Why does the search by article number not work in Bitrix if there are special characters?

There is a search event by article:

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

It searches for the article if this article consists only of numbers and letters, and if the article, for example, KLC-100, then it will not find it, it will find it if you specify KLC100, although in fact the article is KLC-100.

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