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;
64 #[\ReturnTypeWillChange]
75 #[\ReturnTypeWillChange]
86 #[\ReturnTypeWillChange]
90 $this->currentRecord = $this->
nextItem();
99 #[\ReturnTypeWillChange]
102 $this->currentKey = 0;
104 $this->currentRecord = $this->
nextItem();
114 #[\ReturnTypeWillChange]
117 return is_array($this->currentRecord);
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);
152 foreach($arAvailGroups as $group)
153 if ($result < $group[
"ID"])
154 $result = $group[
"ID"];
156 $result += 100000000;
163 $arAvailGroups = array();
165 if (!$this->bAllSections)
167 for ($i = 0, $intSectionsCount = count($this->arSections); $i < $intSectionsCount; $i++)
169 $db_res = \CIBlockSection::GetNavChain($this->iBlockId, $this->arSections[$i]);
171 $curRIGHT_MARGIN = 0;
172 while ($ar_res = $db_res->Fetch())
174 $curLEFT_MARGIN = (int)$ar_res[
"LEFT_MARGIN"];
175 $curRIGHT_MARGIN = (int)$ar_res[
"RIGHT_MARGIN"];
176 $arAvailGroups[$ar_res[
"ID"]] = array(
177 "ID" => (
int)$ar_res[
"ID"],
178 "IBLOCK_SECTION_ID" => (
int)$ar_res[
"IBLOCK_SECTION_ID"],
179 "NAME" => $ar_res[
"NAME"]
183 $filter = array(
"IBLOCK_ID"=>$this->iBlockId,
">LEFT_MARGIN"=>$curLEFT_MARGIN,
"<RIGHT_MARGIN"=>$curRIGHT_MARGIN,
"ACTIVE"=>
"Y",
"IBLOCK_ACTIVE"=>
"Y",
"GLOBAL_ACTIVE"=>
"Y");
184 $db_res = \CIBlockSection::GetList(array(
"left_margin"=>
"asc"), $filter);
185 while ($ar_res = $db_res->Fetch())
187 $arAvailGroups[$ar_res[
"ID"]] = array(
188 "ID" => (
int)$ar_res[
"ID"],
189 "IBLOCK_SECTION_ID" => (
int)$ar_res[
"IBLOCK_SECTION_ID"],
190 "NAME" => $ar_res[
"NAME"]
197 $filter = array(
"IBLOCK_ID"=>$this->iBlockId,
"ACTIVE"=>
"Y",
"IBLOCK_ACTIVE"=>
"Y",
"GLOBAL_ACTIVE"=>
"Y");
198 $db_res = \CIBlockSection::GetList(array(
"left_margin"=>
"asc"), $filter);
199 while ($ar_res = $db_res->Fetch())
201 $arAvailGroups[$ar_res[
"ID"]] = array(
202 "ID" => (
int)$ar_res[
"ID"],
203 "IBLOCK_SECTION_ID" => (
int)$ar_res[
"IBLOCK_SECTION_ID"],
204 "NAME" => $ar_res[
"NAME"]
209 return $arAvailGroups;
216 if (is_array($selectedGroups))
218 foreach ($selectedGroups as $value)
232 $dbIblock = \CIBlock::GetByID($this->iBlockId);
237 if ($serverName ==
'')
241 $rsSite = \CSite::GetList(
'',
'', array(
"LID" =>
$arIblock[
"LID"]));
242 if($arSite = $rsSite->Fetch())
243 $arIblock[
"SERVER_NAME"] = $arSite[
"SERVER_NAME"];
244 if(
$arIblock[
"SERVER_NAME"] ==
'' && defined(
"SITE_SERVER_NAME"))
245 $arIblock[
"SERVER_NAME"] = SITE_SERVER_NAME;
247 $arIblock[
"SERVER_NAME"] = \COption::GetOptionString(
"main",
"server_name",
"");
257 $rsProps = \CIBlockProperty::GetList(
258 array(
'SORT' =>
'ASC',
'NAME' =>
'ASC'),
259 array(
'IBLOCK_ID' => $this->iBlockId,
'ACTIVE' =>
'Y',
'CHECK_PERMISSIONS' =>
'N')
261 while ($arProp = $rsProps->Fetch())
263 $arProp[
'ID'] = (int)$arProp[
'ID'];
264 $arProp[
'USER_TYPE'] = (string)$arProp[
'USER_TYPE'];
265 $arProp[
'CODE'] = (string)$arProp[
'CODE'];
266 $arIblock[
'PROPERTY'][$arProp[
'ID']] = $arProp;
277 $rsProducts = \CCatalogProduct::GetList(
279 array(
'ID' => $productId),
282 array(
'ID',
'QUANTITY',
'QUANTITY_TRACE',
'CAN_BUY_ZERO')
285 if ($arProduct = $rsProducts->Fetch())
287 $arProduct[
'QUANTITY'] = doubleval($arProduct[
'QUANTITY']);
289 if (0 >= $arProduct[
'QUANTITY'] && (
'Y' != $arProduct[
'QUANTITY_TRACE'] ||
'N' != $arProduct[
'CAN_BUY_ZERO']))
292 $result = $arProduct[
'QUANTITY'];
305 $currencyList = Currency\CurrencyManager::getCurrencyList();
307 return (isset($currencyList[
'RUR']) ?
'RUR' :
'RUB');
318 $this->onlyAvailableElements =
true;
320 $this->onlyAvailableElements =
false;
328 $minPriceCurrency =
"";
330 $baseCurrency = Currency\CurrencyManager::getBaseCurrency();
333 if ($this->xmlData[
'PRICE'] > 0)
335 $rsPrices = \CPrice::GetListEx(array(),array(
336 'PRODUCT_ID' => $productId,
337 'CATALOG_GROUP_ID' => $this->xmlData[
'PRICE'],
339 'GROUP_GROUP_ID' => array(2),
340 '+<=QUANTITY_FROM' => 1,
341 '+>=QUANTITY_TO' => 1,
345 if ($arPrice = $rsPrices->Fetch())
347 if ($arOptimalPrice = \CCatalogProduct::GetOptimalPrice(
356 $minPrice = $arOptimalPrice[
'RESULT_PRICE'][
'DISCOUNT_PRICE'];
357 $minPriceCurrency = $baseCurrency;
358 $minPriceRUR = \CCurrencyRates::ConvertCurrency($minPrice, $baseCurrency, $RUR);
359 $minPriceGroup = $arOptimalPrice[
'PRICE'][
'CATALOG_GROUP_ID'];
365 if ($arPrice = \CCatalogProduct::GetOptimalPrice(
374 $minPrice = $arPrice[
'RESULT_PRICE'][
'DISCOUNT_PRICE'];
375 $minPriceCurrency = $baseCurrency;
376 $minPriceRUR = \CCurrencyRates::ConvertCurrency($minPrice, $baseCurrency, $RUR);
377 $minPriceGroup = $arPrice[
'PRICE'][
'CATALOG_GROUP_ID'];
383 "MIN_RUB" => $minPriceRUR,
384 "MIN_GROUP" => $minPriceGroup,
385 "MIN_CURRENCY" => $minPriceCurrency
393 if ($detailPageUrl ==
'')
394 $detailPageUrl =
'/';
396 $detailPageUrl = str_replace(
' ',
'%20', $detailPageUrl);
398 $result =
"http://".$this->arIblock[
'SERVER_NAME'].Main\Text\HtmlFilter::encode($detailPageUrl);
407 if ($file = \CFile::GetFileArray($pictNo))
409 if(mb_substr($file[
"SRC"], 0, 1) ==
"/")
410 $strFile =
"http://".$this->arIblock[
'SERVER_NAME'].implode(
"/", array_map(
"rawurlencode", explode(
"/", $file[
"SRC"])));
411 elseif(preg_match(
"/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $file[
"SRC"], $match))
412 $strFile =
"http://".$match[2].
'/'.implode(
"/", array_map(
"rawurlencode", explode(
"/", $match[3])));
414 $strFile = $file[
"SRC"];
425 $arProperties = array();
427 $arUserTypeFormat = array();
429 foreach($arProperties as $key => $arProperty)
431 $arUserTypeFormat[$arProperty[
"ID"]] =
false;
432 if($arProperty[
"USER_TYPE"] <>
'')
434 $arUserType = \CIBlockProperty::GetUserType($arProperty[
"USER_TYPE"]);
435 if(array_key_exists(
"GetPublicViewHTML", $arUserType))
437 $arUserTypeFormat[$arProperty[
"ID"]] = $arUserType[
"GetPublicViewHTML"];
438 $arProperties[$key][
'PROPERTY_TYPE'] =
'USER_TYPE';
446 if (is_array($this->xmlData) && is_array($this->xmlData[
'XML_DATA']) && is_array($this->xmlData[
'XML_DATA'][
'PARAMS']))
448 foreach ($this->xmlData[
'XML_DATA'][
'PARAMS'] as $key => $propId)
451 $result[] = $this->
getValue($product,
'PARAM_'.$key, $propId, $arProperties, $arUserTypeFormat);
458 protected function getValue($arOffer, $param, $PROPERTY, $arProperties, $arUserTypeFormat)
462 $bParam = (strncmp($param,
'PARAM_', 6) == 0);
464 if (isset($arProperties[$PROPERTY]) && !empty($arProperties[$PROPERTY]))
466 $PROPERTY_CODE = $arProperties[$PROPERTY][
'CODE'];
468 isset($arOffer[
'PROPERTIES'][$PROPERTY_CODE])
469 ? $arOffer[
'PROPERTIES'][$PROPERTY_CODE]
470 : $arOffer[
'PROPERTIES'][$PROPERTY]
475 if(!is_array($arProperty[
"VALUE"]))
476 $arProperty[
"VALUE"] = array($arProperty[
"VALUE"]);
478 switch ($arProperties[$PROPERTY][
'PROPERTY_TYPE'])
481 foreach($arProperty[
"VALUE"] as $oneValue)
483 $value[] = call_user_func_array($arUserTypeFormat[$PROPERTY],
486 array(
"VALUE" => $oneValue),
487 array(
'MODE' =>
'SIMPLE_TEXT'),
493 $arCheckValue = array();
495 foreach ($arProperty[
'VALUE'] as &$intValue)
497 $intValue = (int)$intValue;
499 $arCheckValue[] = $intValue;
502 if (isset($intValue))
505 if (!empty($arCheckValue))
507 $dbRes = \CIBlockElement::GetList(array(), array(
'IBLOCK_ID' => $arProperties[$PROPERTY][
'LINK_IBLOCK_ID'],
'ID' => $arCheckValue),
false,
false, array(
'NAME'));
508 while ($arRes = $dbRes->Fetch())
510 $value[] = $arRes[
'NAME'];
516 $arCheckValue = array();
518 foreach ($arProperty[
'VALUE'] as &$intValue)
520 $intValue = (int)$intValue;
522 $arCheckValue[] = $intValue;
525 if (isset($intValue))
528 if (!empty($arCheckValue))
530 $dbRes = \CIBlockSection::GetList(array(), array(
'IBLOCK_ID' => $arProperty[
'LINK_IBLOCK_ID'],
'ID' => $arCheckValue),
false, array(
'NAME'));
531 while ($arRes = $dbRes->Fetch())
533 $value[] = $arRes[
'NAME'];
539 $value .= $arProperty[
'VALUE'];
543 foreach ($arProperty[
'VALUE'] as &$intValue)
545 $intValue = (int)$intValue;
548 if ($ar_file = \CFile::GetFileArray($intValue))
550 if(mb_substr($ar_file[
"SRC"], 0, 1) ==
"/")
551 $strFile =
"http://".$this->arIblock[
"SERVER_NAME"].implode(
"/", array_map(
"rawurlencode", explode(
"/", $ar_file[
"SRC"])));
552 elseif(preg_match(
"/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file[
"SRC"], $match))
553 $strFile =
"http://".$match[2].
'/'.implode(
"/", array_map(
"rawurlencode", explode(
"/", $match[3])));
555 $strFile = $ar_file[
"SRC"];
561 if (isset($intValue))
566 $value = $arProperty[
'VALUE'];
569 if(is_array($value) && count($value) == 1)
570 $value = implode(
"", $value);
574 $result[$param] = array(
575 "NAME" => $arProperties[$PROPERTY][
'NAME'],
581 $result[$param] = $value;
590 $boolCurrentSections =
false;
593 $dbElementGroups = \CIBlockElement::GetElementGroups($productId,
false, array(
'ID',
'ADDITIONAL_PROPERTY_ID'));
595 while ($arElementGroup = $dbElementGroups->Fetch())
597 if (0 < (
int)$arElementGroup[
'ADDITIONAL_PROPERTY_ID'])
600 $boolCurrentSections =
true;
602 if (in_array((
int)$arElementGroup[
"ID"], $this->arSectionIDs))
603 $result[] = $arElementGroup[
"ID"];
606 if (!$boolCurrentSections)
614 if (!empty($availGroups))
626 if (100 <= $this->cnt)
629 \CCatalogDiscount::ClearDiscountCache(array(
632 'PROPERTIES' =>
true,
639 if(!$obElement = $this->dbItems->GetNextElement())
642 $arItem = $obElement->GetFields();
643 $arItem[
'PROPERTIES'] = $obElement->GetProperties();
644 $arItem[
"QUANTITY"] = $this->
getQuantity($arItem[
"ID"]);
645 $arItem[
"PRICES"] = $this->
getPrices($arItem[
"ID"], $this->arIblock[
'LID']);
647 $arItem[
"DETAIL_PICTURE_URL"] = $this->
getPictureUrl((
int)$arItem[
"DETAIL_PICTURE"]);
648 $arItem[
"PREVIEW_PICTURE_URL"] = $this->
getPictureUrl((
int)$arItem[
"PREVIEW_PICTURE"]);
649 $arItem[
"PARAMS"] = $this->
getParams($arItem, $this->arIblock);
650 $arItem[
"DETAIL_PAGE_URL"] = $this->
getDetailPageUrl($arItem[
"~DETAIL_PAGE_URL"]);
getValue($arOffer, $param, $PROPERTY, $arProperties, $arUserTypeFormat)
getIblockProps($serverName)
getDetailPageUrl($detailPageUrl)
getParams($product, $arIblock)
getSections($selectedGroups)
getMaxSectionId(array $arAvailGroups)
getSectionIDs(array $availGroups)
setOnlyAvailableFlag($flag)
getPrices($productId, $siteId)
__construct($catalogType, $params)
getCategories($productId)