276 lines
8.6 KiB
PHP
276 lines
8.6 KiB
PHP
<?php
|
||
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED!==true)die();
|
||
//$arParams - параметры, чтение, изменение. Не затрагивает одноименный член компонента, но изменения тут влияют на $arParams в файле template.php.
|
||
//$arResult — результат, чтение/изменение. Затрагивает одноименный член класса компонента.
|
||
//$APPLICATION, $USER, $DB - объявлять их как global избыточно, они уже доступны по-умолчанию.
|
||
//$this — ссылка на текущий шаблон (объект, описывающий шаблон, тип CBitrixComponentTemplate)
|
||
|
||
//$cp = $this->__component; // объект компонента
|
||
//
|
||
//if (is_object($cp))
|
||
//{
|
||
// // добавим в arResult компонента два поля - MY_TITLE и IS_OBJECT
|
||
// $cp->arResult['MY_TITLE'] = 'Мое название';
|
||
// $cp->arResult['IS_OBJECT'] = 'Y';
|
||
// $cp->SetResultCacheKeys(array('MY_TITLE','IS_OBJECT'));
|
||
//
|
||
// $APPLICATION->SetTitle($cp->arResult['MY_TITLE']); // не будет работать на каждом хите:
|
||
////отработает только первый раз, затем будет все браться из кеша и вызова $APPLICATION->SetTitle()
|
||
//// не будет. Поэтому изменение title делается в component_epilog, который выполняется на каждом хите.
|
||
//
|
||
//}
|
||
|
||
$catalog_positions_ids = [];
|
||
$catalog_positions = [];
|
||
|
||
$used_positions_ids = [];
|
||
$used_positions = [];
|
||
|
||
$special_offers_ids = [];
|
||
$special_offers = [];
|
||
|
||
$programs_ids = [];
|
||
$programs = [];
|
||
|
||
$news_ids = [];
|
||
$news = [];
|
||
|
||
$services_ids = [];
|
||
$services = [];
|
||
|
||
//print "<pre>";
|
||
//print_r($arResult['SEARCH']);
|
||
//print "</pre>";
|
||
|
||
foreach($arResult['SEARCH'] AS $arItem)
|
||
{
|
||
if($arItem['PARAM2'] == IBLOCK_ID_CATALOG_CARS_NEW)
|
||
{
|
||
array_push($catalog_positions_ids, $arItem['ITEM_ID']);
|
||
}
|
||
|
||
if($arItem['PARAM2'] == IBLOCK_ID_CATALOG_CARS_USED)
|
||
{
|
||
array_push($used_positions_ids, $arItem['ITEM_ID']);
|
||
}
|
||
|
||
if($arItem['PARAM2'] == IBLOCK_ID_NEWS)
|
||
{
|
||
array_push($news_ids, $arItem['ITEM_ID']);
|
||
}
|
||
|
||
if($arItem['PARAM2'] == IBLOCK_ID_SPECIALS)
|
||
{
|
||
array_push($special_offers_ids, $arItem['ITEM_ID']);
|
||
}
|
||
|
||
if($arItem['PARAM2'] == IBLOCK_ID_SERVICES)
|
||
{
|
||
array_push($services_ids, $arItem['ITEM_ID']);
|
||
}
|
||
|
||
if($arItem['PARAM2'] == IBLOCK_ID_PROGRAMS)
|
||
{
|
||
array_push($programs_ids, $arItem['ITEM_ID']);
|
||
}
|
||
}
|
||
|
||
//print_r($catalog_positions_ids);
|
||
if(count($news_ids) > 0)
|
||
{
|
||
$res_news = CIBlockElement::GetList([ 'NAME' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_NEWS, 'ID' => $news_ids ], false, [
|
||
]);
|
||
|
||
while ($ob_element_news = $res_news->GetNextElement())
|
||
{
|
||
$ar_res_news = $ob_element_news->GetFields();
|
||
$ar_res_news['PROPERTIES'] = $ob_element_news->GetProperties();
|
||
if(isset($ar_res_news['PREVIEW_PICTURE']))
|
||
{
|
||
$ar_res_news['PREVIEW_PICTURE'] = CFile::GetPath($ar_res_news['PREVIEW_PICTURE']);
|
||
}
|
||
|
||
$news[$ar_res_news['ID']] = $ar_res_news;
|
||
}
|
||
}
|
||
|
||
if(count($special_offers_ids) > 0)
|
||
{
|
||
$res_specials = CIBlockElement::GetList([ 'NAME' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_SPECIALS, 'ID' => $special_offers_ids ], false, [
|
||
]);
|
||
|
||
while ($ob_element_specials = $res_specials->GetNextElement())
|
||
{
|
||
$ar_res_specials = $ob_element_specials->GetFields();
|
||
$ar_res_specials['PROPERTIES'] = $ob_element_specials->GetProperties();
|
||
if(isset($ar_res_specials['PREVIEW_PICTURE']))
|
||
{
|
||
$ar_res_specials['PREVIEW_PICTURE'] = CFile::GetPath($ar_res_specials['PREVIEW_PICTURE']);
|
||
}
|
||
|
||
$special_offers[$ar_res_specials['ID']] = $ar_res_specials;
|
||
}
|
||
}
|
||
|
||
if(count($services_ids) > 0)
|
||
{
|
||
$res_services = CIBlockElement::GetList([ 'NAME' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_SERVICES, 'ID' => $services_ids ], false, [
|
||
]);
|
||
|
||
while ($ob_element_services = $res_services->GetNextElement())
|
||
{
|
||
$ar_res_services = $ob_element_services->GetFields();
|
||
$ar_res_services['PROPERTIES'] = $ob_element_services->GetProperties();
|
||
if(isset($ar_res_services['PREVIEW_PICTURE']))
|
||
{
|
||
$ar_res_services['PREVIEW_PICTURE'] = CFile::GetPath($ar_res_services['PREVIEW_PICTURE']);
|
||
}
|
||
|
||
$services[$ar_res_services['ID']] = $ar_res_services;
|
||
}
|
||
}
|
||
|
||
if(count($programs_ids) > 0)
|
||
{
|
||
$res_programs = CIBlockElement::GetList([ 'NAME' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_PROGRAMS, 'ID' => $programs_ids ], false, [
|
||
]);
|
||
|
||
while ($ob_element_programs = $res_programs->GetNextElement())
|
||
{
|
||
$ar_res_programs = $ob_element_programs->GetFields();
|
||
$ar_res_programs['PROPERTIES'] = $ob_element_programs->GetProperties();
|
||
if(isset($ar_res_programs['PREVIEW_PICTURE']))
|
||
{
|
||
$ar_res_programs['PREVIEW_PICTURE'] = CFile::GetPath($ar_res_programs['PREVIEW_PICTURE']);
|
||
}
|
||
|
||
$programs[$ar_res_programs['ID']] = $ar_res_programs;
|
||
}
|
||
}
|
||
|
||
if(count($catalog_positions_ids) > 0)
|
||
{
|
||
$res_catalog = CIBlockElement::GetList([ 'NAME' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_CATALOG_CARS_NEW, 'ID' => $catalog_positions_ids ], false, [
|
||
/*
|
||
"NAME",
|
||
"DETAIL_PAGE_URL",
|
||
"BRAND",
|
||
"MODEL",
|
||
"BODY",
|
||
"MODIFICATION",
|
||
"ENGINE_FUEL",
|
||
"GEAR",
|
||
"ENGINE_POWER",
|
||
"PRICE",
|
||
"IMAGE_URL",
|
||
*/
|
||
]);
|
||
|
||
while ($ob_element_catalog = $res_catalog->GetNextElement())
|
||
{
|
||
$ar_res_catalog = $ob_element_catalog->GetFields();
|
||
$ar_res_catalog['PROPERTIES'] = $ob_element_catalog->GetProperties();
|
||
$ar_res_catalog['PROPERTIES']['BRAND']['RELATED'] = get_related(IBLOCK_ID_BRANDS, $ar_res_catalog['PROPERTIES']['BRAND']['VALUE']);
|
||
$ar_res_catalog['PROPERTIES']['MODEL']['RELATED'] = get_related(IBLOCK_ID_MODELS, $ar_res_catalog['PROPERTIES']['MODEL']['VALUE']);
|
||
$ar_res_catalog['PROPERTIES']['MODIFICATION']['RELATED'] = get_related(IBLOCK_ID_MODIFICATIONS, $ar_res_catalog['PROPERTIES']['MODIFICATION']['VALUE']);
|
||
|
||
$ar_res_catalog['CALCULATION'] = [];
|
||
$ar_res_catalog['CALCULATION']['MONTHLY'] = number_format((($ar_res_catalog['PROPERTIES']['PRICE']['VALUE'] / 100) * 10), 0, ".", " ");
|
||
$ar_res_catalog['CALCULATION']['SAVINGS_TAX'] = number_format((($ar_res_catalog['PROPERTIES']['PRICE']['VALUE'] / 100) * 4), 0, ".", " ");
|
||
$ar_res_catalog['CALCULATION']['SAVINGS_VAT'] = number_format((($ar_res_catalog['PROPERTIES']['PRICE']['VALUE'] / 100) * 4), 0, ".", " ");
|
||
|
||
$catalog_positions[$ar_res_catalog['ID']] = $ar_res_catalog;
|
||
|
||
//print $ar_res_catalog['ID']." - ".$ar_res_catalog['NAME']."\n";
|
||
}
|
||
}
|
||
|
||
if(count($used_positions_ids) > 0)
|
||
{
|
||
$res_catalog = CIBlockElement::GetList([ 'NAME' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_CATALOG_CARS_USED, 'ID' => $used_positions_ids ], false, [
|
||
/*
|
||
"NAME",
|
||
"DETAIL_PAGE_URL",
|
||
"BRAND",
|
||
"MODEL",
|
||
"BODY",
|
||
"MODIFICATION",
|
||
"ENGINE_FUEL",
|
||
"GEAR",
|
||
"ENGINE_POWER",
|
||
"PRICE",
|
||
"IMAGE_URL",
|
||
*/
|
||
]);
|
||
|
||
while ($ob_element_catalog = $res_catalog->GetNextElement())
|
||
{
|
||
$ar_res_catalog = $ob_element_catalog->GetFields();
|
||
$ar_res_catalog['PROPERTIES'] = $ob_element_catalog->GetProperties();
|
||
$ar_res_catalog['PROPERTIES']['BRAND']['RELATED'] = get_related(IBLOCK_ID_BRANDS_USED, $ar_res_catalog['PROPERTIES']['BRAND']['VALUE']);
|
||
$ar_res_catalog['PROPERTIES']['MODEL']['RELATED'] = get_related(IBLOCK_ID_MODELS_USED, $ar_res_catalog['PROPERTIES']['MODEL']['VALUE']);
|
||
|
||
$ar_res_catalog['CALCULATION'] = [];
|
||
$ar_res_catalog['CALCULATION']['MONTHLY'] = number_format((($ar_res_catalog['PROPERTIES']['PRICE']['VALUE'] / 100) * 10), 0, ".", " ");
|
||
|
||
$ar_res_catalog['PREVIEW_PICTURE'] = CFile::GetPath($ar_res_catalog['PROPERTIES']['PHOTO']['VALUE']);
|
||
|
||
$used_positions[$ar_res_catalog['ID']] = $ar_res_catalog;
|
||
|
||
//print $ar_res_catalog['ID']." - ".$ar_res_catalog['NAME']."\n";
|
||
}
|
||
}
|
||
|
||
foreach($arResult['SEARCH'] AS $key => $item)
|
||
{
|
||
if($item['PARAM2'] == IBLOCK_ID_CATALOG_CARS_NEW)
|
||
{
|
||
if(isset($catalog_positions[$item['ITEM_ID']]))
|
||
{
|
||
$arResult['SEARCH'][$key]['CAR'] = $catalog_positions[$item['ITEM_ID']];
|
||
}
|
||
}
|
||
|
||
if($item['PARAM2'] == IBLOCK_ID_CATALOG_CARS_USED)
|
||
{
|
||
if(isset($used_positions[$item['ITEM_ID']]))
|
||
{
|
||
$arResult['SEARCH'][$key]['USED'] = $used_positions[$item['ITEM_ID']];
|
||
}
|
||
}
|
||
|
||
if($item['PARAM2'] == IBLOCK_ID_NEWS)
|
||
{
|
||
if(isset($news[$item['ITEM_ID']]))
|
||
{
|
||
$arResult['SEARCH'][$key]['ENTRY'] = $news[$item['ITEM_ID']];
|
||
}
|
||
}
|
||
|
||
if($item['PARAM2'] == IBLOCK_ID_SPECIALS)
|
||
{
|
||
if(isset($special_offers[$item['ITEM_ID']]))
|
||
{
|
||
$arResult['SEARCH'][$key]['OFFER'] = $special_offers[$item['ITEM_ID']];
|
||
}
|
||
}
|
||
|
||
if($item['PARAM2'] == IBLOCK_ID_SERVICES)
|
||
{
|
||
if(isset($services[$item['ITEM_ID']]))
|
||
{
|
||
$arResult['SEARCH'][$key]['ENTRY'] = $services[$item['ITEM_ID']];
|
||
}
|
||
}
|
||
|
||
if($item['PARAM2'] == IBLOCK_ID_PROGRAMS)
|
||
{
|
||
if(isset($programs[$item['ITEM_ID']]))
|
||
{
|
||
$arResult['SEARCH'][$key]['ENTRY'] = $programs[$item['ITEM_ID']];
|
||
}
|
||
}
|
||
}
|
||
|
||
?>
|