17 public const TYPE_ID = Catalog\Product\SystemField\Type\HighloadBlock::class;
24 public static function getConfig(): ?array
26 if (!static::isAllowed())
32 $className = static::getTypeId();
33 $fieldId = static::getFieldId();
37 'TABLE_NAME' => $className::getTableName($fieldId),
38 'NAME' => $className::getName($fieldId),
39 'FIELDS' => static::getHighloadblockFields(),
40 'RIGHTS' => $className::getDefaultRights(),
41 'VALUES' => static::getHighloadblockValues(),
43 'FIELD' => self::getUserFieldBaseParam() + [
46 'SHOW_IN_LIST' =>
'Y',
47 'EDIT_IN_LIST' =>
'Y',
48 'IS_SEARCHABLE' =>
'N',
49 'SETTINGS' => $className::getDefaultSettings(),
52 'HLFIELD_ID' =>
'UF_NAME',
56 $result[
'FIELD'][
'SETTINGS'][
'DEFAULT_VALUE'] = [
61 $titles = static::getMessages(
63 [
'TITLES' =>
'PRODUCT_MAPPING_STORAGE_TITLE',]
66 $result[
'HIGHLOADBLOCK'] = $result[
'HIGHLOADBLOCK'] + $titles;
69 $result[
'FIELD'] += static::getMessages(
72 'EDIT_FORM_LABEL' =>
'PRODUCT_MAPPING_FIELD_TITLE',
73 'LIST_COLUMN_LABEL' =>
'PRODUCT_MAPPING_FIELD_TITLE',
74 'LIST_FILTER_LABEL' =>
'PRODUCT_MAPPING_FIELD_TITLE',
75 'HELP_MESSAGE' =>
'PRODUCT_MAPPING_FIELD_TITLE_HINT',
84 return Type\HighloadBlock::isAllowed() && static::isBitrix24();
92 public static function getUserFieldBaseParam(): array
95 $className = static::getTypeId();
96 $fieldId = static::getFieldId();
99 'ENTITY_ID' => Catalog\ProductTable::getUfId(),
100 'FIELD_NAME' => static::getUserFieldName($fieldId),
101 'USER_TYPE_ID' => $className::getUserTypeId(),
102 'XML_ID' => $fieldId,
117 'DEFAULT_VALUE' =>
'',
125 'DEFAULT_VALUE' =>
'',
135 foreach (array_keys($fieldSettings) as $fieldId)
137 $messageList = static::getMessages(
140 'EDIT_FORM_LABEL' =>
'PRODUCT_MAPPING_UF_FIELD_'.$fieldId,
141 'LIST_COLUMN_LABEL' =>
'PRODUCT_MAPPING_UF_FIELD_'.$fieldId,
142 'LIST_FILTER_LABEL' =>
'PRODUCT_MAPPING_UF_FIELD_'.$fieldId
147 'FIELD_NAME' => static::getUserFieldName($fieldId),
148 'USER_TYPE_ID' => Main\UserField\Types\StringType::USER_TYPE_ID,
149 'XML_ID' => $fieldId,
153 'SHOW_FILTER' =>
'S',
154 'SHOW_IN_LIST' =>
'Y',
155 'EDIT_IN_LIST' =>
'Y',
156 'IS_SEARCHABLE' =>
'N',
157 'SETTINGS' => $fieldSettings[$fieldId],
174 foreach ($mapId as $id)
179 'UF_NAME' => $title ?: $id,
194 $catalog[
'CATALOG_TYPE'] !== \CCatalogSku::TYPE_CATALOG
195 && $catalog[
'CATALOG_TYPE'] !== \CCatalogSku::TYPE_FULL
196 && $catalog[
'CATALOG_TYPE'] !== \CCatalogSku::TYPE_PRODUCT
202 $field = static::load();
209 'USER_FIELD' => $field,
211 $config[
'VISUAL'] = [
224 Catalog\ProductTable::TYPE_PRODUCT,
225 Catalog\ProductTable::TYPE_SET,
226 Catalog\ProductTable::TYPE_SKU,
227 Catalog\ProductTable::TYPE_SERVICE,
234 Catalog\Product\SystemField::OPERATION_EXPORT,
235 Catalog\Product\SystemField::OPERATION_IMPORT,
241 if (!static::isAllowed())
246 $fields = static::getUserFieldBaseParam();
249 case Catalog\Product\SystemField::OPERATION_EXPORT:
250 case Catalog\Product\SystemField::OPERATION_IMPORT:
252 $fields[
'XML_ID'] => $fields[
'FIELD_NAME'],
263 public static function prepareValue(
string $operation, array $productRow): array
265 $field = static::load();
270 if (!array_key_exists($field[
'XML_ID'], $productRow))
277 case Catalog\Product\SystemField::OPERATION_IMPORT:
278 $productRow = self::prepareValueForImport($field, $productRow);
280 case Catalog\Product\SystemField::OPERATION_EXPORT:
281 $productRow = self::prepareValueForExport($field, $productRow);
288 private static function prepareValueForImport(array $field, array $productRow): array
290 if (!is_array($productRow[$field[
'XML_ID']]))
292 $productRow[$field[
'XML_ID']] = [];
294 if (!empty($productRow[$field[
'XML_ID']]))
296 $productRow[$field[
'FIELD_NAME']] = array_values(self::getIdListByXmlId(
297 $field[
'SETTINGS'][
'HLBLOCK_ID'],
298 $productRow[$field[
'XML_ID']]
303 $productRow[$field[
'FIELD_NAME']] = [];
305 unset($productRow[$field[
'XML_ID']]);
310 private static function prepareValueForExport(array $field, array $productRow): array
312 if (!is_array($productRow[$field[
'XML_ID']]))
314 $productRow[$field[
'XML_ID']] = [];
316 if (!empty($productRow[$field[
'XML_ID']]))
318 $productRow[$field[
'XML_ID']] = array_values(self::getXmlIdListById(
319 $field[
'SETTINGS'][
'HLBLOCK_ID'],
320 $productRow[$field[
'XML_ID']]
327 public static function getExtendedFilterByArea(array $filter,
string $areaXmlId): array
329 if (!static::isAllowed())
333 if ($areaXmlId ===
'')
338 $userField = static::load();
339 if ($userField ===
null)
344 if (empty($userField[
'SETTINGS']) || !is_array($userField[
'SETTINGS']))
350 $className = static::getTypeId();
352 $list = $className::getIdByXmlId((
int)$userField[
'SETTINGS'][
'HLBLOCK_ID'], [$areaXmlId]);
353 if (!isset($list[$areaXmlId]))
358 $filter[
'=PRODUCT_'.static::getUserFieldName(static::getFieldId())] = $list[$areaXmlId];
365 $row = parent::afterLoadInternalModify($row);
366 if (empty($row[
'SETTINGS']) || !is_array($row[
'SETTINGS']))
368 $row[
'SETTINGS'] = [];
370 $row[
'SETTINGS'][
'HLBLOCK_ID'] = (int)($row[
'SETTINGS'][
'HLBLOCK_ID'] ?? 0);
371 $row[
'SETTINGS'][
'HLFIELD_ID'] = (int)($row[
'SETTINGS'][
'HLFIELD_ID'] ?? 0);
378 if (!static::isAllowed())
382 $field = static::load();
388 Catalog\Update\UiFormConfiguration::addFormField(
390 'name' => $field[
'FIELD_NAME'],
391 'optionFlags' =>
'1',
393 'showCode' =>
'true',
396 Catalog\Update\UiFormConfiguration::PARENT_SECTION_MAIN
402 if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_PUBLIC_VISIBILITY_SET))
404 $field[
'EDIT_IN_LIST'] =
'N';
407 return parent::renderAdminFormControl($field, $product, $config);
412 $description[
'type'] = UI\EntityForm\Control\Type::MULTI_LIST;
416 'RETURN_FIELD_ID' =>
'Y',
420 $items = Type\HighloadBlock::getItems($userField, $config);
423 $description[
'data'] += [
429 if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_PUBLIC_VISIBILITY_SET))
431 $description[
'editable'] =
false;
432 $description[
'defaultValue'] = [];
433 $description[
'lockText'] =
Loc::getMessage(
'PRODUCT_MAPPING_FIELD_LOCK_TEXT');
static getMessage($code, $replace=null, $language=null)