18 if (!Loader::includeModule(
'crm'))
23 $crmCatalogIblockId = \Bitrix\Crm\Product\Catalog::getDefaultId();
25 if (!Loader::includeModule(
'iblock') || !self::checkIblock($crmCatalogIblockId))
30 $propertyId = self::loadProperty($crmCatalogIblockId);
33 self::createProperty($crmCatalogIblockId);
37 private static function checkIblock(
int $iblockId): bool
39 $iblock = IblockTable::getList([
41 'filter' => [
'=ID' => $iblockId],
46 return !empty($iblock);
49 private static function loadProperty(
int $iblockId): ?int
51 $property = PropertyTable::getList([
54 '=IBLOCK_ID' => $iblockId,
55 '=CODE' => self::PROPERTY_CODE,
61 if (!empty($property))
63 return (
int)$property[
'ID'];
69 private static function createProperty(
int $iblockId): ?int
71 $highloadBlockTable = self::createHighloadBlockTable();
72 if (!$highloadBlockTable)
77 $propertyDescription = self::getPropertyDescription($iblockId, $highloadBlockTable);
78 $propertyId = (new \CIBlockProperty())->Add($propertyDescription);
80 return (
int)$propertyId ?:
null;
83 private static function getPropertyDescription(
int $iblockId,
string $highloadBlockTable): array
89 'IBLOCK_ID' => $iblockId,
90 'PROPERTY_TYPE' => PropertyTable::TYPE_STRING,
91 'USER_TYPE' =>
'directory',
92 'USER_TYPE_SETTINGS' => [
97 'TABLE_NAME' => $highloadBlockTable,
101 'WITH_DESCRIPTION' =>
'N',
106 private static function createHighloadBlockTable(): ?string
108 if (!Loader::includeModule(
'highloadblock'))
113 $uniqId = uniqid(
'BRAND_FOR_FACEBOOK_',
false);
115 $tableName = mb_strtolower(\CIBlockPropertyDirectory::createHighloadTableName($uniqId));
117 $addResult = HighloadBlockTable::add([
118 'NAME' => $className,
119 'TABLE_NAME' => $tableName,
121 if (!$addResult->isSuccess())
126 $userFieldEntity = new \CUserTypeEntity();
128 foreach (self::getUserFieldDescriptions((
string)$addResult->getId()) as $description)
130 $userFieldEntity->Add($description);
136 private static function getUserFieldDescriptions(
string $highloadBlockId): array
140 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
141 'FIELD_NAME' =>
'UF_NAME',
142 'USER_TYPE_ID' =>
'string',
143 'XML_ID' =>
'UF_BRAND_NAME',
147 'SHOW_FILTER' =>
'N',
148 'SHOW_IN_LIST' =>
'Y',
149 'EDIT_IN_LIST' =>
'Y',
150 'IS_SEARCHABLE' =>
'Y',
153 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
154 'FIELD_NAME' =>
'UF_FILE',
155 'USER_TYPE_ID' =>
'file',
156 'XML_ID' =>
'UF_BRAND_FILE',
160 'SHOW_FILTER' =>
'N',
161 'SHOW_IN_LIST' =>
'Y',
162 'EDIT_IN_LIST' =>
'Y',
163 'IS_SEARCHABLE' =>
'Y',
166 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
167 'FIELD_NAME' =>
'UF_LINK',
168 'USER_TYPE_ID' =>
'string',
169 'XML_ID' =>
'UF_BRAND_LINK',
173 'SHOW_FILTER' =>
'N',
174 'SHOW_IN_LIST' =>
'Y',
175 'EDIT_IN_LIST' =>
'Y',
176 'IS_SEARCHABLE' =>
'Y',
179 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
180 'FIELD_NAME' =>
'UF_DESCRIPTION',
181 'USER_TYPE_ID' =>
'string',
182 'XML_ID' =>
'UF_BRAND_DESCR',
186 'SHOW_FILTER' =>
'N',
187 'SHOW_IN_LIST' =>
'Y',
188 'EDIT_IN_LIST' =>
'Y',
189 'IS_SEARCHABLE' =>
'Y',
192 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
193 'FIELD_NAME' =>
'UF_FULL_DESCRIPTION',
194 'USER_TYPE_ID' =>
'string',
195 'XML_ID' =>
'UF_BRAND_FULL_DESCR',
199 'SHOW_FILTER' =>
'N',
200 'SHOW_IN_LIST' =>
'Y',
201 'EDIT_IN_LIST' =>
'Y',
202 'IS_SEARCHABLE' =>
'Y',
205 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
206 'FIELD_NAME' =>
'UF_SORT',
207 'USER_TYPE_ID' =>
'double',
208 'XML_ID' =>
'UF_BRAND_SORT',
212 'SHOW_FILTER' =>
'N',
213 'SHOW_IN_LIST' =>
'Y',
214 'EDIT_IN_LIST' =>
'Y',
215 'IS_SEARCHABLE' =>
'N',
218 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
219 'FIELD_NAME' =>
'UF_EXTERNAL_CODE',
220 'USER_TYPE_ID' =>
'string',
221 'XML_ID' =>
'UF_BRAND_EXTERNAL_CODE',
225 'SHOW_FILTER' =>
'N',
226 'SHOW_IN_LIST' =>
'Y',
227 'EDIT_IN_LIST' =>
'Y',
228 'IS_SEARCHABLE' =>
'N',
231 'ENTITY_ID' =>
'HLBLOCK_' . $highloadBlockId,
232 'FIELD_NAME' =>
'UF_XML_ID',
233 'USER_TYPE_ID' =>
'string',
234 'XML_ID' =>
'UF_XML_ID',
238 'SHOW_FILTER' =>
'N',
239 'SHOW_IN_LIST' =>
'Y',
240 'EDIT_IN_LIST' =>
'Y',
241 'IS_SEARCHABLE' =>
'N',
static getMessage($code, $replace=null, $language=null)