11if (Loader::includeModule(
'iblock'))
13 class PropertyCatalogFeature
extends Iblock\Model\PropertyFeature
15 const FEATURE_ID_BASKET_PROPERTY =
'IN_BASKET';
16 const FEATURE_ID_OFFER_TREE_PROPERTY =
'OFFER_TREE';
24 public static function handlerPropertyFeatureBuildList(Main\Event $event): Main\EventResult
28 $property = $event->getParameter(
'property');
29 $description = $event->getParameter(
'description');
31 if (self::checkBasketProperty($property, $description))
34 'MODULE_ID' =>
'catalog',
35 'FEATURE_ID' => self::FEATURE_ID_BASKET_PROPERTY,
36 'FEATURE_NAME' =>
Loc::getMessage(
'PROPERTY_CATALOG_FEATURE_NAME_BASKET_PROPERTY')
39 if (self::checkOfferTreeProperty($property, $description))
42 'MODULE_ID' =>
'catalog',
43 'FEATURE_ID' => self::FEATURE_ID_OFFER_TREE_PROPERTY,
44 'FEATURE_NAME' =>
Loc::getMessage(
'PROPERTY_CATALOG_FEATURE_NAME_SKU_TREE_PROPERTY')
47 unset($description, $property);
49 return new Main\EventResult(Main\EventResult::SUCCESS, $list);
68 public static function getBasketPropertyCodes($iblockId, array $parameters = []): ?array
70 $iblockId = (int)$iblockId;
74 $catalog = \CCatalogSku::GetInfoByIBlock($iblockId);
78 if (!self::isEnabledFeatures())
79 return self::getBasketPropertyByTypes($catalog, $parameters);
82 switch ($catalog[
'CATALOG_TYPE'])
84 case \CCatalogSku::TYPE_CATALOG:
85 case \CCatalogSku::TYPE_PRODUCT:
86 case \CCatalogSku::TYPE_FULL:
91 '=PROPERTY.MULTIPLE' =>
'Y',
92 '@PROPERTY.PROPERTY_TYPE' => [
93 Iblock\PropertyTable::TYPE_ELEMENT,
94 Iblock\PropertyTable::TYPE_SECTION,
95 Iblock\PropertyTable::TYPE_LIST,
96 Iblock\PropertyTable::TYPE_NUMBER,
97 Iblock\PropertyTable::TYPE_STRING
101 '=PROPERTY.MULTIPLE' =>
'N',
102 '@PROPERTY.PROPERTY_TYPE' => [
103 Iblock\PropertyTable::TYPE_ELEMENT,
104 Iblock\PropertyTable::TYPE_LIST
110 case \CCatalogSku::TYPE_OFFERS:
112 '!=PROPERTY.PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_FILE,
113 '!=PROPERTY.ID' => $catalog[
'SKU_PROPERTY_ID']
119 if ($filter ===
null)
122 $filter[
'=MODULE_ID'] =
'catalog';
123 $filter[
'=FEATURE_ID'] = self::FEATURE_ID_BASKET_PROPERTY;
125 return self::getFilteredPropertyCodes($iblockId, $filter, $parameters);
144 public static function getOfferTreePropertyCodes($iblockId, array $parameters = []): ?array
146 $iblockId = (int)$iblockId;
150 $catalog = \CCatalogSku::GetInfoByOfferIBlock($iblockId);
154 if (!self::isEnabledFeatures())
155 return self::getOfferTreePropertyByTypes($catalog, $parameters);
158 '=MODULE_ID' =>
'catalog',
159 '=FEATURE_ID' => self::FEATURE_ID_OFFER_TREE_PROPERTY,
160 '=PROPERTY.MULTIPLE' =>
'N',
161 '!=PROPERTY.ID' => $catalog[
'SKU_PROPERTY_ID'],
165 '@PROPERTY.PROPERTY_TYPE' => [
166 Iblock\PropertyTable::TYPE_ELEMENT,
167 Iblock\PropertyTable::TYPE_LIST
171 '=PROPERTY.PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_STRING,
172 '=PROPERTY.USER_TYPE' =>
'directory'
177 return self::getFilteredPropertyCodes($iblockId, $filter, $parameters);
195 private static function getBasketPropertyByTypes(array $catalog, array $parameters = []): ?array
199 $getCode = (isset($parameters[
'CODE']) && $parameters[
'CODE'] ==
'Y');
201 switch ($catalog[
'CATALOG_TYPE'])
203 case \CCatalogSku::TYPE_CATALOG:
205 '=IBLOCK_ID' => $catalog[
'IBLOCK_ID'],
210 '@PROPERTY_TYPE' => [
211 Iblock\PropertyTable::TYPE_ELEMENT,
212 Iblock\PropertyTable::TYPE_SECTION,
213 Iblock\PropertyTable::TYPE_LIST,
214 Iblock\PropertyTable::TYPE_NUMBER,
215 Iblock\PropertyTable::TYPE_STRING
220 '@PROPERTY_TYPE' => [
221 Iblock\PropertyTable::TYPE_ELEMENT,
222 Iblock\PropertyTable::TYPE_LIST
228 case \CCatalogSku::TYPE_PRODUCT:
229 case \CCatalogSku::TYPE_FULL:
231 '=IBLOCK_ID' => $catalog[
'PRODUCT_IBLOCK_ID'],
236 '@PROPERTY_TYPE' => [
237 Iblock\PropertyTable::TYPE_ELEMENT,
238 Iblock\PropertyTable::TYPE_SECTION,
239 Iblock\PropertyTable::TYPE_LIST,
240 Iblock\PropertyTable::TYPE_NUMBER,
241 Iblock\PropertyTable::TYPE_STRING
246 '@PROPERTY_TYPE' => [
247 Iblock\PropertyTable::TYPE_ELEMENT,
248 Iblock\PropertyTable::TYPE_LIST
254 case \CCatalogSku::TYPE_OFFERS:
256 '=IBLOCK_ID' => $catalog[
'IBLOCK_ID'],
257 '!=PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_FILE,
258 '!=ID' => $catalog[
'SKU_PROPERTY_ID']
262 $filter[
'=ACTIVE'] =
'Y';
264 $iterator = Iblock\PropertyTable::getList([
265 'select' => [
'ID',
'CODE',
'SORT'],
267 'order' => [
'SORT' =>
'ASC',
'ID' =>
'ASC']
269 while ($row = $iterator->fetch())
270 $result[(int)$row[
'ID']] = self::getPropertyCode($row, $getCode);
271 unset($row, $iterator);
272 unset($filter, $getCode);
274 return (!empty($result) ? array_values($result) : null);
292 private static function getOfferTreePropertyByTypes(array $catalog, array $parameters = []): ?array
296 $getCode = (isset($parameters[
'CODE']) && $parameters[
'CODE'] ==
'Y');
298 '=IBLOCK_ID' => $catalog[
'IBLOCK_ID'],
299 '!=ID' => $catalog[
'SKU_PROPERTY_ID'],
305 '@PROPERTY_TYPE' => [
306 Iblock\PropertyTable::TYPE_ELEMENT,
307 Iblock\PropertyTable::TYPE_LIST
311 '=PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_STRING,
312 '=USER_TYPE' =>
'directory'
316 $iterator = Iblock\PropertyTable::getList([
317 'select' => [
'ID',
'CODE',
'SORT'],
319 'order' => [
'SORT' =>
'ASC',
'ID' =>
'ASC']
321 while ($row = $iterator->fetch())
322 $result[(int)$row[
'ID']] = self::getPropertyCode($row, $getCode);
323 unset($row, $iterator);
324 unset($filter, $getCode);
326 return (!empty($result) ? array_values($result) : null);
337 private static function checkBasketProperty(array $property, array $description): bool
339 if (!isset($property[
'IBLOCK_ID']))
342 if ((
int)$property[
'IBLOCK_ID'] > 0)
344 $catalog = \CCatalogSku::GetInfoByIBlock($property[
'IBLOCK_ID']);
347 $catalogType = $catalog[
'CATALOG_TYPE'];
353 if ($catalogType ===
null)
355 if (!isset($property[
'PROPERTY_TYPE']))
357 if (!isset($property[
'MULTIPLE']))
360 switch ($catalogType)
362 case \CCatalogSku::TYPE_PRODUCT:
363 case \CCatalogSku::TYPE_CATALOG:
364 case \CCatalogSku::TYPE_FULL:
365 if ($property[
'MULTIPLE'] ==
'Y')
368 $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_ELEMENT
369 && $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_SECTION
370 && $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_LIST
371 && $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_NUMBER
372 && $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_STRING
376 elseif ($property[
'MULTIPLE'] ==
'N')
379 $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_ELEMENT
380 && $property[
'PROPERTY_TYPE'] !== Iblock\PropertyTable::TYPE_LIST
389 case \CCatalogSku::TYPE_OFFERS:
390 if ($property[
'PROPERTY_TYPE'] == Iblock\PropertyTable::TYPE_FILE)
406 private static function checkOfferTreeProperty(array $property, array $description): bool
408 if (!isset($property[
'IBLOCK_ID']))
410 if ((
int)$property[
'IBLOCK_ID'] > 0)
412 $catalog = \CCatalogSku::GetInfoByOfferIBlock($property[
'IBLOCK_ID']);
422 !isset($property[
'PROPERTY_TYPE'])
424 $property[
'PROPERTY_TYPE'] != Iblock\PropertyTable::TYPE_ELEMENT
425 && $property[
'PROPERTY_TYPE'] != Iblock\PropertyTable::TYPE_LIST
426 && $property[
'PROPERTY_TYPE'] != Iblock\PropertyTable::TYPE_STRING
430 if ($property[
'PROPERTY_TYPE'] == Iblock\PropertyTable::TYPE_ELEMENT)
432 if (isset($property[
'USER_TYPE']) && $property[
'USER_TYPE'] == \CIBlockPropertySKU::USER_TYPE)
435 if ($property[
'PROPERTY_TYPE'] == Iblock\PropertyTable::TYPE_STRING)
437 if (!isset($property[
'USER_TYPE']) || $property[
'USER_TYPE'] !=
'directory')
440 if (!isset($property[
'MULTIPLE']) || $property[
'MULTIPLE'] !=
'N')
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)