Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
product.php
1<?php
3
10
16{
17 private $groupByIblock = array();
18 private $columnsList = null;
19 private $parentsIds = array();
20 private $measuresIds = null;
21 private $siteId = null;
22 private $storesCount = null;
24 private $provider = null;
25 private $productsIds = array();
26 private $tmpId = '';
27
28 private $iblockData = null;
29 private $catalogData = null;
30
31 private $resultData = array();
32
33 private $useSliderCard = null;
34
44 public static function getData(array $productsIds, $siteId, array $columnsList = array(), $tmpId = "")
45 {
46 if(empty($productsIds))
47 return array();
48
49 if(!\Bitrix\Main\Loader::includeModule('iblock'))
50 return array();
51
52 if(!\Bitrix\Main\Loader::includeModule('catalog'))
53 return array();
54
55 $product = new self($productsIds, $siteId, $columnsList, $tmpId);
56 $product->fillIblockData();
57
58 if(count($product->resultData) <= 0)
59 return array();
60
61 $product->fillCatalogData();
62 $product->completeResultData();
63 $result = $product->getResultData();
64 return $result;
65 }
66
76 public static function getProviderData(array $productsData, $siteId, $userId = null, array &$errors = array())
77 {
78 if(empty($productsData))
79 return array();
80
81 if($siteId == '')
82 return array();
83
84 $context = array(
85 'SITE_ID' => $siteId
86 );
87
88 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
90 $orderClass = $registry->getOrderClassName();
91
92 $order = $orderClass::create($siteId);
93
94 if(intval($userId) > 0)
95 {
96 $order->setFieldNoDemand("USER_ID", intval($userId));
97 $context['USER_ID'] = $userId;
98 }
99
101 $basketClass = $registry->getBasketClassName();
102 $basket = $basketClass::create($siteId);
103 $order->setBasket($basket);
104
105 if(intval($userId) > 0)
106 {
107 $fUserId = Fuser::getIdByUserId(intval($userId));
108 $basket->setFUserId($fUserId);
109 }
110
111 foreach($productsData as $productFields)
112 {
113 if (isset($productFields['OFFER_ID']))
114 {
115 $productFields['PRODUCT_ID'] = $productFields['OFFER_ID'];
116 }
117
118 $r = Catalog\Product\Basket::addProductToBasket($basket, $productFields, $context);
119 if (!$r->isSuccess())
120 {
121 $errors = $r->getErrorMessages();
122 return null;
123 }
124 }
125
126 return Provider::getProductData($basket, array("PRICE", "AVAILABLE_QUANTITY"));
127 }
128
129 private function __construct(array $productsIds, $siteId, array $columnsList = array(), $tmpId = "")
130 {
131 $this->columnsList = $columnsList;
132 if (!in_array('PROPERTY_MORE_PHOTO', $columnsList, true))
133 {
134 $this->columnsList[] = 'PROPERTY_MORE_PHOTO';
135 }
136 $this->productsIds = $productsIds;
137 $this->siteId = $siteId;
138 $this->tmpId = $tmpId;
139
140 $this->provider = \CSaleBasket::GetProductProvider(
141 array(
142 "MODULE" => 'catalog',
143 "PRODUCT_PROVIDER_CLASS" => 'CCatalogProductProvider'
144 )
145 );
146
147 $this->useSliderCard = Catalog\Config\State::isProductCardSliderEnabled();
148 }
149
150 private function getResultData()
151 {
152 if($this->resultData === null)
153 throw new ArgumentNullException('this->resultData must be set earlier!');
154
155 return $this->resultData;
156 }
157
158 private function fillCatalogData()
159 {
160 $this->catalogData = [];
161 $this->measuresIds = [];
162
163 if (empty($this->iblockData))
164 {
165 return;
166 }
167
168 $setIds = [];
169
170 $res = Catalog\ProductTable::getList([
171 'select' => [
172 'ID', 'TYPE',
173 'AVAILABLE', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO',
174 'WEIGHT', 'WIDTH', 'LENGTH', 'HEIGHT',
175 'MEASURE', 'BARCODE_MULTI', 'VAT_ID'
176 ],
177 'filter' => ['@ID' => array_keys($this->iblockData)]
178 ]);
179 while ($row = $res->fetch())
180 {
181 $this->catalogData[$row['ID']] = $row;
182 $this->measuresIds[] = $row['MEASURE'];
183
184 $type = (int)$row['TYPE'];
185 if($type === Catalog\ProductTable::TYPE_SET)
186 {
187 $setIds[] = $row['ID'];
188 }
189
190 if (isset($this->resultData[$row['ID']]))
191 {
192 $this->resultData[$row['ID']]['TYPE'] = Sale\Internals\Catalog\ProductTypeMapper::getType($type);
193 $this->resultData[$row['ID']]['DIMENSIONS'] = serialize(
194 [
195 "WIDTH" => $row["WIDTH"],
196 "HEIGHT" => $row["HEIGHT"],
197 "LENGTH" => $row["LENGTH"]
198 ]
199 );
200
201 $this->resultData[$row['ID']]['AVAILABLE'] = (float)$row["QUANTITY"];
202 $this->resultData[$row['ID']]['WEIGHT'] = $row["WEIGHT"];
203 $this->resultData[$row['ID']]['BARCODE_MULTI'] = $row["BARCODE_MULTI"];
204 $this->resultData[$row['ID']]["SET_ITEMS"] = [];
205 $this->resultData[$row['ID']]["IS_SET_ITEM"] = "N";
206 $this->resultData[$row['ID']]["VAT_ID"] = $row["VAT_ID"];
207 $this->resultData[$row['ID']]["IS_SET_PARENT"] = "N"; //empty($arSetInfo) ? "N" : "Y";
208 }
209 }
210
211 if (!empty($setIds))
212 {
213 $this->fillSetInfo($setIds);
214 }
215 }
216
217 private function fillSetInfo($setIds)
218 {
219 if(!$this->provider)
220 return;
221
222 if(!method_exists($this->provider, 'GetSetItems'))
223 return;
224
225 $provider = $this->provider;
226 $childrenParent = array();
227 $itemsIds = array();
228 $items = array();
229
230 if ($this->tmpId == "")
231 $this->tmpId = randString(7);
232
233 foreach($setIds as $id)
234 {
235 if ($this->catalogData[$id]["TYPE"] != \CCatalogProduct::TYPE_SET)
236 continue;
237
238 $arSets = $provider::GetSetItems($id, \CSaleBasket::TYPE_SET);
239
240 if (empty($arSets))
241 continue;
242
243 foreach ($arSets as $arSetData)
244 {
245 foreach ($arSetData["ITEMS"] as $setItem)
246 {
247 $arSetItemParams = array();
248 $arSetItemParams["PARENT_OFFER_ID"] = $id;
249 $arSetItemParams["OFFER_ID"] = $setItem["PRODUCT_ID"];
250 $arSetItemParams["NAME"] = $setItem["NAME"];
251 $arSetItemParams["MODULE"] = $setItem["MODULE"];
252 $arSetItemParams["PRODUCT_PROVIDER_CLASS"] = $setItem["PRODUCT_PROVIDER_CLASS"];
253 $arSetItemParams["BARCODE_MULTI"] = $setItem["BARCODE_MULTI"];
254 $arSetItemParams["PRODUCT_TYPE"] = $setItem["TYPE"];
255 $arSetItemParams["WEIGHT"] = $setItem["WEIGHT"];
256 $arSetItemParams["SET_ITEMS"] = "";
257 $arSetItemParams["OLD_PARENT_ID"] = $id."_tmp".$this->tmpId;
258 $arSetItemParams["IS_SET_ITEM"] = "Y";
259 $arSetItemParams["IS_SET_PARENT"] = "N";
260 $arSetItemParams["PROVIDER_DATA"] = serialize($setItem);
261 $items[$id][$setItem["PRODUCT_ID"]] = $arSetItemParams;
262
263 if(!in_array($setItem["PRODUCT_ID"], $itemsIds))
264 $itemsIds[] = $setItem["PRODUCT_ID"];
265
266 if(!is_array($childrenParent[$setItem["PRODUCT_ID"]]))
267 $childrenParent[$setItem["PRODUCT_ID"]] = array();
268
269 $childrenParent[$setItem["PRODUCT_ID"]][] = $id;
270 }
271 }
272
273 $tmpData = self::getData($itemsIds, $this->siteId, $this->columnsList, $this->tmpId);
274
275 foreach($childrenParent as $childId => $childData)
276 {
277 if(!is_array($childData))
278 continue;
279
280 if(empty($tmpData[$childId]))
281 continue;
282
283 foreach($childData as $productId)
284 {
285 if(empty($items[$productId][$childId]))
286 continue;
287
288 foreach($this->resultData[$productId]['SET_ITEMS'] as $set)
289 if($set['OFFER_ID'] == $childId)
290 continue(2);
291
292 $this->resultData[$productId]['SET_ITEMS'][] = array_merge($tmpData[$childId], $items[$productId][$childId]);
293 $this->resultData[$productId]["IS_SET_PARENT"] = empty($this->resultData[$productId]["SET_ITEMS"]) ? 'N' : 'Y';
294 $this->resultData[$productId]["OLD_PARENT_ID"] = empty($this->resultData[$productId]["SET_ITEMS"]) ? '' : $productId."_tmp".$this->tmpId;
295 $this->resultData[$productId]["PRODUCT_TYPE"] = empty($this->resultData[$productId]["SET_ITEMS"]) ? "" : \CSaleBasket::TYPE_SET;
296 }
297 }
298 }
299 }
300
301 private function fillIblockData()
302 {
303 $select = array("ID", "NAME", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE", "XML_ID", "IBLOCK_EXTERNAL_ID");
304 $blockedFields = array(
305 'QUANTITY' => true,
306 'AVAILABLE' => true,
307 'PRICE' => true
308 );
309 foreach ($this->columnsList as $field)
310 {
311 if (isset($blockedFields[$field]))
312 continue;
313 $select[] = $field;
314 }
315
316 if (!empty($this->productsIds))
317 {
318 $parentList = \CCatalogSku::getProductList($this->productsIds);
319 if (!is_array($parentList))
320 $parentList = array();
321 $simpleProducts = array();
322 foreach ($this->productsIds as $id)
323 {
324 if (isset($parentList[$id]))
325 {
326 $info = $parentList[$id];
327
328 $this->resultData[$id] = array(
329 "PRODUCT_ID" => $info["ID"],
330 "IBLOCK_ID" => $info["IBLOCK_ID"],
331 "OFFERS_IBLOCK_ID" => $info["OFFER_IBLOCK_ID"]
332 );
333 $this->parentsIds[] = $info["ID"];
334
335 if(!isset($this->groupByIblock[$info['OFFER_IBLOCK_ID']]))
336 $this->groupByIblock[$info['OFFER_IBLOCK_ID']] = array();
337
338 $this->groupByIblock[$info['OFFER_IBLOCK_ID']][] = $id;
339
340 if(!isset($this->groupByIblock[$info['IBLOCK_ID']]))
341 $this->groupByIblock[$info['IBLOCK_ID']] = array();
342
343 $this->groupByIblock[$info['IBLOCK_ID']][] = $info["ID"];
344
345 unset($info);
346 }
347 else
348 {
349 $simpleProducts[$id] = $id;
350 }
351 }
352 unset($id);
353 unset($parentList);
354
355 if (!empty($simpleProducts))
356 {
357 $simpleIblock = \CIBlockElement::GetIBlockByIDList($simpleProducts);
358 foreach ($simpleIblock as $id => $iblockId)
359 {
360 $this->resultData[$id] = array(
361 "PRODUCT_ID" => $id,
362 "IBLOCK_ID" => $iblockId,
363 "OFFERS_IBLOCK_ID" => 0
364 );
365
366 if(!isset($this->groupByIblock[$iblockId]))
367 $this->groupByIblock[$iblockId] = array();
368
369 $this->groupByIblock[$iblockId][] = $id;
370 }
371 unset($id, $iblockId, $simpleIblock);
372 }
373 unset($simpleProducts);
374 }
375
376 $this->iblockData = array();
377 $ppData = getProductProps(array_merge($this->productsIds, $this->parentsIds), $select);
378
379 foreach($ppData as $id => $fields)
380 {
381 if(empty($ppData[$id]))
382 continue;
383
384 foreach($fields as $k => $v)
385 if(mb_substr($k, 0, 1) == '~')
386 $fields[mb_substr($k, 1)] = $v;
387
388 $this->iblockData[$id] = $ppData[$id];
389 $this->iblockData[$id]["PRODUCT_PROPS_VALUES"] = $this->createProductPropsValues($id);
390
391 if(!in_array($id, $this->productsIds))
392 continue;
393
394 $this->resultData[$id] = array_merge(
395 $this->resultData[$id],
396 array_intersect_key(
397 $this->iblockData[$id],
398 array_flip(
399 $this->columnsList
400 )));
401
402 $this->resultData[$id]["OFFER_ID"] = $id;
403 $this->resultData[$id]["NAME"] = $fields["NAME"];
404 $this->resultData[$id]["PRODUCT_XML_ID"] = $fields["XML_ID"];
405 $this->resultData[$id]["CATALOG_XML_ID"] = $fields["~IBLOCK_EXTERNAL_ID"];
406 $this->resultData[$id]["PRODUCT_PROPS_VALUES"] = $this->iblockData[$id]["PRODUCT_PROPS_VALUES"];
407 $this->resultData[$id]['EDIT_PAGE_URL'] = $this->createEditPageUrl($fields);
408 }
409
410 $notFound = array_diff($this->productsIds, array_keys($this->iblockData));
411
412 if(!empty($notFound))
413 {
414 foreach($notFound as $id)
415 {
416 unset($this->resultData[$id]);
417 unset(
418 $this->productsIds[
419 array_search(
420 $id,
421 $this->productsIds
422 )
423 ]
424 );
425 }
426 }
427 return;
428 }
429
430 private static function isOffer($productData)
431 {
432 return intval($productData['PRODUCT_ID']) != intval($productData['OFFER_ID']);
433 }
434
435 private function completeResultData()
436 {
437 if(empty($this->resultData))
438 return;
439
440 foreach($this->resultData as $productId => $productData)
441 {
442 $this->resultData[$productId]['PROPERTIES'] = array();
443 $this->resultData[$productId]['PICTURE_URL'] = $this->createImageUrl($productId);
444 $this->resultData[$productId]['MODULE'] = "catalog";
445 $this->resultData[$productId]["PRODUCT_PROVIDER_CLASS"] = '\Bitrix\Catalog\Product\CatalogProvider';
446 $this->resultData[$productId]["STORES"] = $this->getStoresData($productId);
447
448 if($this->isOffer($productData) && !empty($this->iblockData[$productData['PRODUCT_ID']]))
449 {
450 $parentData = $this->iblockData[$productData['PRODUCT_ID']];
451
452 if(is_array($parentData['PRODUCT_PROPS_VALUES']))
453 {
454 foreach($parentData['PRODUCT_PROPS_VALUES'] as $fieldId => $fieldValue)
455 {
456 if(!isset($productData['PRODUCT_PROPS_VALUES'][$fieldId])
457 || (isset($productData['PRODUCT_PROPS_VALUES'][$fieldId]) && is_null($productData['PRODUCT_PROPS_VALUES'][$fieldId]))
458 )
459 {
460 $this->resultData[$productId]["PRODUCT_PROPS_VALUES"][$fieldId] = $fieldValue;
461 }
462 }
463 }
464
465 if(mb_strpos($this->iblockData[$productId]["XML_ID"], '#') === false)
466 {
467 $parentXmlId = strval($parentData['XML_ID']);
468 $this->resultData[$productId]['PRODUCT_XML_ID'] = $parentXmlId.'#'.$this->iblockData[$productId]['XML_ID'];
469 }
470 }
471
472 if(is_array($this->resultData[$productId]['PRODUCT_PROPS_VALUES']))
473 {
474 foreach($this->resultData[$productId]['PRODUCT_PROPS_VALUES'] as $fieldId => $fieldValue)
475 {
476 if(is_null($fieldValue))
477 {
478 $this->resultData[$productId]['PRODUCT_PROPS_VALUES'][$fieldId] = '&nbsp';
479 }
480 }
481 }
482 }
483
484 $this->fillPropsData();
485 $this->fillMeasures();
486 $this->fillMeasuresRatio();
487 }
488
489 private function fillPropsData()
490 {
491 if(empty($this->resultData))
492 return;
493
494 foreach($this->groupByIblock as $iblockId => $elIds)
495 {
496 $exists = false;
497 foreach ($elIds as $oneId)
498 {
499 if (isset($this->resultData[$oneId]))
500 {
501 $exists = true;
502 break;
503 }
504 }
505 if ($exists)
506 {
507 $basketProperties = Catalog\Product\PropertyCatalogFeature::getBasketPropertyCodes($iblockId);
508 if (empty($basketProperties))
509 continue;
510 \CIBlockElement::GetPropertyValuesArray(
511 $this->resultData,
512 $iblockId,
513 array(
514 'ID' => $elIds,
515 'IBLOCK_ID' => $iblockId
516 ),
517 array(
518 'ID' => $basketProperties
519 ),
520 array(
521 'PROPERTY_FIELDS' => array(
522 'ID', 'IBLOCK_ID', 'NAME', 'CODE', 'PROPERTY_TYPE',
523 'MULTIPLE', 'LINK_IBLOCK_ID',
524 'USER_TYPE', 'USER_TYPE_SETTINGS',
525 'LIST_TYPE',
526 )
527 )
528 );
529 }
530 }
531
532 foreach($this->resultData as $elId => $elData)
533 {
534 if(isset($elData['PROPERTIES']))
535 {
536 $props = $this->formatProps($elData['PROPERTIES']);
537 unset($this->resultData[$elId]['PROPERTIES']);
538
539 if($elData["CATALOG_XML_ID"] <> '')
540 {
541 $props[] = array(
542 "ID" => 0,
543 "NAME" => "Catalog XML_ID",
544 "CODE" => "CATALOG.XML_ID",
545 "VALUE" => $elData['CATALOG_XML_ID']
546 );
547 }
548
549 if($elData["PRODUCT_XML_ID"] <> '')
550 {
551 $props[] = array(
552 "ID" => 0,
553 "NAME" => "Product XML_ID",
554 "CODE" => "PRODUCT.XML_ID",
555 "VALUE" => $elData["PRODUCT_XML_ID"]
556 );
557 }
558
559 if(empty($props))
560 continue;
561
562 $this->resultData[$elId]['PROPS'] = $props;
563 }
564 }
565 }
566
567 //creators
568 private static function formatProps(array $properties)
569 {
570 if(empty($properties))
571 return array();
572
573 $result = array();
574
575 foreach ($properties as $prop)
576 {
577 if (
578 (isset($prop['XML_ID']) && $prop['XML_ID'] === 'CML2_LINK')
579 || $prop['PROPERTY_TYPE'] == 'F'
580 )
581 {
582 continue;
583 }
584
585 if (is_array($prop["VALUE"]) && empty($prop["VALUE"]))
586 {
587 continue;
588 }
589
590 if (!is_array($prop["VALUE"]) && $prop["VALUE"] == '')
591 {
592 continue;
593 }
594
595 $displayProperty = \CIBlockFormatProperties::GetDisplayValue(array(), $prop, '');
596
597 $mxValues = '';
598
599 if ('E' == $prop['PROPERTY_TYPE'])
600 {
601 if (!empty($displayProperty['LINK_ELEMENT_VALUE']))
602 {
603 $mxValues = array();
604
605 foreach ($displayProperty['LINK_ELEMENT_VALUE'] as $arTempo)
606 $mxValues[] = $arTempo['NAME'].' ['.$arTempo['ID'].']';
607 }
608 }
609 elseif ('G' == $prop['PROPERTY_TYPE'])
610 {
611 if (!empty($displayProperty['LINK_SECTION_VALUE']))
612 {
613 $mxValues = array();
614
615 foreach ($displayProperty['LINK_SECTION_VALUE'] as $arTempo)
616 $mxValues[] = $arTempo['NAME'].' ['.$arTempo['ID'].']';
617 }
618 }
619 if (empty($mxValues))
620 {
621 $mxValues = $displayProperty["DISPLAY_VALUE"];
622 }
623
624 $result[] = array(
625 'ID' => $prop["ID"],
626 'CODE' => htmlspecialcharsback($prop['CODE']),
627 'NAME' => htmlspecialcharsback($prop["NAME"]),
628 'VALUE' => htmlspecialcharsback(strip_tags(is_array($mxValues) ? implode("/ ", $mxValues) : $mxValues))
629 );
630 }
631
632 return $result;
633 }
634
635 private function createProductPropsValues($productId)
636 {
637 if(intval($productId) <= 0)
638 return array();
639
640 $result = array();
641 $fields = $this->iblockData[$productId];
642
643 foreach ($fields as $fieldId => $fieldValue)
644 {
645 if (strncmp($fieldId, 'PROPERTY_', 9) == 0 && mb_substr($fieldId, -6) == "_VALUE")
646 {
647 $propertyInfo = $this->getPropertyInfo(str_replace("_VALUE", "", $fieldId));
648 $code = $propertyInfo['CODE'] <> '' ? $propertyInfo['CODE'] : $propertyInfo['ID'];
649 $keyResult = 'PROPERTY_'.$code.'_VALUE';
650 $result[$keyResult] = self::getIblockPropInfo($fieldValue, $propertyInfo, array("WIDTH" => 90, "HEIGHT" => 90));
651 }
652 }
653
654 return $result;
655 }
656
657
658 private function preparePropertyInfo()
659 {
660 $result = array();
661 $codes = array();
662
663 foreach($this->columnsList as $column)
664 {
665 if(strncmp($column, 'PROPERTY_', 9) != 0)
666 continue;
667
668 $propertyCode = mb_substr($column, 9);
669
670 if ($propertyCode == '')
671 continue;
672
673 $codes[] = $propertyCode;
674 }
675
676 $dbRes = PropertyTable::getList(array(
677 'filter' => array(
678 'LOGIC' => 'OR',
679 "=CODE" => $codes,
680 "=ID" => $codes
681 )
682 ));
683
684 while($propData = $dbRes->fetch())
685 {
686 $code = $propData['CODE'] <> '' ? $propData['CODE'] : $propData['ID'];
687 $result['PROPERTY_'.mb_strtoupper($code)] = $propData;
688 }
689
690 return $result;
691 }
692
693 private function getPropertyInfo($fieldId)
694 {
695 static $propsInfo = null;
696
697 if($propsInfo === null)
698 $propsInfo = $this->preparePropertyInfo();
699
700 return isset($propsInfo[$fieldId]) ? $propsInfo[$fieldId] : array();
701 }
702
703 private function createImageUrl($productId)
704 {
705 $imgUrl = '';
706
707 $imgCode = $this->getImageId($this->iblockData[$productId]);
708
709 if ($imgCode == 0 && $this->isOffer($this->resultData[$productId]))
710 {
711 if(!empty($this->iblockData[$this->resultData[$productId]['PRODUCT_ID']]))
712 {
713 $imgCode = $this->getImageId($this->iblockData[$this->resultData[$productId]['PRODUCT_ID']]);
714 }
715 }
716
717 if ($imgCode > 0)
718 {
719 $arFile = \CFile::GetFileArray($imgCode);
720 $arImgProduct = \CFile::ResizeImageGet($arFile, array('width'=>80, 'height'=>80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
721
722 if (is_array($arImgProduct))
723 $imgUrl = $arImgProduct["src"];
724 }
725
726 return $imgUrl;
727 }
728
729 private function getImageId(array $product): int
730 {
731 $fieldImage = 0;
732 if (isset($product['PREVIEW_PICTURE']) && (int)$product['PREVIEW_PICTURE'] > 0)
733 {
734 $fieldImage = (int)$product['PREVIEW_PICTURE'];
735 }
736 elseif (isset($product['DETAIL_PICTURE']) && (int)$product['DETAIL_PICTURE'] > 0)
737 {
738 $fieldImage = (int)$product['DETAIL_PICTURE'];
739 }
740
741 $propertyImage = 0;
742 if (isset($product['PROPERTY_MORE_PHOTO_VALUE']))
743 {
744 if (is_array($product['PROPERTY_MORE_PHOTO_VALUE']))
745 {
746 $propertyImage = (int)reset($product['PROPERTY_MORE_PHOTO_VALUE']);
747 }
748 elseif ((int)$product['PROPERTY_MORE_PHOTO_VALUE'] > 0)
749 {
750 $propertyImage = (int)$product['PROPERTY_MORE_PHOTO_VALUE'];
751 }
752 }
753
754 if ($this->useSliderCard)
755 {
756 $result = ($propertyImage > 0 ? $propertyImage : $fieldImage);
757 }
758 else
759 {
760 $result = ($fieldImage > 0 ? $fieldImage : $propertyImage);
761 }
762 unset($propertyImage, $fieldImage);
763
764 return $result;
765 }
766
767 private static function createEditPageUrl(array $productData)
768 {
769
770 if(intval($productData['IBLOCK_ID']) <= 0 || intval($productData['ID']) <= 0)
771 return '';
772
773 $result = \CIBlock::GetAdminElementEditLink(
774 intval($productData['IBLOCK_ID']),
775 intval($productData['ID']),
776 array(
777 "find_section_section" => (intval($productData['IBLOCK_SECTION_ID']) > 0 ? intval($productData['IBLOCK_SECTION_ID']) : null),
778 'WF' => 'Y'
779 ));
780
781 return $result;
782 }
783
784 private function fillMeasures()
785 {
786 $measures = array();
787 $defaultMeasure = \CCatalogMeasure::getDefaultMeasure(true, true);
788 $defaultMeasureText = ($defaultMeasure["SYMBOL_RUS"] != '' ? $defaultMeasure["SYMBOL_RUS"] : $defaultMeasure["SYMBOL_INTL"]);
789 $defaultMeasureCode = 0;
790 $settedIds = array();
791
792 $dbRes = \CCatalogMeasure::GetList(
793 array(),
794 array("ID" => $this->measuresIds),
795 false,
796 false,
797 array("ID", "CODE", "SYMBOL_RUS", "SYMBOL_INTL")
798 );
799
800 while ($measure = $dbRes->Fetch())
801 $measures[$measure['ID']] = $measure;
802
803 foreach($this->catalogData as $productId => $productFields)
804 {
805 if(!isset($this->resultData[$productId]))
806 continue;
807
808 $this->resultData[$productId]["MEASURE_TEXT"] = $defaultMeasureText;
809 $this->resultData[$productId]["MEASURE_CODE"] = $defaultMeasureCode;
810
811 if (empty($measures[$productFields['MEASURE']]) || !is_array($measures[$productFields['MEASURE']]))
812 continue;
813
814 $measure = $measures[$productFields['MEASURE']];
815
816 $this->resultData[$productId]["MEASURE_TEXT"] = ($measure["SYMBOL_RUS"] != '' ? $measure["SYMBOL_RUS"] : $measure["SYMBOL_INTL"]);
817 $this->resultData[$productId]["MEASURE_CODE"] = $measure["CODE"] != '' ? $measure["CODE"] : $defaultMeasureText;
818
819 $settedIds[] = $productId;
820 }
821
822 $needToSet = array_diff_key($this->resultData, array_flip($settedIds));
823
824 foreach($needToSet as $productId => $fields)
825 {
826 if(!isset($fields['MEASURE_CODE']))
827 $this->resultData[$productId]['MEASURE_CODE'] = $defaultMeasureCode;
828
829 if(!empty($fields['MEASURE_TEXT']))
830 $this->resultData[$productId]["MEASURE_TEXT"] = $defaultMeasureText;
831 }
832 }
833
834 private function fillMeasuresRatio()
835 {
836 $dbRes = \Bitrix\Catalog\MeasureRatioTable::getList(array(
837 'select' => array('*'),
838 'filter' => array("@PRODUCT_ID" => array_keys($this->resultData), '=IS_DEFAULT' => 'Y')
839 ));
840
841 while($ratio = $dbRes->fetch())
842 {
843 if(!isset($this->resultData[$ratio['PRODUCT_ID']]))
844 continue;
845
846 $this->resultData[$ratio['PRODUCT_ID']]['MEASURE_RATIO'] = $ratio["RATIO"];
847 }
848
849 foreach($this->resultData as $productId => $fields)
850 {
851 if(!isset($fields['MEASURE_RATIO']))
852 $this->resultData[$productId]['MEASURE_RATIO'] = 1;
853 }
854 }
855
856 private function getStoresData($productId)
857 {
858 $result = array();
859
860 if(!$this->provider)
861 return array();
862
863 $productProvider = $this->provider;
864
865 if($this->storesCount === null)
866 $this->storesCount = $productProvider::GetStoresCount(array("SITE_ID" => $this->siteId));
867
868 if(intval($this->storesCount <= 0))
869 return array();
870
871 $stores = $productProvider::GetProductStores(array("PRODUCT_ID" => $productId, "SITE_ID" => $this->siteId));
872
873 if($stores)
874 $result = $stores;
875
876 return $result;
877 }
878
879 private static function getIblockPropInfo($value, $propData, $arSize = array("WIDTH" => 90, "HEIGHT" => 90), $orderId = 0)
880 {
881 $res = "";
882
883 if ($propData["MULTIPLE"] === "Y")
884 {
885 $arVal = array();
886 if (!is_array($value))
887 {
888 $value = (string)$value;
889 if (mb_strpos($value, ",") !== false)
890 {
891 $arVal = explode(",", $value);
892 }
893 else
894 {
895 $arVal[] = $value;
896 }
897 }
898 else
899 {
900 $arVal = $value;
901 }
902
903 if (count($arVal) > 0)
904 {
905 foreach ($arVal as $key => $val)
906 {
907 if ($propData["PROPERTY_TYPE"] === "F")
908 {
909 $val = (string)$val;
910 if ($res <> '')
911 {
912 $res .= "<br/> ".self::showImageOrDownloadLink(trim($val), $orderId, $arSize);
913 }
914 else
915 {
916 $res = self::showImageOrDownloadLink(trim($val), $orderId, $arSize);
917 }
918 }
919 else
920 {
921 if ($res <> '')
922 {
923 $res .= ", ".$val;
924 }
925 else
926 {
927 $res = $val;
928 }
929 }
930 }
931 }
932 }
933 else
934 {
935 if ($propData["PROPERTY_TYPE"] === "F")
936 {
937 $res = self::showImageOrDownloadLink($value, $orderId, $arSize);
938 }
939 elseif($propData["PROPERTY_TYPE"] === "S" && $propData["USER_TYPE"] === "HTML" && isset($value["TEXT"]))
940 {
941 $res = $value["TEXT"];
942 }
943 else
944 {
945 $res = $value;
946 }
947 }
948
949 if ($res == '')
950 {
951 $res = null;
952 }
953
954 return $res;
955 }
956
957 private static function showImageOrDownloadLink($fileId, $orderId = 0, $arSize = array("WIDTH" => 90, "HEIGHT" => 90))
958 {
959 $resultHTML = "";
960 $arFile = \CFile::GetFileArray($fileId);
961
962 if ($arFile)
963 {
964 $isImage = \CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"]);
965 if ($isImage)
966 $resultHTML = \CFile::ShowImage($arFile["ID"], $arSize["WIDTH"], $arSize["HEIGHT"], "border=0", "", true);
967 else
968 $resultHTML = "<a href=\"sale_order_detail.php?ID=".$orderId."&download=Y&file_id=".$arFile["ID"]."&".bitrix_sessid_get()."\">".$arFile["ORIGINAL_NAME"]."</a>";
969 }
970
971 return $resultHTML;
972 }
973}
static getData(array $productsIds, $siteId, array $columnsList=array(), $tmpId="")
Definition product.php:44