Answer the question
In order to leave comments, you need to log in
How to make Bitrix search for linked elements?
Previously, I already asked the question when the product had downloaded files and it was necessary to search for them.
How can Bitrix search by the property of an infoblock of the File/Multiple type?
I added it to init.php and everything works great.
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('search', 'BeforeIndex', array('MySearch', 'BeforeIndex'));
class MySearch {
public static function BeforeIndex($arFields) {
if(intval($arFields['PARAM2']) == 34 && intval($arFields['ITEM_ID']) > 0 && isset($arFields['BODY'])) {
\Bitrix\Main\Loader::includeModule('iblock');
$dbRes = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $arFields['PARAM2'], 'ID' => $arFields['ITEM_ID']), false, false, array('PROPERTY_DOCUMENTS'));
while($arRes = $dbRes->Fetch()) {
$arFile = CFile::GetFileArray($arRes['PROPERTY_DOCUMENTS_VALUE']);
$arFields['BODY'] .= PHP_EOL.$arFile['ORIGINAL_NAME'];
}
return $arFields;
}
}
}
Answer the question
In order to leave comments, you need to log in
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('search', 'BeforeIndex', array('MySearch', 'BeforeIndex'));
class MySearch {
private static $catalogIblockId = 2;
private static $docsIblockId = 4;
const PROPERTY_DOCUMENTS = 'PROPERTY_FILE';
public static function BeforeIndex($arFields) {
if(intval($arFields['PARAM2']) == self::$catalogIblockId && intval($arFields['ITEM_ID']) > 0 && isset($arFields['BODY'])) {
\Bitrix\Main\Loader::includeModule('iblock');
$arDocsId = array();
$dbRes = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $arFields['PARAM2'], 'ID' => $arFields['ITEM_ID']), false, false, array(self::PROPERTY_DOCUMENTS));
while($arRes = $dbRes->Fetch()) {
if($arRes[self::PROPERTY_DOCUMENTS.'_VALUE'])
$arDocsId[] = $arRes[self::PROPERTY_DOCUMENTS.'_VALUE'];
}
if($arDocsId) {
$dbRes = CIBlockElement::GetList(array(), array('IBLOCK_ID' => self::$docsIblockId, 'ID' => $arDocsId), false, false, array('NAME'));
while($arRes = $dbRes->Fetch()) {
$arFields['BODY'] .= PHP_EOL.$arRes['NAME'];
}
}
return $arFields;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question