1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
PropertyValue.php
См. документацию.
1<?php
2
4
5use Bitrix\Catalog\Product\PropertyCatalogFeature;
8
17final class PropertyValue
18{
23 public static function getSkuPropertyDisplayValues(BaseSku $sku): string
24 {
25 if ($sku->isSimple())
26 {
27 return '';
28 }
29
30 $propertyValues = self::getPropertyValues(
31 $sku->getIblockId(),
32 [$sku->getId()]
33 );
34
35 $skuPropertyValues = $propertyValues[$sku->getId()] ?? [];
36
37 return self::getPropertyDisplayValues($skuPropertyValues);
38 }
39
44 public static function getSkuPropertyDisplayValuesMap(BaseSku $sku): array
45 {
46 if ($sku->isSimple())
47 {
48 return [];
49 }
50
51 $propertyValues = self::getPropertyValues(
52 $sku->getIblockId(),
53 [$sku->getId()]
54 );
55
56 $skuPropertyValues = $propertyValues[$sku->getId()] ?? [];
57
58 $result = [];
59
60 foreach ($skuPropertyValues as $property)
61 {
62 $displayValue = self::getPropertyDisplayValue($property);
63 if (!$displayValue)
64 {
65 continue;
66 }
67
68 $property['DISPLAY_VALUE'] = $displayValue;
69
70 $result[$property['CODE']] = $property;
71 }
72
73 return $result;
74 }
75
81 private static function getPropertyValues($skuIblockId, array $skuIds): array
82 {
83 $propertyIds = PropertyCatalogFeature::getOfferTreePropertyCodes($skuIblockId);
84 if ($propertyIds === null)
85 {
86 return [];
87 }
88
89 $propertyValues = [];
90 \CIBlockElement::GetPropertyValuesArray(
91 $propertyValues,
92 $skuIblockId,
93 ['ID' => $skuIds],
94 ['ID' => $propertyIds]
95 );
96
97 return $propertyValues;
98 }
99
104 public static function getPropertyValuesBySku(BaseSku $sku): array
105 {
106 return self::getPropertyValues($sku->getIblockId(), [$sku->getId()])[$sku->getId()];
107 }
108
113 private static function getPropertyDisplayValues(array $properties): string
114 {
115 $result = [];
116
117 foreach ($properties as $property)
118 {
119 $displayValue = self::getPropertyDisplayValue($property);
120 if (!$displayValue)
121 {
122 continue;
123 }
124
125 $result[] = $displayValue;
126 }
127
128 return implode(', ', $result);
129 }
130
135 public static function getPropertyDisplayValue(array $propertyValue): string
136 {
137 if (!empty($propertyValue['USER_TYPE']))
138 {
139 $userType = \CIBlockProperty::GetUserType($propertyValue['USER_TYPE']);
140 $searchMethod = $userType['GetSearchContent'] ?? null;
141
142 if ($searchMethod && is_callable($searchMethod))
143 {
144 $value = $searchMethod($propertyValue, ['VALUE' => $propertyValue['~VALUE']], []);
145 }
146 else
147 {
148 $value = '';
149 }
150 }
151 else
152 {
153 $value = $propertyValue['~VALUE'] ?? '';
154 }
155
156 if (is_array($value))
157 {
158 $value = implode(', ', $value);
159 }
160
161 $value = trim((string)$value);
162
163 return $value;
164 }
165}
static getPropertyDisplayValue(array $propertyValue)
Определения PropertyValue.php:135
static getSkuPropertyDisplayValues(BaseSku $sku)
Определения PropertyValue.php:23
static getPropertyValuesBySku(BaseSku $sku)
Определения PropertyValue.php:104
static getSkuPropertyDisplayValuesMap(BaseSku $sku)
Определения PropertyValue.php:44
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
Определения file_new.php:729
</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