if(is_null($_REQUEST["q"]) && is_null($arParams["SECTION_CODE"])){ $arResult['sec_id'] = 0; $this->IncludeComponentTemplate(); }else{ if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); if(!CModule::IncludeModule("iblock")) return; $q = isset($_REQUEST['q']) ? trim($_REQUEST['q']) : null; if(!$q) $q = null; $cart = Order::GetCart(); $cats = []; $arResult['cats'] = []; $arResult['prods'] = []; $arResult['sec_id'] = 0; $arResult['total'] = 0; $sids = []; $sec_id = 0; $sec_count = 0; $sec_name = 0; $catMs = []; $catPs = []; $parId = 0; $rootId = 0; $cFil = ['IBLOCK_ID'=>$arParams['IBLOCK_ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y']; if(isset($arParams['SECTION_CODE'])) { $row = CIBlockSection::GetList(['SORT' => 'ASC'], ['IBLOCK_ID'=>$arParams['IBLOCK_ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'CODE' => $arParams['SECTION_CODE']], false)->GetNext(); if($row && !$row['IBLOCK_SECTION_ID']) $parId = $row['ID']; else $rootId = $row['IBLOCK_SECTION_ID']; } $rows = CIBlockSection::GetList(['SORT' => 'ASC'], $cFil, false); while($res = $rows->GetNext()) { if($parId != 0 && $parId != $res['ID'] && $parId != $res['IBLOCK_SECTION_ID']) continue; if($rootId && $rootId != $res['ID'] && $rootId != $res['IBLOCK_SECTION_ID']) continue; $cat = []; $cat['id'] = $res['ID']; $cat['parent_id'] = $res['IBLOCK_SECTION_ID']; $cat['name'] = $res['NAME']; $cat['desc'] = $res['DESCRIPTION']; $cat['url'] = $res['SECTION_PAGE_URL']; $file = CFile::GetFileArray($res["PICTURE"]); $cat['image'] = $file ? $file['SRC'] : '/local/images/no-image.png'; $cat['childs'] = []; $cat['count'] = (int)CIBlockElement::GetList(Array(), Array('IBLOCK_ID' => $arParams['IBLOCK_ID'], 'SECTION_ID' => $res['ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'CATALOG_AVAILABLE' => 'Y'), false)->SelectedRowsCount(); $ids = []; $r1 = CIBlockElement::GetList(Array(), Array('IBLOCK_ID' => $arParams['IBLOCK_ID'], 'SECTION_ID' => $res['ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'CATALOG_AVAILABLE' => 'Y'), false, false, ['XML_ID']); while($r2 = $r1->GetNext()) $ids[] = $r2['XML_ID']; $nq = Order::NoQualitiesCount($ids); $cat['count'] -= $nq; $arResult['total'] += ($cat['count'] - $nq); if(isset($arParams['SECTION_CODE']) && $arParams['SECTION_CODE'] == $res['CODE']) { $sec_id = $cat['id']; $sec_count = $cat['count']; $sec_name = $cat['name']; } $catMs[$cat['id']] = $cat; $cats[$cat['id']] = $cat['name']; $sids[] = $cat['id']; } if($_GET['dev'] == 'y'){ // foreach($catMs as &$cat){ // if($cat['parent_id'] && isset($catMs[$cat['parent_id']])){ // $catMs[$cat['parent_id']]['childs'][] = $cat; // $catMs[$cat['parent_id']]['hasChilds'] = 'Y'; // } // } // foreach($catMs as &$cat){ // if($cat['hasChilds'] == "Y"){ // $catPs[] = $cat; // } // } // $arResult['cats'] = $catPs; ////////////////////////////////////////////////// // foreach($catMs as $category){ // if(!$category['parent_id']){ // $categoryArray[] = $category; // } // } // // foreach($categoryArray as $arrayItem){ // $categoryFinal = $arrayItem; // $newCategoryArray = array(); // foreach($catMs as $category){ // if($category['parent_id'] == $arrayItem['id']){ // $newCategoryArray[] = $category; // } // } // // foreach($newCategoryArray as $category2){ // foreach($catMs as $category2_1){ // if($category2_1['parent_id'] == $category2['id']){ // $newCategory2Array[] = $category2_1; // } // } // } // // // // $categoryFinal['childs'] = $newCategoryArray; // $final[] = $categoryFinal; // } // $arResult['cats'] = $catMs; // // echo '
';
// var_dump('abc');
// echo '';
}else{
foreach($catMs as &$cat)
if($cat['parent_id'] && isset($catMs[$cat['parent_id']]))
$catMs[$cat['parent_id']]['childs'][] = $cat;
foreach($catMs as &$cat)
if(!$cat['parent_id'])
$catPs[] = $cat;
$arResult['cats'] = $catPs;
}
//===================== START FILTER =====================
$request = array_diff($_REQUEST, array('', NULL, false));
unset($request['test']);
unset($request['t']);
unset($request['clear_cache']);
$filterQuery = array(
"LOGIC" => "AND",
);
if($request["dostupnost"] === "vnalichii"){
$filterQuery[">CATALOG_QUANTITY"] = 0;
}elseif($request["dostupnost"] === "podzakaz"){
$filterQuery["CATALOG_QUANTITY"] = 0;
}
foreach($request as $key => $query){
$filterQuery[$key] = $query;
}
//===================== END FILTER ======================
$fil = Array('IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'CATALOG_AVAILABLE' => 'Y', $filterQuery);
// $fil = Array('IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'CATALOG_AVAILABLE' => 'Y', ["LOGIC" => "OR", ["?PROPERTY_CML2_MANUFACTURER_VALUE" => "BRAHMA"]]);
// $fil = Array('IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'CATALOG_AVAILABLE' => 'Y',["LOGIC" => "OR", [">CATALOG_QUANTITY" => 0], ["ZAKAZNAYA_PRODKUTSIYA_DLYA_SAYTA" => "Да"]]);
$fil['SECTION_ID'] = $sids;
if($sec_id)
{
if(isset($catMs[$sec_id]) && count($catMs[$sec_id]['childs']))
{
$ids = [];
$arResult['total'] = 0;
foreach($catMs[$sec_id]['childs'] as $ch)
{
$arResult['total'] += $ch['count'];
$ids[] = $ch['id'];
}
$fil['SECTION_ID'] = $ids;
}
else
{
$fil['SECTION_ID'] = $sec_id;
$arResult['total'] = $sec_count;
}
$arResult['sec_id'] = $sec_id;
$APPLICATION->AddChainItem($sec_name);
$APPLICATION->SetTitle($sec_name);
}
if($q)
{
//$fil['?NAME'] = $q;
//$fil[] = ["LOGIC" => "OR", ['?NAME' => $q], ['?PROPERTY_CML2_MANUFACTURER_VALUE' => $q]];
//$fil[] = ["LOGIC" => "OR", ['?NAME' => $q], ['?PROPERTY_CML2_MANUFACTURER_VALUE' => $q], ['PROPERTY_ARTIKUL_VALUE' => $q], ['PROPERTY_CML2_ARTICLE_VALUE' => $q]];
$fil[] = ["LOGIC" => "OR", ['?NAME' => $q], ['?PROPERTY_CML2_MANUFACTURER_VALUE' => $q], ['PROPERTY_CML2_ARTICLE' => "%{$q}%"]];
//$fil[] = ["LOGIC" => "OR", ['?PROPERTY_ARTIKUL_VALUE' => $q], ['?PROPERTY_CML2_ARTICLE_VALUE' => $q]];
//$fil[] = [">CATALOG_QUANTITY" => 0, ['?NAME' => $q], ['?PROPERTY_CML2_MANUFACTURER_VALUE' => $q]];
//$fil[] = [["LOGIC" => "OR", ['?NAME' => $q], ['?PROPERTY_CML2_MANUFACTURER_VALUE' => $q]], ["LOGIC" => "OR", [">CATALOG_QUANTITY" => 0], ["ZAKAZNAYA_PRODKUTSIYA_DLYA_SAYTA" => "Да"]]];
}
$cnt = CIBlockElement::GetList(Array('SORT' => 'ASC'), $fil, false, false)->SelectedRowsCount();
$arResult['total'] = $cnt;
$arResult['onPage'] = 50;
$arResult['page'] = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$arResult['pageMax'] = (int)(($arResult['total'] - 1)/$arResult['onPage']) + 1;
$arResult['pageStart'] = max(1, $arResult['page'] - 2);
$asort = ['NAME' => 'ASC'];
$sort = Order::GetSort();
if($sort == 'abc')
$asort = ['NAME' => 'ASC'];
else if($sort == 'zyx')
$asort = ['NAME' => 'DESC'];
else if($sort == 'price')
$asort = ['catalog_PRICE_2' => 'ASC'];
else if($sort == 'priced')
$asort = ['catalog_PRICE_2' => 'DESC'];
//filter THAT!
$rows = CIBlockElement::GetList($asort, $fil, false, Array('iNumPage' => $arResult['page'], 'nPageSize' => $arResult['onPage'], 'checkOutOfRange' => true), array('ID', 'NAME', 'XML_ID', 'PREVIEW_PICTURE', 'CATALOG_GROUP_1', 'DETAIL_PAGE_URL', 'CATALOG_AVAILABLE', 'IBLOCK_SECTION_ID', 'ZAKAZNAYA_PRODKUTSIYA_DLYA_SAYTA'));
while($ob = $rows->GetNextElement())
{
$res = $ob->GetFields();
$props = $ob->GetProperties();
$item = [];
if(!Order::IsQuality($res["XML_ID"]))
continue;
$item['id'] = $res['ID'];
$item['name'] = $res['NAME'];
//$item['podzakaz'] = $props['ZAKAZNAYA_PRODKUTSIYA_DLYA_SAYTA']['VALUE'];
$file = CFile::GetFileArray($res["PREVIEW_PICTURE"]);
$item['image'] = $file ? $file['SRC'] : '/local/images/no-image.png';
$item['price'] = CPrice::GetBasePrice($item['id'])['PRICE'];
// $item['price'] = $res['CATALOG_PRICE_1'];
$item['url'] = $res['DETAIL_PAGE_URL'];
$item['cat'] = isset($cats[$res['IBLOCK_SECTION_ID']]) ? $cats[$res['IBLOCK_SECTION_ID']] : '';
$item['qty'] = $res['CATALOG_QUANTITY'];
if ($item['qty'] > 0) {
$item['podzakaz']="Нет";
} else {
$item['podzakaz']="Да";
}
$item['how'] = ($item['qty'] > 4) ? 'Много' : 'Мало';
$item['available'] = $res['CATALOG_AVAILABLE'] == 'Y';
$item['sku'] = $props['CML2_ARTICLE']['VALUE'];
$item['used_with'] = $props['DLYA_KAKOGO_KONKRETNO_OBORUDOVANIYA']['VALUE'];
if($props['DLYA_KAKOGO_KONKRETNO_OBORUDOVANIYA_1']['VALUE'])
$item['used_with'] .= ($item['used_with'] ? ', ' : '') . $props['DLYA_KAKOGO_KONKRETNO_OBORUDOVANIYA_1']['VALUE'];
if($props['DLYA_KAKOGO_KONKRETNO_OBORUDOVANIYA_2']['VALUE'])
$item['used_with'] .= ($item['used_with'] ? ', ' : '') . $props['DLYA_KAKOGO_KONKRETNO_OBORUDOVANIYA_2']['VALUE'];
$item['used_with'] = trim($item['used_with']);
$item['man'] = trim($props['CML2_MANUFACTURER']['VALUE']);
$item['inCart'] = 0;
$meas = \Bitrix\Catalog\ProductTable::getCurrentRatioWithMeasure($item['id']);
$item['measure_count'] = [1, 2, 3, 4, 5, 10, 20];
$item['measure_ratio'] = $meas ? $meas[$item['id']]['RATIO'] : '1';
$item['measure_id'] = $meas ? $meas[$item['id']]['MEASURE']['ID'] : '5';
$item['measure'] = $meas ? $meas[$item['id']]['MEASURE']['SYMBOL_RUS'] : 'шт';
foreach($cart['items'] as $it)
if($it['id'] == $item['id'])
{
$item['inCart'] = 1;
break;
}
if ($item['qty'] !== '0' || $item['podzakaz'] === 'Да'){
$arResult['prods'][] = $item;
}
}
$this->IncludeComponentTemplate();
}