1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ProductPicture.php
См. документацию.
1<?php
2
4
7
8final class ProductPicture
9{
10 private const CODE_PREVIEW_PICTURE = 'PREVIEW_PICTURE';
11 private const CODE_DETAIL_PICTURE = 'DETAIL_PICTURE';
12 private const CODE_MORE_PHOTO = \CIBlockPropertyTools::CODE_MORE_PHOTO;
13
14 public static function get(array $productIdList): ?array
15 {
16 if (!Loader::includeModule('iblock'))
17 {
18 return null;
19 }
20
21 if (empty($productIdList))
22 {
23 return null;
24 }
25
26 $result = [];
27 $productListToGetMorePhoto = [];
28
29 $iblockElementList = \CIBlockElement::GetList(
30 [],
31 [
32 'ID' => $productIdList,
33 ],
34 false,
35 false,
36 [
37 'ID',
38 'IBLOCK_ID',
39 ProductPicture::CODE_PREVIEW_PICTURE,
40 ProductPicture::CODE_DETAIL_PICTURE,
41 ],
42 );
43
44 while ($product = $iblockElementList->Fetch())
45 {
46 $productId = (int)$product['ID'];
47
48 if (!empty($product[ProductPicture::CODE_PREVIEW_PICTURE]))
49 {
50 $result[$productId] = (int)$product[ProductPicture::CODE_PREVIEW_PICTURE];
51 }
52 else if (!empty($product[ProductPicture::CODE_DETAIL_PICTURE]))
53 {
54 $result[$productId] = (int)$product[ProductPicture::CODE_DETAIL_PICTURE];
55 }
56 else
57 {
58 $productIblockId = (int)$product['IBLOCK_ID'];
59 $productListToGetMorePhoto[$productIblockId] ??= [];
60 $productListToGetMorePhoto[$productIblockId][] = $productId;
61 }
62 }
63
64 if (!empty($productListToGetMorePhoto))
65 {
66 $productMorePhoto = ProductPicture::getMorePhoto($productListToGetMorePhoto);
67 foreach ($productMorePhoto as $productId => $productPhotos)
68 {
69 $result[$productId] = array_shift($productPhotos);
70 }
71 }
72
73 return $result;
74 }
75
76 private static function getMorePhoto(array $productList): array
77 {
78 $result = [];
79
80 foreach ($productList as $iblockId => $productIdList)
81 {
82 $rawPropertyResult = [];
83 \CIBlockElement::GetPropertyValuesArray(
84 $rawPropertyResult,
86 [
87 'ID' => $productIdList,
88 ],
89 [
90 'CODE' => ProductPicture::CODE_MORE_PHOTO,
91 ],
92 [
93 'GET_RAW_DATA' => 'Y',
94 ],
95 );
96
97 foreach ($rawPropertyResult as $productId => $productProperty)
98 {
99 $productId = (int)$productId;
100
101 if (!empty($productProperty[ProductPicture::CODE_MORE_PHOTO]))
102 {
103 $photoValues = $productProperty[ProductPicture::CODE_MORE_PHOTO]['VALUE'];
104
105 if (empty($photoValues))
106 {
107 continue;
108 }
109
110 Collection::normalizeArrayValuesByInt($photoValues, false);
111
112 $result[$productId] = $photoValues;
113 }
114 }
115 }
116
117 return $result;
118 }
119}
Определения loader.php:13
const CODE_MORE_PHOTO
Определения iblockproptools.php:11
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$iblockId
Определения iblock_catalog_edit.php:30
$productIblockId
Определения iblock_catalog_edit.php:242