PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/sale.bestsellers/templates/vertical/result_modifier.php

https://gitlab.com/alexprowars/bitrix
PHP | 402 lines | 352 code | 38 blank | 12 comment | 89 complexity | b8c4acae5ff26d6bc1afcecc801cf41a MD5 | raw file
  1. <?
  2. if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();
  3. /** @var CBitrixComponentTemplate $this */
  4. /** @var array $arParams */
  5. /** @var array $arResult */
  6. /** @global CDatabase $DB */
  7. if (!isset($arParams['LINE_ELEMENT_COUNT']))
  8. $arParams['LINE_ELEMENT_COUNT'] = 3;
  9. $arParams['LINE_ELEMENT_COUNT'] = intval($arParams['LINE_ELEMENT_COUNT']);
  10. if (2 > $arParams['LINE_ELEMENT_COUNT'] || 5 < $arParams['LINE_ELEMENT_COUNT'])
  11. $arParams['LINE_ELEMENT_COUNT'] = 3;
  12. $arParams['TEMPLATE_THEME'] = (string)($arParams['TEMPLATE_THEME']);
  13. if ('' != $arParams['TEMPLATE_THEME'])
  14. {
  15. $arParams['TEMPLATE_THEME'] = preg_replace('/[^a-zA-Z0-9_\-\(\)\!]/', '', $arParams['TEMPLATE_THEME']);
  16. if ('site' == $arParams['TEMPLATE_THEME'])
  17. {
  18. $templateId = COption::GetOptionString("main", "wizard_template_id", "eshop_bootstrap", SITE_ID);
  19. $templateId = (preg_match("/^eshop_adapt/", $templateId)) ? "eshop_adapt" : $templateId;
  20. $arParams['TEMPLATE_THEME'] = COption::GetOptionString('main', 'wizard_'.$templateId.'_theme_id', 'blue', SITE_ID);
  21. }
  22. if ('' != $arParams['TEMPLATE_THEME'])
  23. {
  24. if (!is_file($_SERVER['DOCUMENT_ROOT'].$this->GetFolder().'/themes/'.$arParams['TEMPLATE_THEME'].'/style.css'))
  25. $arParams['TEMPLATE_THEME'] = '';
  26. }
  27. }
  28. if ('' == $arParams['TEMPLATE_THEME'])
  29. $arParams['TEMPLATE_THEME'] = 'blue';
  30. if (!empty($arResult['ITEMS']))
  31. {
  32. $arEmptyPreview = false;
  33. $strEmptyPreview = $this->GetFolder() . '/images/no_photo.png';
  34. if (file_exists($_SERVER['DOCUMENT_ROOT'] . $strEmptyPreview))
  35. {
  36. $arSizes = getimagesize($_SERVER['DOCUMENT_ROOT'] . $strEmptyPreview);
  37. if (!empty($arSizes))
  38. {
  39. $arEmptyPreview = array(
  40. 'SRC' => $strEmptyPreview,
  41. 'WIDTH' => intval($arSizes[0]),
  42. 'HEIGHT' => intval($arSizes[1])
  43. );
  44. }
  45. unset($arSizes);
  46. }
  47. unset($strEmptyPreview);
  48. $arSKUPropList = array();
  49. $arSKUPropIDs = array();
  50. $arSKUPropKeys = array();
  51. $boolSKU = false;
  52. $strBaseCurrency = '';
  53. $boolConvert = isset($arResult['CONVERT_CURRENCY']['CURRENCY_ID']);
  54. //
  55. $skuPropList = array(); // array("id_catalog" => array(...))
  56. $skuPropIds = array(); // array("id_catalog" => array(...))
  57. $skuPropKeys = array(); // array("id_catalog" => array(...))
  58. if (!$boolConvert)
  59. $strBaseCurrency = CCurrency::GetBaseCurrency();
  60. $catalogs = array();
  61. foreach($arResult['CATALOGS'] as $catalog)
  62. {
  63. $offersCatalogId = (int)$catalog['OFFERS_IBLOCK_ID'];
  64. $offersPropId = (int)$catalog['OFFERS_PROPERTY_ID'];
  65. $catalogId = (int)$catalog['IBLOCK_ID'];
  66. $sku = false;
  67. if($offersCatalogId > 0 && $offersPropId > 0)
  68. $sku = array("IBLOCK_ID" => $offersCatalogId, "SKU_PROPERTY_ID" => $offersPropId, "PRODUCT_IBLOCK_ID" => $catalogId);
  69. if (!empty($sku) && is_array($sku))
  70. {
  71. $skuPropList[$catalogId] = CIBlockPriceTools::getTreeProperties(
  72. $sku,
  73. $arParams['OFFER_TREE_PROPS'][$offersCatalogId],
  74. array(
  75. 'PICT' => $arEmptyPreview,
  76. 'NAME' => '-'
  77. )
  78. );
  79. $needValues = array();
  80. CIBlockPriceTools::getTreePropertyValues($skuPropList[$catalogId], $needValues);
  81. $skuPropIds[$catalogId] = array_keys($skuPropList[$catalogId]);
  82. if (!empty($skuPropIds[$catalogId]))
  83. $skuPropKeys[$catalogId] = array_fill_keys($skuPropIds[$catalogId], false);
  84. }
  85. }
  86. $arNewItemsList = array();
  87. foreach ($arResult['ITEMS'] as $key => $arItem)
  88. {
  89. $arItem['CATALOG_QUANTITY'] = (
  90. 0 < $arItem['CATALOG_QUANTITY'] && is_float($arItem['CATALOG_MEASURE_RATIO'])
  91. ? floatval($arItem['CATALOG_QUANTITY'])
  92. : intval($arItem['CATALOG_QUANTITY'])
  93. );
  94. $arItem['CATALOG'] = false;
  95. $arItem['LABEL'] = false;
  96. if (!isset($arItem['CATALOG_SUBSCRIPTION']) || 'Y' != $arItem['CATALOG_SUBSCRIPTION'])
  97. $arItem['CATALOG_SUBSCRIPTION'] = 'N';
  98. // Item Label Properties
  99. $itemIblockId = $arItem['IBLOCK_ID'];
  100. $propertyName = isset($arParams['LABEL_PROP'][$itemIblockId]) ? $arParams['LABEL_PROP'][$itemIblockId] : false;
  101. if ($propertyName && isset($arItem['PROPERTIES'][$propertyName]))
  102. {
  103. $property = $arItem['PROPERTIES'][$propertyName];
  104. if (!empty($property['VALUE']))
  105. {
  106. if ('N' == $property['MULTIPLE'] && 'L' == $property['PROPERTY_TYPE'] && 'C' == $property['LIST_TYPE'])
  107. {
  108. $arItem['LABEL_VALUE'] = $property['NAME'];
  109. }
  110. else
  111. {
  112. $arItem['LABEL_VALUE'] = (is_array($property['VALUE'])
  113. ? implode(' / ', $property['VALUE'])
  114. : $property['VALUE']
  115. );
  116. }
  117. $arItem['LABEL'] = true;
  118. if (isset($arItem['DISPLAY_PROPERTIES'][$propertyName]))
  119. unset($arItem['DISPLAY_PROPERTIES'][$propertyName]);
  120. }
  121. unset($property);
  122. }
  123. // !Item Label Properties
  124. // item double images
  125. $productPictures = array(
  126. "PICT" => false,
  127. "SECOND_PICT" => false
  128. );
  129. if (isset($arParams['ADDITIONAL_PICT_PROP'][$itemIblockId]))
  130. {
  131. $productPictures = CIBlockPriceTools::getDoublePicturesForItem($arItem, $arParams['ADDITIONAL_PICT_PROP'][$itemIblockId]);
  132. }
  133. else
  134. {
  135. $productPictures = CIBlockPriceTools::getDoublePicturesForItem($arItem, false);
  136. }
  137. if (empty($productPictures['PICT']))
  138. $productPictures['PICT'] = $arEmptyPreview;
  139. if (empty($productPictures['SECOND_PICT']))
  140. $productPictures['SECOND_PICT'] = $productPictures['PICT'];
  141. $arItem['PREVIEW_PICTURE'] = $productPictures['PICT'];
  142. $arItem['PREVIEW_PICTURE_SECOND'] = $productPictures['SECOND_PICT'];
  143. $arItem['SECOND_PICT'] = true;
  144. $arItem['PRODUCT_PREVIEW'] = $productPictures['PICT'];
  145. $arItem['PRODUCT_PREVIEW_SECOND'] = $productPictures['SECOND_PICT'];
  146. // !item double images
  147. $arItem['CATALOG'] = true;
  148. if (!isset($arItem['CATALOG_TYPE']))
  149. $arItem['CATALOG_TYPE'] = CCatalogProduct::TYPE_PRODUCT;
  150. if (
  151. (CCatalogProduct::TYPE_PRODUCT == $arItem['CATALOG_TYPE'] || CCatalogProduct::TYPE_SKU == $arItem['CATALOG_TYPE'])
  152. && !empty($arItem['OFFERS'])
  153. )
  154. {
  155. $arItem['CATALOG_TYPE'] = CCatalogProduct::TYPE_SKU;
  156. }
  157. switch ($arItem['CATALOG_TYPE'])
  158. {
  159. case CCatalogProduct::TYPE_SET:
  160. $arItem['OFFERS'] = array();
  161. $arItem['CATALOG_MEASURE_RATIO'] = 1;
  162. $arItem['CATALOG_QUANTITY'] = 0;
  163. $arItem['CHECK_QUANTITY'] = false;
  164. break;
  165. case CCatalogProduct::TYPE_SKU:
  166. break;
  167. case CCatalogProduct::TYPE_PRODUCT:
  168. default:
  169. $arItem['CHECK_QUANTITY'] = ('Y' == $arItem['CATALOG_QUANTITY_TRACE'] && 'N' == $arItem['CATALOG_CAN_BUY_ZERO']);
  170. break;
  171. }
  172. // Offers
  173. if ($arItem['CATALOG'] && isset($arItem['OFFERS']) && !empty($arItem['OFFERS']))
  174. {
  175. $arSKUPropIDs = isset($skuPropIds[$arItem['IBLOCK_ID']]) ? $skuPropIds[$arItem['IBLOCK_ID']] : array();
  176. $arSKUPropList = isset($skuPropList[$arItem['IBLOCK_ID']]) ? $skuPropList[$arItem['IBLOCK_ID']] : array();
  177. $arSKUPropKeys = isset($skuPropKeys[$arItem['IBLOCK_ID']]) ? $skuPropKeys[$arItem['IBLOCK_ID']] : array();
  178. $arMatrixFields = $arSKUPropKeys;
  179. $arMatrix = array();
  180. $arNewOffers = array();
  181. $boolSKUDisplayProperties = false;
  182. $arItem['OFFERS_PROP'] = false;
  183. foreach ($arItem['OFFERS'] as $keyOffer => $arOffer)
  184. {
  185. $arRow = array();
  186. foreach ($arSKUPropIDs as $propkey => $strOneCode)
  187. {
  188. $arCell = array(
  189. 'VALUE' => 0,
  190. 'SORT' => PHP_INT_MAX,
  191. 'NA' => true
  192. );
  193. if (isset($arOffer['DISPLAY_PROPERTIES'][$strOneCode]))
  194. {
  195. $arMatrixFields[$strOneCode] = true;
  196. $arCell['NA'] = false;
  197. if ('directory' == $arSKUPropList[$strOneCode]['USER_TYPE'])
  198. {
  199. $intValue = $arSKUPropList[$strOneCode]['XML_MAP'][$arOffer['DISPLAY_PROPERTIES'][$strOneCode]['VALUE']];
  200. $arCell['VALUE'] = $intValue;
  201. }
  202. elseif ('L' == $arSKUPropList[$strOneCode]['PROPERTY_TYPE'])
  203. {
  204. $arCell['VALUE'] = intval($arOffer['DISPLAY_PROPERTIES'][$strOneCode]['VALUE_ENUM_ID']);
  205. }
  206. elseif ('E' == $arSKUPropList[$strOneCode]['PROPERTY_TYPE'])
  207. {
  208. $arCell['VALUE'] = intval($arOffer['DISPLAY_PROPERTIES'][$strOneCode]['VALUE']);
  209. }
  210. $arCell['SORT'] = $arSKUPropList[$strOneCode]['VALUES'][$arCell['VALUE']]['SORT'];
  211. }
  212. $arRow[$strOneCode] = $arCell;
  213. }
  214. $arMatrix[$keyOffer] = $arRow;
  215. CIBlockPriceTools::clearProperties($arOffer['DISPLAY_PROPERTIES'], $arParams['OFFER_TREE_PROPS'][$arOffer['IBLOCK_ID']]);
  216. $newOfferProps = array();
  217. if(!empty($arParams['PROPERTY_CODE'][$arOffer['IBLOCK_ID']]))
  218. {
  219. foreach($arParams['PROPERTY_CODE'][$arOffer['IBLOCK_ID']] as $propName)
  220. {
  221. if (isset($arOffer['DISPLAY_PROPERTIES'][$propName]) && is_array($arOffer['DISPLAY_PROPERTIES'][$propName]))
  222. $newOfferProps[$propName] = $arOffer['DISPLAY_PROPERTIES'][$propName];
  223. }
  224. }
  225. $arOffer['DISPLAY_PROPERTIES'] = $newOfferProps;
  226. $arOffer['CHECK_QUANTITY'] = ('Y' == $arOffer['CATALOG_QUANTITY_TRACE'] && 'N' == $arOffer['CATALOG_CAN_BUY_ZERO']);
  227. if (!isset($arOffer['CATALOG_MEASURE_RATIO']))
  228. $arOffer['CATALOG_MEASURE_RATIO'] = 1;
  229. if (!isset($arOffer['CATALOG_QUANTITY']))
  230. $arOffer['CATALOG_QUANTITY'] = 0;
  231. $arOffer['CATALOG_QUANTITY'] = (
  232. 0 < $arOffer['CATALOG_QUANTITY'] && is_float($arOffer['CATALOG_MEASURE_RATIO'])
  233. ? floatval($arOffer['CATALOG_QUANTITY'])
  234. : intval($arOffer['CATALOG_QUANTITY'])
  235. );
  236. $arOffer['CATALOG_TYPE'] = CCatalogProduct::TYPE_OFFER;
  237. CIBlockPriceTools::setRatioMinPrice($arOffer);
  238. $offerPictures = CIBlockPriceTools::getDoublePicturesForItem($arOffer, $arParams['ADDITIONAL_PICT_PROP'][$arOffer['IBLOCK_ID']]);
  239. $arOffer['OWNER_PICT'] = empty($offerPictures['PICT']);
  240. $arOffer['PREVIEW_PICTURE'] = false;
  241. $arOffer['PREVIEW_PICTURE_SECOND'] = false;
  242. $arOffer['SECOND_PICT'] = true;
  243. if (!$arOffer['OWNER_PICT'])
  244. {
  245. if (empty($offerPictures['SECOND_PICT']))
  246. $offerPictures['SECOND_PICT'] = $offerPictures['PICT'];
  247. $arOffer['PREVIEW_PICTURE'] = $offerPictures['PICT'];
  248. $arOffer['PREVIEW_PICTURE_SECOND'] = $offerPictures['SECOND_PICT'];
  249. }
  250. if ('' != $arParams['OFFER_ADD_PICT_PROP'] && isset($arOffer['DISPLAY_PROPERTIES'][$arParams['OFFER_ADD_PICT_PROP']]))
  251. unset($arOffer['DISPLAY_PROPERTIES'][$arParams['OFFER_ADD_PICT_PROP']]);
  252. $arNewOffers[$keyOffer] = $arOffer;
  253. }
  254. $arItem['OFFERS'] = $arNewOffers;
  255. $arUsedFields = array();
  256. $arSortFields = array();
  257. foreach ($arSKUPropIDs as $propkey => $strOneCode)
  258. {
  259. $boolExist = $arMatrixFields[$strOneCode];
  260. foreach ($arMatrix as $keyOffer => $arRow)
  261. {
  262. if ($boolExist)
  263. {
  264. if (!isset($arItem['OFFERS'][$keyOffer]['TREE']))
  265. $arItem['OFFERS'][$keyOffer]['TREE'] = array();
  266. $arItem['OFFERS'][$keyOffer]['TREE']['PROP_' . $arSKUPropList[$strOneCode]['ID']] = $arMatrix[$keyOffer][$strOneCode]['VALUE'];
  267. $arItem['OFFERS'][$keyOffer]['SKU_SORT_' . $strOneCode] = $arMatrix[$keyOffer][$strOneCode]['SORT'];
  268. $arUsedFields[$strOneCode] = true;
  269. $arSortFields['SKU_SORT_' . $strOneCode] = SORT_NUMERIC;
  270. }
  271. else
  272. {
  273. unset($arMatrix[$keyOffer][$strOneCode]);
  274. }
  275. }
  276. }
  277. $arItem['OFFERS_PROP'] = $arUsedFields;
  278. \Bitrix\Main\Type\Collection::sortByColumn($arItem['OFFERS'], $arSortFields);
  279. // Find Selected offer
  280. foreach($arItem['OFFERS'] as $ind => $offer)
  281. if($offer['SELECTED'])
  282. {
  283. $arItem['OFFERS_SELECTED'] = $ind;
  284. break;
  285. }
  286. $arMatrix = array();
  287. $intSelected = -1;
  288. $arItem['MIN_PRICE'] = false;
  289. foreach ($arItem['OFFERS'] as $keyOffer => $arOffer)
  290. {
  291. if (empty($arItem['MIN_PRICE']) && $arOffer['CAN_BUY'])
  292. {
  293. $intSelected = $keyOffer;
  294. $arItem['MIN_PRICE'] = (isset($arOffer['RATIO_PRICE']) ? $arOffer['RATIO_PRICE'] : $arOffer['MIN_PRICE']);
  295. }
  296. $arSKUProps = false;
  297. if (!empty($arOffer['DISPLAY_PROPERTIES']))
  298. {
  299. $boolSKUDisplayProperties = true;
  300. $arSKUProps = array();
  301. foreach ($arOffer['DISPLAY_PROPERTIES'] as &$arOneProp)
  302. {
  303. if ('F' == $arOneProp['PROPERTY_TYPE'])
  304. continue;
  305. $arSKUProps[] = array(
  306. 'NAME' => $arOneProp['NAME'],
  307. 'VALUE' => $arOneProp['DISPLAY_VALUE']
  308. );
  309. }
  310. unset($arOneProp);
  311. }
  312. $arOneRow = array(
  313. 'ID' => $arOffer['ID'],
  314. 'NAME' => $arOffer['~NAME'],
  315. 'TREE' => $arOffer['TREE'],
  316. 'DISPLAY_PROPERTIES' => $arSKUProps,
  317. 'PRICE' => (isset($arOffer['RATIO_PRICE']) ? $arOffer['RATIO_PRICE'] : $arOffer['MIN_PRICE']),
  318. 'SECOND_PICT' => $arOffer['SECOND_PICT'],
  319. 'OWNER_PICT' => $arOffer['OWNER_PICT'],
  320. 'PREVIEW_PICTURE' => $arOffer['PREVIEW_PICTURE'],
  321. 'PREVIEW_PICTURE_SECOND' => $arOffer['PREVIEW_PICTURE_SECOND'],
  322. 'CHECK_QUANTITY' => $arOffer['CHECK_QUANTITY'],
  323. 'MAX_QUANTITY' => $arOffer['CATALOG_QUANTITY'],
  324. 'STEP_QUANTITY' => $arOffer['CATALOG_MEASURE_RATIO'],
  325. 'QUANTITY_FLOAT' => is_double($arOffer['CATALOG_MEASURE_RATIO']),
  326. 'MEASURE' => $arOffer['~CATALOG_MEASURE_NAME'],
  327. 'CAN_BUY' => $arOffer['CAN_BUY'],
  328. 'BUY_URL' => $arOffer['~BUY_URL'],
  329. 'ADD_URL' => $arOffer['~ADD_URL'],
  330. );
  331. $arMatrix[$keyOffer] = $arOneRow;
  332. }
  333. if (-1 == $intSelected)
  334. $intSelected = 0;
  335. if (!$arMatrix[$intSelected]['OWNER_PICT'])
  336. {
  337. $arItem['PREVIEW_PICTURE'] = $arMatrix[$intSelected]['PREVIEW_PICTURE'];
  338. $arItem['PREVIEW_PICTURE_SECOND'] = $arMatrix[$intSelected]['PREVIEW_PICTURE_SECOND'];
  339. }
  340. $arItem['JS_OFFERS'] = $arMatrix;
  341. //$arItem['OFFERS_SELECTED'] = $intSelected;
  342. $arItem['OFFERS_PROPS_DISPLAY'] = $boolSKUDisplayProperties;
  343. }
  344. if ($arItem['CATALOG'] && CCatalogProduct::TYPE_PRODUCT == $arItem['CATALOG_TYPE'])
  345. {
  346. CIBlockPriceTools::setRatioMinPrice($arItem, true);
  347. }
  348. if (!empty($arItem['DISPLAY_PROPERTIES']))
  349. {
  350. foreach ($arItem['DISPLAY_PROPERTIES'] as $propKey => $arDispProp)
  351. {
  352. if ('F' == $arDispProp['PROPERTY_TYPE'])
  353. unset($arItem['DISPLAY_PROPERTIES'][$propKey]);
  354. }
  355. }
  356. $arItem['LAST_ELEMENT'] = 'N';
  357. $arNewItemsList[$key] = $arItem;
  358. }
  359. $arNewItemsList[$key]['LAST_ELEMENT'] = 'Y';
  360. $arResult['ITEMS'] = $arNewItemsList;
  361. $arResult['SKU_PROPS'] = $skuPropList;
  362. $arResult['DEFAULT_PICTURE'] = $arEmptyPreview;
  363. }
  364. ?>