17 private const COMMON =
'C';
18 private const PERSONAL =
'P';
25 !Loader::includeModule(
'crm')
26 || !Loader::includeModule(
'catalog')
27 || !Loader::includeModule(
'bitrix24')
33 self::showProductField();
34 self::showNameCodeField(
'CATALOG_PRODUCT_CARD', self::COMMON);
35 self::showNameCodeField(
'CATALOG_PRODUCT_CARD', self::PERSONAL);
36 self::showNameCodeField(
'CATALOG_VARIATION_CARD', self::COMMON);
37 self::showNameCodeField(
'CATALOG_VARIATION_CARD', self::PERSONAL);
42 private static function showProductField(): void
44 $crmCatalogId = \CCrmCatalog::GetDefaultID();
46 if ($crmCatalogId === 0)
51 $tablePrefix =
'tbl_product_list_';
52 $listId =
'CRM_PRODUCT_CATALOG.' . $crmCatalogId;
54 if (Catalog\
Config\State::isProductCardSliderEnabled())
59 $tableId = $tablePrefix . md5($listId);
61 $productGridOptions = new \Bitrix\Main\Grid\Options($tableId);
62 $visibleColumns = $productGridOptions->GetVisibleColumns();
64 if (empty($visibleColumns))
69 $hasProductField = in_array(
'CATALOG_PRODUCT', $visibleColumns,
true);
70 $hasMorePhotoField = in_array(
'MORE_PHOTO', $visibleColumns,
true);
72 $oldNameFieldIndex = array_search(
'NAME', $visibleColumns,
true);
76 if ($oldNameFieldIndex !==
false)
78 unset($visibleColumns[$oldNameFieldIndex]);
80 elseif ($hasMorePhotoField)
87 if ($oldNameFieldIndex !==
false)
89 $visibleColumns[$oldNameFieldIndex] =
'CATALOG_PRODUCT';
93 array_unshift($visibleColumns,
'CATALOG_PRODUCT');
97 if (!$hasMorePhotoField)
99 $catalogProductFieldIndex = array_search(
'CATALOG_PRODUCT', $visibleColumns,
true);
100 $visibleColumnsBefore = array_slice($visibleColumns, 0, $catalogProductFieldIndex + 1);
101 $visibleColumnsAfter = array_slice($visibleColumns, $catalogProductFieldIndex + 1);
102 $visibleColumns = array_merge($visibleColumnsBefore, [
'MORE_PHOTO'], $visibleColumnsAfter);
105 $productGridOptions->SetVisibleColumns($visibleColumns);
108 private static function showNameCodeField(
string $configId,
string $scope): void
110 if (!Loader::includeModule(
'ui'))
115 $entityEditorConfiguration = new \Bitrix\UI\Form\EntityEditorConfiguration(
'ui.form.editor');
116 $cardSettings = $entityEditorConfiguration->get($configId, $scope);
118 if (!is_array($cardSettings))
123 $hasOldNameField = self::hasField($cardSettings,
'NAME');
124 $hasOldCodeField = self::hasField($cardSettings,
'CODE');
125 $hasNameCodeField = self::hasField($cardSettings,
'NAME-CODE');
127 if ($hasNameCodeField)
129 if (!$hasOldNameField && !$hasOldCodeField)
134 if ($hasOldNameField)
136 $cardSettings = self::unsetField($cardSettings,
'NAME');
142 'name' =>
'NAME-CODE',
143 'optionFlags' =>
'1',
145 'showCode' => $hasOldCodeField ?
'true' :
'false',
149 if (!$hasOldNameField)
151 $cardSettings = self::setField($cardSettings, $nameCodeField);
155 $cardSettings = self::replaceField($cardSettings,
'NAME', $nameCodeField);
159 if ($hasOldCodeField)
161 $cardSettings = self::unsetField($cardSettings,
'CODE');
164 $entityEditorConfiguration->set($configId, $cardSettings, [
'scope' => $scope]);
167 private static function hasField(array $cardSettings,
string $fieldName): bool
169 foreach ($cardSettings as $column)
171 foreach ($column[
'elements'] as $columnElement)
173 if ($columnElement[
'type'] !==
'section')
178 foreach ($columnElement[
'elements'] as $element)
180 if ($element[
'name'] === $fieldName)
191 private static function unsetField(array $cardSettings,
string $fieldName): array
193 foreach ($cardSettings as $columnKey => $column)
195 foreach ($column[
'elements'] as $columnElementKey => $columnElement)
197 if ($columnElement[
'type'] !==
'section')
202 foreach ($columnElement[
'elements'] as $elementKey => $element)
204 if ($element[
'name'] === $fieldName)
206 unset ($cardSettings[$columnKey][
'elements'][$columnElementKey][
'elements'][$elementKey]);
207 return $cardSettings;
213 return $cardSettings;
216 private static function replaceField(array $cardSettings,
string $oldFieldName, array $newField): array
218 foreach ($cardSettings as $columnKey => $column)
220 foreach ($column[
'elements'] as $columnElementKey => $columnElement)
222 if ($columnElement[
'type'] !==
'section')
227 foreach ($columnElement[
'elements'] as $elementKey => $element)
229 if ($element[
'name'] === $oldFieldName)
231 $cardSettings[$columnKey][
'elements'][$columnElementKey][
'elements'][$elementKey] = $newField;
232 return $cardSettings;
238 return $cardSettings;
241 private static function setField(array $cardSettings, array $newField): array
243 foreach ($cardSettings as $columnKey => $column)
245 foreach ($column[
'elements'] as $columnElementKey => $columnElement)
247 if ($columnElement[
'name'] ===
'main')
250 $cardSettings[$columnKey][
'elements'][$columnElementKey][
'elements'],
253 return $cardSettings;
258 return $cardSettings;