36 if(!isset($params[
"IBLOCK_ID"]) || intval($params[
"IBLOCK_ID"]) <= 0)
37 throw new SystemException(
"Incorrect iBlock ID (".__CLASS__.
"::".__METHOD__.
")");
41 $this->iBlockId = $params[
"IBLOCK_ID"];
42 $this->xmlData = $params[
"XML_DATA"];
44 $this->arIblock = $this->
getIblockProps($params[
"SETUP_SERVER_NAME"]);
45 $this->arSections = $this->
getSections($params[
"PRODUCT_GROUPS"]);
46 if(isset($params[
"START_POSITION"]) && $params[
"START_POSITION"])
47 $this->startPosition = $params[
"START_POSITION"];
48 if(isset($params[
"INCLUDE_SUBSECTION"]))
49 $this->includeSubsections = $params[
"INCLUDE_SUBSECTION"];
51 $this->bAllSections = in_array(0, $this->arSections) ? true :
false;
123 $order = array(
"ID" =>
"ASC");
124 $arSelect = array(
"ID",
"LID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"NAME",
"PREVIEW_PICTURE",
"PREVIEW_TEXT",
125 "PREVIEW_TEXT_TYPE",
"DETAIL_PICTURE",
"LANG_DIR",
"DETAIL_PAGE_URL",
"DETAIL_TEXT");
127 $filter = array(
"IBLOCK_ID" => $this->iBlockId);
130 if($this->startPosition)
133 if (!$this->bAllSections && !empty($this->arSections))
135 $filter[
"INCLUDE_SUBSECTIONS"] = $this->includeSubsections ?
"Y" :
"N";
139 if($this->onlyAvailableElements)
140 $filter[
"CATALOG_AVAILABLE"] =
"Y";
141 $filter[
"ACTIVE"] =
"Y";
142 $filter[
"SECTION_GLOBAL_ACTIVE"] =
"Y";
143 $filter[
"ACTIVE_DATE"] =
"Y";
145 return \CIBlockElement::GetList($order, $filter,
false,
false, $arSelect);
165 if (!$this->bAllSections)
167 $intSectionsCount = count($this->arSections);
168 for ($i = 0; $i < $intSectionsCount; $i++)
170 $list = \CIBlockSection::GetNavChain(
172 $this->arSections[$i],
184 $curRIGHT_MARGIN = 0;
185 foreach ($list as $ar_res)
187 $curLEFT_MARGIN = (int)$ar_res[
'LEFT_MARGIN'];
188 $curRIGHT_MARGIN = (int)$ar_res[
'RIGHT_MARGIN'];
189 $arAvailGroups[$ar_res[
'ID']] = [
190 'ID' => (int)$ar_res[
'ID'],
191 'IBLOCK_SECTION_ID' => (
int)$ar_res[
'IBLOCK_SECTION_ID'],
192 'NAME' => $ar_res[
'NAME'],
195 unset($ar_res, $list);
199 '>LEFT_MARGIN' => $curLEFT_MARGIN,
200 '<RIGHT_MARGIN' => $curRIGHT_MARGIN,
202 'IBLOCK_ACTIVE' =>
'Y',
203 'GLOBAL_ACTIVE' =>
'Y',
205 $db_res = \CIBlockSection::GetList(
206 [
'LEFT_MARGIN '=>
'ASC'],
217 while ($ar_res = $db_res->Fetch())
219 $arAvailGroups[$ar_res[
'ID']] = [
220 'ID' => (int)$ar_res[
'ID'],
221 'IBLOCK_SECTION_ID' => (
int)$ar_res[
'IBLOCK_SECTION_ID'],
222 'NAME' => $ar_res[
'NAME'],
225 unset($ar_res, $db_res);
233 'IBLOCK_ACTIVE' =>
'Y',
234 'GLOBAL_ACTIVE' =>
'Y',
236 $db_res = \CIBlockSection::GetList(
237 [
'LEFT_MARGIN' =>
'ASC'],
248 while ($ar_res = $db_res->Fetch())
250 $arAvailGroups[$ar_res[
'ID']] = [
251 'ID' => (int)$ar_res[
'ID'],
252 'IBLOCK_SECTION_ID' => (
int)$ar_res[
'IBLOCK_SECTION_ID'],
253 'NAME' => $ar_res[
'NAME'],
256 unset($ar_res, $db_res);
259 return $arAvailGroups;
282 $dbIblock = \CIBlock::GetByID($this->iBlockId);
287 if ($serverName ==
'')
291 $rsSite = \CSite::GetList(
'',
'', array(
"LID" =>
$arIblock[
"LID"]));
292 if($arSite = $rsSite->Fetch())
293 $arIblock[
"SERVER_NAME"] = $arSite[
"SERVER_NAME"];
294 if(
$arIblock[
"SERVER_NAME"] ==
'' && defined(
"SITE_SERVER_NAME"))
295 $arIblock[
"SERVER_NAME"] = SITE_SERVER_NAME;
297 $arIblock[
"SERVER_NAME"] = \COption::GetOptionString(
"main",
"server_name",
"");
307 $rsProps = \CIBlockProperty::GetList(
308 array(
'SORT' =>
'ASC',
'NAME' =>
'ASC'),
309 array(
'IBLOCK_ID' => $this->iBlockId,
'ACTIVE' =>
'Y',
'CHECK_PERMISSIONS' =>
'N')
311 while ($arProp = $rsProps->Fetch())
313 $arProp[
'ID'] = (int)$arProp[
'ID'];
314 $arProp[
'USER_TYPE'] = (string)$arProp[
'USER_TYPE'];
315 $arProp[
'CODE'] = (string)$arProp[
'CODE'];
316 $arIblock[
'PROPERTY'][$arProp[
'ID']] = $arProp;
378 $minPriceCurrency =
"";
380 $baseCurrency = Currency\CurrencyManager::getBaseCurrency();
383 if ($this->xmlData[
'PRICE'] > 0)
385 $rsPrices = \CPrice::GetListEx(array(),array(
386 'PRODUCT_ID' => $productId,
387 'CATALOG_GROUP_ID' => $this->xmlData[
'PRICE'],
389 'GROUP_GROUP_ID' => array(2),
390 '+<=QUANTITY_FROM' => 1,
391 '+>=QUANTITY_TO' => 1,
395 if ($arPrice = $rsPrices->Fetch())
397 if ($arOptimalPrice = \CCatalogProduct::GetOptimalPrice(
406 $minPrice = $arOptimalPrice[
'RESULT_PRICE'][
'DISCOUNT_PRICE'];
407 $minPriceCurrency = $baseCurrency;
408 $minPriceRUR = \CCurrencyRates::ConvertCurrency($minPrice, $baseCurrency, $RUR);
409 $minPriceGroup = $arOptimalPrice[
'PRICE'][
'CATALOG_GROUP_ID'];
415 if ($arPrice = \CCatalogProduct::GetOptimalPrice(
424 $minPrice = $arPrice[
'RESULT_PRICE'][
'DISCOUNT_PRICE'];
425 $minPriceCurrency = $baseCurrency;
426 $minPriceRUR = \CCurrencyRates::ConvertCurrency($minPrice, $baseCurrency, $RUR);
427 $minPriceGroup = $arPrice[
'PRICE'][
'CATALOG_GROUP_ID'];
433 "MIN_RUB" => $minPriceRUR,
434 "MIN_GROUP" => $minPriceGroup,
435 "MIN_CURRENCY" => $minPriceCurrency
475 $arProperties = array();
477 $arUserTypeFormat = array();
479 foreach($arProperties as $key => $arProperty)
481 $arUserTypeFormat[$arProperty[
"ID"]] =
false;
482 if($arProperty[
"USER_TYPE"] <>
'')
484 $arUserType = \CIBlockProperty::GetUserType($arProperty[
"USER_TYPE"]);
485 if(array_key_exists(
"GetPublicViewHTML", $arUserType))
487 $arUserTypeFormat[$arProperty[
"ID"]] = $arUserType[
"GetPublicViewHTML"];
488 $arProperties[$key][
'PROPERTY_TYPE'] =
'USER_TYPE';
496 if (is_array($this->xmlData) && is_array($this->xmlData[
'XML_DATA']) && is_array($this->xmlData[
'XML_DATA'][
'PARAMS']))
498 foreach ($this->xmlData[
'XML_DATA'][
'PARAMS'] as $key => $propId)
501 $result[] = $this->
getValue($product,
'PARAM_'.$key, $propId, $arProperties, $arUserTypeFormat);
508 protected function getValue($arOffer, $param, $PROPERTY, $arProperties, $arUserTypeFormat)
512 $bParam = (strncmp($param,
'PARAM_', 6) == 0);
514 if (isset($arProperties[$PROPERTY]) && !empty($arProperties[$PROPERTY]))
516 $PROPERTY_CODE = $arProperties[$PROPERTY][
'CODE'];
518 isset($arOffer[
'PROPERTIES'][$PROPERTY_CODE])
519 ? $arOffer[
'PROPERTIES'][$PROPERTY_CODE]
520 : $arOffer[
'PROPERTIES'][$PROPERTY]
525 if(!is_array($arProperty[
"VALUE"]))
526 $arProperty[
"VALUE"] = array($arProperty[
"VALUE"]);
528 switch ($arProperties[$PROPERTY][
'PROPERTY_TYPE'])
531 foreach($arProperty[
"VALUE"] as $oneValue)
533 $value[] = call_user_func_array($arUserTypeFormat[$PROPERTY],
536 array(
"VALUE" => $oneValue),
537 array(
'MODE' =>
'SIMPLE_TEXT'),
543 $arCheckValue = array();
545 foreach ($arProperty[
'VALUE'] as &$intValue)
547 $intValue = (int)$intValue;
549 $arCheckValue[] = $intValue;
552 if (isset($intValue))
555 if (!empty($arCheckValue))
557 $dbRes = \CIBlockElement::GetList(array(), array(
'IBLOCK_ID' => $arProperties[$PROPERTY][
'LINK_IBLOCK_ID'],
'ID' => $arCheckValue),
false,
false, array(
'NAME'));
558 while ($arRes = $dbRes->Fetch())
560 $value[] = $arRes[
'NAME'];
566 $arCheckValue = array();
568 foreach ($arProperty[
'VALUE'] as &$intValue)
570 $intValue = (int)$intValue;
572 $arCheckValue[] = $intValue;
575 if (isset($intValue))
578 if (!empty($arCheckValue))
580 $dbRes = \CIBlockSection::GetList(array(), array(
'IBLOCK_ID' => $arProperty[
'LINK_IBLOCK_ID'],
'ID' => $arCheckValue),
false, array(
'NAME'));
581 while ($arRes = $dbRes->Fetch())
583 $value[] = $arRes[
'NAME'];
589 $value .= $arProperty[
'VALUE'];
593 foreach ($arProperty[
'VALUE'] as &$intValue)
595 $intValue = (int)$intValue;
598 if ($ar_file = \CFile::GetFileArray($intValue))
600 if(mb_substr($ar_file[
"SRC"], 0, 1) ==
"/")
601 $strFile =
"http://".$this->arIblock[
"SERVER_NAME"].implode(
"/", array_map(
"rawurlencode", explode(
"/", $ar_file[
"SRC"])));
602 elseif(preg_match(
"/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file[
"SRC"], $match))
603 $strFile =
"http://".$match[2].
'/'.implode(
"/", array_map(
"rawurlencode", explode(
"/", $match[3])));
605 $strFile = $ar_file[
"SRC"];
611 if (isset($intValue))
616 $value = $arProperty[
'VALUE'];
619 if(is_array($value) && count($value) == 1)
620 $value = implode(
"", $value);
624 $result[$param] = array(
625 "NAME" => $arProperties[$PROPERTY][
'NAME'],
631 $result[$param] = $value;