19 public const TYPE_ID = Catalog\Product\SystemField\Type\HighloadBlock::class;
26 public static function getConfig(): ?array
28 if (!static::isAllowed())
34 $className = static::getTypeId();
35 $fieldId = static::getFieldId();
39 'TABLE_NAME' => $className::getTableName($fieldId),
40 'NAME' => $className::getName($fieldId),
41 'FIELDS' => static::getHighloadblockFields(),
42 'RIGHTS' => $className::getDefaultRights(),
43 'TRANSFORM_VALUES' => static::getHighloadblockTransformValues(),
44 'VALUES' => static::getHighloadblockValues(),
46 'FIELD' => self::getUserFieldBaseParam() + [
49 'SHOW_IN_LIST' =>
'Y',
50 'EDIT_IN_LIST' =>
'Y',
51 'IS_SEARCHABLE' =>
'N',
52 'SETTINGS' => $className::getDefaultSettings(),
55 'HLFIELD_ID' =>
'UF_NAME',
59 $titles = static::getMessages(
61 [
'TITLES' =>
'MARKING_CODE_GROUP_STORAGE_TITLE',]
64 $result[
'HIGHLOADBLOCK'] = $result[
'HIGHLOADBLOCK'] + $titles;
66 $result[
'FIELD'] += static::getMessages(
69 'EDIT_FORM_LABEL' =>
'MARKING_CODE_GROUP_FIELD_TITLE',
70 'LIST_COLUMN_LABEL' =>
'MARKING_CODE_GROUP_FIELD_TITLE',
71 'LIST_FILTER_LABEL' =>
'MARKING_CODE_GROUP_FIELD_TITLE',
78 public static function isAllowed(): bool
81 $className = static::getTypeId();
83 if (!$className::isAllowed())
87 if (!static::isBitrix24())
89 $iterator = LanguageTable::getList([
96 $row = $iterator->fetch();
102 $iterator = LanguageTable::getList([
105 '@ID' => [
'ua',
'by',
'kz'],
110 $row = $iterator->fetch();
120 return (\CBitrix24::getPortalZone() ===
'ru');
129 public static function getUserFieldBaseParam(): array
132 $className = static::getTypeId();
135 'ENTITY_ID' => Catalog\ProductTable::getUfId(),
136 'FIELD_NAME' => static::getUserFieldName(self::SHORT_FIELD_ID),
137 'USER_TYPE_ID' => $className::getUserTypeId(),
138 'XML_ID' => static::getFieldId(),
153 'DEFAULT_VALUE' =>
'',
158 'REGEXP' =>
'/^[0-9]{1,16}$/'
161 'DEFAULT_VALUE' =>
'',
171 foreach (array_keys($fieldSettings) as $fieldId)
173 $messageList = static::getMessages(
176 'EDIT_FORM_LABEL' =>
'MARKING_CODE_GROUP_UF_FIELD_'.$fieldId,
177 'LIST_COLUMN_LABEL' =>
'MARKING_CODE_GROUP_UF_FIELD_'.$fieldId,
178 'LIST_FILTER_LABEL' =>
'MARKING_CODE_GROUP_UF_FIELD_'.$fieldId
183 'FIELD_NAME' => static::getUserFieldName($fieldId),
184 'USER_TYPE_ID' => Main\UserField\Types\StringType::USER_TYPE_ID,
185 'XML_ID' => $fieldId,
189 'SHOW_FILTER' =>
'S',
190 'SHOW_IN_LIST' =>
'Y',
191 'EDIT_IN_LIST' =>
'Y',
192 'IS_SEARCHABLE' =>
'N',
193 'SETTINGS' => $fieldSettings[$fieldId],
218 $_SERVER[
'DOCUMENT_ROOT'].
'/bitrix/modules/catalog/regionalsystemfields/markingcodegroup.php',
223 foreach ($groupCodes as $id)
227 'UF_NAME' => $groupTitles[self::VALUE_NAME_PREFIX.$id]
238 'OLD_XML_ID' =>
'5048',
239 'NEW_XML_ID' =>
'17485',
242 'OLD_XML_ID' =>
'5408',
243 'NEW_XML_ID' =>
'17485',
256 $catalog[
'CATALOG_TYPE'] === \CCatalogSku::TYPE_OFFERS
257 && self::isUsedMarkingOffer()
260 $catalog[
'CATALOG_TYPE'] !== \CCatalogSku::TYPE_CATALOG
261 && $catalog[
'CATALOG_TYPE'] !== \CCatalogSku::TYPE_FULL
262 && $catalog[
'CATALOG_TYPE'] !== \CCatalogSku::TYPE_PRODUCT
269 $field = static::load();
276 'USER_FIELD' => $field,
287 $config[
'ADDITIONAL_ITEMS'] = [
291 'NAME' =>
Loc::getMessage(
'MARKING_CODE_GROUP_MESS_USE_PARENT_PRODUCT_VALUE'),
303 Catalog\ProductTable::TYPE_PRODUCT,
304 Catalog\ProductTable::TYPE_SKU,
306 if (self::isUsedMarkingOffer())
308 $result[] = Catalog\ProductTable::TYPE_OFFER;
316 if (!parent::checkRestictions($restrictions))
321 if (isset($restrictions[
'IBLOCK_ID']) && !isset($restrictions[
'CATALOG']))
323 $iterator = Catalog\CatalogIblockTable::getList([
328 '=IBLOCK_ID' => $restrictions[
'IBLOCK_ID'],
334 $row = $iterator->fetch();
337 $restrictions[
'CATALOG'] = $row;
339 unset($row, $iterator);
342 if (!empty($restrictions[
'CATALOG']) && is_array($restrictions[
'CATALOG']))
344 if ($restrictions[
'CATALOG'][
'SUBSCRIPTION'] ===
'Y')
356 Catalog\Product\SystemField::OPERATION_PROVIDER,
357 Catalog\Product\SystemField::OPERATION_EXPORT,
358 Catalog\Product\SystemField::OPERATION_IMPORT,
364 if (!static::isAllowed())
369 $fields = static::getUserFieldBaseParam();
372 case Catalog\Product\SystemField::OPERATION_PROVIDER:
373 case Catalog\Product\SystemField::OPERATION_EXPORT:
374 case Catalog\Product\SystemField::OPERATION_IMPORT:
376 $fields[
'XML_ID'] => $fields[
'FIELD_NAME'],
387 public static function prepareValue(
string $operation, array $productRow): array
389 $field = static::load();
394 if (!array_key_exists($field[
'XML_ID'], $productRow))
401 case Catalog\Product\SystemField::OPERATION_PROVIDER:
402 $productRow = self::prepareValueForProvider($field, $productRow);
404 case Catalog\Product\SystemField::OPERATION_IMPORT:
405 $productRow = self::prepareValueForImport($field, $productRow);
407 case Catalog\Product\SystemField::OPERATION_EXPORT:
408 $productRow = self::prepareValueForExport($field, $productRow);
415 private static function prepareValueForProvider(array $field, array $productRow): array
417 $value = $productRow[$field[
'XML_ID']];
420 $value = (int)$value;
422 if (self::isNeedParent($productRow))
425 !self::isUsedMarkingOffer()
429 $productValue = self::getParentProductValue($productRow[
'ID'], $field);
430 if ($value === self::USE_PARENT_PRODUCT_VALUE)
432 $value = $productValue;
436 $value = $productValue ?? $value;
441 $productRow[$field[
'XML_ID']] = ($value !==
null
449 private static function prepareValueForImport(array $field, array $productRow): array
451 $value = $productRow[$field[
'XML_ID']];
452 if ($value === self::USE_PARENT_PRODUCT_XML_VALUE)
458 $productRow[$field[
'FIELD_NAME']] = ($value !==
null
463 unset($productRow[$field[
'XML_ID']]);
468 private static function prepareValueForExport(array $field, array $productRow): array
470 $value = $productRow[$field[
'XML_ID']];
473 $value = (int)$value;
475 if ($value === self::USE_PARENT_PRODUCT_VALUE)
479 elseif ($value !==
null)
482 $field[
'SETTINGS'][
'HLBLOCK_ID'],
490 private static function isNeedParent(array $productRow): bool
493 isset($productRow[
'ID'])
494 && isset($productRow[
'TYPE'])
499 private static function isUsedMarkingOffer(): bool
501 return Option::get(
'catalog',
'use_offer_marking_code_group') ===
'Y';
504 private static function getParentProductValue(
int $id, $field): ?string
507 $parentsList = \CCatalogSku::getProductList($id);
508 if (!empty($parentsList) && isset($parentsList[$id]))
510 $row = Catalog\ProductTable::getRow([
513 $field[
'FIELD_NAME'],
516 '=ID' => $parentsList[$id][
'ID'],
521 $result = $row[$field[
'FIELD_NAME']];
530 $row = parent::afterLoadInternalModify($row);
531 if (empty($row[
'SETTINGS']) || !is_array($row[
'SETTINGS']))
533 $row[
'SETTINGS'] = [];
535 $row[
'SETTINGS'][
'HLBLOCK_ID'] = (int)($row[
'SETTINGS'][
'HLBLOCK_ID'] ?? 0);
536 $row[
'SETTINGS'][
'HLFIELD_ID'] = (int)($row[
'SETTINGS'][
'HLFIELD_ID'] ?? 0);
543 if (!static::isAllowed())
547 $field = static::load();
553 Catalog\Update\UiFormConfiguration::addFormField(
555 'name' => $field[
'FIELD_NAME'],
556 'optionFlags' =>
'1',
558 'showCode' =>
'true',
561 Catalog\Update\UiFormConfiguration::PARENT_SECTION_MAIN
567 $result = parent::renderAdminFormControl($field, $product, $config);
568 if ($result !==
null)
572 $parentSelected = (int)$field[
'VALUE'] === self::USE_PARENT_PRODUCT_VALUE;
573 $addOption =
'<option value="' . self::USE_PARENT_PRODUCT_VALUE .
'"'
574 . ($parentSelected ?
' selected' :
'')
575 .
'>' . htmlspecialcharsbx(
Loc::getMessage(
'MARKING_CODE_GROUP_MESS_USE_PARENT_PRODUCT_VALUE'))
580 $result = str_replace(
'selected',
'', $result);
582 $index = strpos($result,
'</option>');
583 if ($index !==
false)
586 $result = substr($result, 0, $index)
588 . substr($result, $index)
599 $description[
'type'] = UI\EntityForm\Control\Type::LIST;
603 'RETURN_FIELD_ID' =>
'Y',
608 isset($restrictions[
'TYPE'])
610 && self::isUsedMarkingOffer()
613 $config[
'ADDITIONAL_ITEMS'] = [
616 'ID' => (string)self::USE_PARENT_PRODUCT_VALUE,
618 'NAME' =>
Loc::getMessage(
'MARKING_CODE_GROUP_MESS_USE_PARENT_PRODUCT_VALUE'),
624 $items = Type\HighloadBlock::getItems($userField, $config);
627 $description[
'data'] += [
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)