Greetings. There is such a problem in the bitrix - there is a search for search.title headers. It is necessary that he did not index the goods, which have no commercial offers in warehouses. I wrote the code on the test page, I drive in the product ID manually - everything shows correctly, whether there is a TP and everything seems to be good. Well, then in init.php I cause an event before indexing and in the same way I try to exclude unnecessary goods, but still they somehow pass. What could be the problem?
AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler"); function BeforeIndexHandler($arFields) { CModule::IncludeModule('iblock'); CModule::IncludeModule('catalog'); $TovarExist = false; $TypeProduct = CCatalogSKU::getOffersList($arFields['ID']); if($TypeProduct != false){ foreach($TypeProduct as $key => $ProdSku){ foreach($ProdSku as $key => $SkuID){ for ($i = 2; $i < 12; $i++) { if ($i !== 8 && $i !== 9) { // неактивные склады $rsStore = CCatalogStoreProduct::GetList(array(), array('PRODUCT_ID' =>$SkuID['ID'], 'STORE_ID' => $i), false, false, array()); $arStore = $rsStore->Fetch(); if($arStore['AMOUNT'] > 0){ $TovarExist = true; } } } } } } if($TovarExist === false){ $arFields["BODY"] = $arFields["TITLE"] = ''; unset($arFields["BODY"]); //на всякий случай unset($arFields["TITLE"]); }
}