Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productform.php
1<?php
2
4
12
13class ProductForm extends BaseForm
14{
16 protected $entity;
17
18 public function getControllers(): array
19 {
20 $controllers = parent::getControllers();
21
22 $controllers[] = $this->getGridController();
23 $controllers[] = [
24 'name' => 'IBLOCK_SECTION_CONTROLLER',
25 'type' => 'iblock_section',
26 'config' => [],
27 ];
28
29 return $controllers;
30 }
31
32 protected function getGridController(): array
33 {
34 return [
35 'name' => 'VARIATION_GRID_CONTROLLER',
36 'type' => 'variation_grid',
37 'config' => [
38 'reloadUrl' => '/bitrix/components/bitrix/' . $this->getVariationGridShortComponentName() . '/list.ajax.php',
39 'signedParameters' => $this->getVariationGridSignedParameters(),
40 'gridId' => $this->getVariationGridId(),
41 ],
42 ];
43 }
44
45 public function collectFieldConfigs(): array
46 {
47 $config = parent::collectFieldConfigs();
48
49 $config['right']['elements'][] = $this->getGridFieldConfig();
50
51 return $config;
52 }
53
54 protected function getGridFieldConfig(): array
55 {
56 return [
57 'name' => 'variation_grid',
58 'title' => 'Variation grid',
59 'type' => 'included_area',
60 'data' => [
61 'isRemovable' => false,
62 'type' => 'component',
63 'componentName' => $this->getVariationGridComponentName(),
64 'action' => 'getProductGrid',
65 'mode' => 'ajax',
66 'signedParametersName' => 'VARIATION_GRID_SIGNED_PARAMETERS',
67 ],
68 'sort' => 100,
69 ];
70 }
71
72 protected function getVariationGridShortComponentName(): string
73 {
74 return 'catalog.productcard.variation.grid';
75 }
76
77 protected function getVariationGridComponentName(): string
78 {
79 return 'bitrix:' . $this->getVariationGridShortComponentName();
80 }
81
82 protected function getVariationGridParameters(): array
83 {
84 return [
85 'IBLOCK_ID' => $this->entity->getIblockId(),
86 'PRODUCT_ID' => $this->entity->getId(),
87 'COPY_PRODUCT_ID' => $this->params['COPY_PRODUCT_ID'] ?? null,
88 'EXTERNAL_FIELDS' => $this->params['EXTERNAL_FIELDS'] ?? null,
89 'PATH_TO' => $this->params['PATH_TO'] ?? [],
90 ];
91 }
92
93 protected function getVariationGridSignedParameters(): string
94 {
98 );
99 }
100
101 protected function getCardSettingsItems(): array
102 {
104 }
105
106 protected function buildDescriptions(): array
107 {
108 return array_merge(
109 parent::buildDescriptions(),
110 $this->getSectionDescriptions(),
112 );
113 }
114
115 protected function getHiddenPropertyCodes(): array
116 {
117 return [self::MORE_PHOTO];
118 }
119
120 protected function getPropertiesConfigElements(): array
121 {
122 return array_merge(
123 [
124 ['name' => 'IBLOCK_SECTION'],
125 ],
126 parent::getPropertiesConfigElements()
127 );
128 }
129
130 private function getSectionDescriptions(): array
131 {
132 return [
133 [
134 'entity' => 'section',
135 'name' => 'IBLOCK_SECTION',
136 'title' => Loc::getMessage('CATALOG_C_F_SECTION_SELECTOR_TITLE'),
137 'type' => 'iblock_section',
138 'editable' => $this->isAllowedEditFields(),
139 'required' => false,
140 'defaultValue' => null,
141 ],
142 ];
143 }
144
145 protected function showSpecificCatalogParameters(): bool
146 {
147 return $this->entity->isSimple();
148 }
149
150 protected function getFieldValue(array $field)
151 {
152 if ($field['entity'] === 'section')
153 {
154 return $this->getIblockSectionFieldValue();
155 }
156
157 return parent::getFieldValue($field);
158 }
159
160 private function getIblockSectionFieldValue(): array
161 {
162 $sectionIds = $this->entity->getSectionCollection()->getValues();
163
164 if (empty($sectionIds))
165 {
166 $sectionIds[] = 0;
167 }
168
169 return $sectionIds;
170 }
171
172 protected function getAdditionalValues(array $values, array $descriptions = []): array
173 {
174 $additionalValues = parent::getAdditionalValues($values, $descriptions);
175
176 $additionalValues['IBLOCK_SECTION_DATA'] = $this->getIblockSectionServiceFieldValue($values);
177 $additionalValues['VARIATION_GRID_SIGNED_PARAMETERS'] = $this->getVariationGridSignedParameters();
178
179 return $additionalValues;
180 }
181
182 private function getIblockSectionServiceFieldValue(array $values): array
183 {
184 $sectionData = [];
185
186 $sections = $values['IBLOCK_SECTION'] ?? [];
187 $sections = array_diff($sections, [0]);
188
189 if (!empty($sections))
190 {
191 $sectionList = \CIBlockSection::GetList(
192 [],
193 ['ID' => $sections],
194 false,
195 ['ID', 'NAME', 'PICTURE']
196 );
197 while ($section = $sectionList->Fetch())
198 {
199 $picture = \CFile::resizeImageGet(
200 $section['PICTURE'],
201 ['width' => 100, 'height' => 100],
202 BX_RESIZE_IMAGE_EXACT,
203 false
204 );
205 $section['PICTURE'] = $picture['src'] ?? null;
206 $sectionData[] = $section;
207 }
208 }
209
210 return $sectionData;
211 }
212}
getAdditionalValues(array $values, array $descriptions=[])
static signParameters($componentName, $parameters)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29