use Bitrix\Main\Page\Asset;
$this->setFrameMode(true);
// Search category for catalog products
$catalogCategory = 'iblock_' . $arParams['IBLOCK_TYPE'];
// hack search request
if (empty($_GET['where']) || empty($_REQUEST['where'])) {
$_GET['where'] = $_REQUEST['where'] = $catalogCategory;
}
if ($_GET['where'] === 'ALL' || $_REQUEST['where'] === 'ALL') {
$_GET['where'] = $_REQUEST['where'] = '';
}
// fill params for bitrix:search.page
$arSearchPageParams = array(
"RESTART" => "Y",
"NO_WORD_LOGIC" => "Y",
"USE_LANGUAGE_GUESS" => "N",
"CHECK_DATES" => "Y",
"USE_TITLE_RANK" => "N",
"DEFAULT_SORT" => "rank",
"FILTER_NAME" => "offerFilter",
"arrFILTER" => array(
0 => $catalogCategory,
1 => "iblock_news"
),
"arrFILTER_".$catalogCategory => array($arParams["IBLOCK_ID"]),
"arrFILTER_iblock_news" => array(
0 => "all",
),
"SHOW_WHERE" => "Y",
"arrWHERE" => array(
0 => $catalogCategory,
1 => "iblock_news",
),
"SHOW_WHEN" => "N",
"PAGE_RESULT_COUNT" => 20,
"DISPLAY_TOP_PAGER" => "N",
"DISPLAY_BOTTOM_PAGER" => "Y",
"PAGER_TITLE" => GetMessage("SEARCH_RESULTS"),
"PAGER_SHOW_ALWAYS" => "N",
"PAGER_TEMPLATE" => "",
"SEARCH_WITH_OFFERS" => false,
//===
"CACHE_TYPE" => "N",
//===
"IBLOCK_TYPE" => $arParams['IBLOCK_TYPE']
);
global $offerFilter;
$offerFilter = array();
$bOffers = false;
$whereBackup = $_REQUEST['where'];
// check catalog offers
do {
if (!empty($_REQUEST['where']) && ($_REQUEST['where'] !== $catalogCategory)) break;
if (!CModule::IncludeModule('catalog')) break;
$arOfferIBlock = CCatalogSKU::GetInfoByProductIBlock($arParams['IBLOCK_ID']);
if (!is_array($arOfferIBlock)) break;
// fill params to search with offers
$bOffers = true;
$offerIBlockType = CIBlock::GetArrayByID($arOfferIBlock['IBLOCK_ID'], 'IBLOCK_TYPE_ID');
$offerCategory = 'iblock_' . $offerIBlockType;
if (in_array($offerCategory, $arSearchPageParams['arrFILTER'])) {
$arSearchPageParams['arrFILTER_' . $offerCategory][] = $arOfferIBlock['IBLOCK_ID'];
} else {
$arSearchPageParams['arrFILTER_' . $offerCategory] = array(0 => $arOfferIBlock['IBLOCK_ID']);
$arSearchPageParams['arrFILTER'][] = $offerCategory;
}
if (
$catalogCategory === $_REQUEST['where'] &&
$catalogCategory !== $offerCategory
) {
// make custom filter for search with offers
// because catalog iblock and offer iblock has different types
$arSearchPageParams['SEARCH_WITH_OFFERS'] = true;
$offerFilter['MODULE_ID'] = 'iblock';
$offerFilter['PARAM1'] = array($arParams['IBLOCK_TYPE'], $offerIBlockType);
$_GET['where'] = $_REQUEST['where'] = '';
}
} while (0);
// perform search, fill elements ID list
$arElements = $APPLICATION->IncludeComponent(
"bitrix:search.page",
"search",
$arSearchPageParams,
$component,
array('HIDE_ICONS' => 'Y')
);
// return request param to original value
$_GET['where'] = $_REQUEST['where'] = $whereBackup;
if (empty($_GET['where'])) {
$_GET['where'] = $_REQUEST['where'] = 'ALL';
}
if ($_REQUEST['where'] !== $catalogCategory) return;
// search made in catalog, output result through catalog.section
if (
!empty($arElements) &&
is_array($arElements)
) {
if ($bOffers) {
$arOffers = CCatalogSKU::getProductList($arElements, $arOfferIBlock['IBLOCK_ID']);
if (is_array($arOffers)) {
$arOffers = array_keys($arOffers);
$arElements = array_diff($arElements, $arOffers);
}
}
global $searchFilter;
/**
* @var array $arSectionParams;
*/
include 'include/prepare_params_section.php';
$arSearchParams = array(
"FILTER_NAME" => "searchFilter",
"SECTION_ID" => "",
"SECTION_CODE" => "",
"SECTION_USER_FIELDS" => array(),
"INCLUDE_SUBSECTIONS" => "Y",
"SHOW_ALL_WO_SECTION" => "Y",
"META_KEYWORDS" => "",
"META_DESCRIPTION" => "",
"BROWSER_TITLE" => "",
"ADD_SECTIONS_CHAIN" => "N",
"SET_TITLE" => "N",
"SET_STATUS_404" => "N",
"CACHE_FILTER" => "N",
"CACHE_GROUPS" => "N",
"ELEMENT_SORT_FIELD" => "",
"ELEMENT_SORT_ORDER" => "",
"ELEMENT_SORT_FIELD2" => "",
"ELEMENT_SORT_ORDER2" => "",
'SEARCH_PAGE' => 'Y'
);
$arSearchParams = array_merge($arSectionParams, $arSearchParams);
$catalogClass = 'catalog blocks active ';
$catalogClass .= $arResult['HOVER-MODE'];
$this->SetViewTarget('catalog_search');
echo '<div class="'.$catalogClass.'" id="catalog_section" data-hover-effect="'.$arResult['HOVER-MODE'].'" data-quick-view-enabled="false">';
if (!empty($arElements)) {
$searchFilter = array(
"=ID" => $arElements,
);
$APPLICATION->IncludeComponent(
"bitrix:catalog.section",
"blockss",
$arSearchParams,
$component,
array('HIDE_ICONS' => 'Y')
);
}
if ($bOffers && !empty($arOffers)) {
$arSearchParams['IBLOCK_TYPE'] = $offerIBlockType;
$arSearchParams['IBLOCK_ID'] = $arOfferIBlock['IBLOCK_ID'];
unset($arSearchParams['DETAIL_URL']);
$searchFilter = array('=ID' => $arOffers);
$APPLICATION->IncludeComponent(
"bitrix:catalog.section",
"blockss",
$arSearchParams,
$component,
array('HIDE_ICONS' => 'Y')
);
}
echo '</div>';
$this->EndViewTarget('catalog_search');
} else {
echo GetMessage("CT_BCSE_NOT_FOUND");
} |