Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
variationform.php
1<?php
2
4
11
13{
15 protected $entity;
16
17 public static function formatFieldName($name): string
18 {
19 return $name;
20 }
21
22 public function getControllers(): array
23 {
24 $controllers = parent::getControllers();
25
26 $controllers[] = [
27 'name' => 'VARIATION_GRID_CONTROLLER',
28 'type' => 'variation_grid',
29 'config' => [
30 'reloadUrl' => '/bitrix/components/bitrix/catalog.productcard.variation.grid/list.ajax.php',
31 'signedParameters' => $this->getVariationGridSignedParameters(),
32 'gridId' => $this->getVariationGridId(),
33 ],
34 ];
35 $controllers[] = [
36 'name' => 'IBLOCK_SECTION_CONTROLLER',
37 'type' => 'iblock_section',
38 'config' => [],
39 ];
40
41 return $controllers;
42 }
43
44 protected function getPropertyDescription(Property $property): array
45 {
46 $description = parent::getPropertyDescription($property);
47
48 $propertyFeatureOfferTree = $property->getPropertyFeatureCollection()->findByFeatureId('OFFER_TREE');
49 $offerTreeParams = $propertyFeatureOfferTree ? $propertyFeatureOfferTree->getSettings() : null;
50
51 if ($offerTreeParams)
52 {
53 $description['isEnabledOfferTree'] = $offerTreeParams['IS_ENABLED'] === 'Y';
54 }
55
56 return $description;
57 }
58
59 public function collectFieldConfigs(): array
60 {
61 $config = parent::collectFieldConfigs();
62
63 $config['right']['elements'][] = [
64 'name' => 'variation_grid',
65 'title' => 'Variation grid',
66 'type' => 'included_area',
67 'data' => [
68 'isRemovable' => false,
69 'type' => 'component',
70 'componentName' => $this->getVariationGridComponentName(),
71 'action' => 'getProductGrid',
72 'mode' => 'ajax',
73 'signedParametersName' => 'VARIATION_GRID_SIGNED_PARAMETERS',
74 ],
75 'sort' => 100,
76 ];
77
78 return $config;
79 }
80
81 protected function getVariationGridComponentName(): string
82 {
83 return 'bitrix:catalog.productcard.variation.grid';
84 }
85
86 protected function getVariationGridParameters(): array
87 {
88 $variationIdList = null;
89 $variationId = $this->params['VARIATION_ID'] ?? null;
90 if (!empty($variationId))
91 {
92 $variationIdList = [$this->params['VARIATION_ID']];
93 }
94
95 return [
96 'IBLOCK_ID' => $this->params['IBLOCK_ID'] ?? null,
97 'PRODUCT_ID' => $this->params['PRODUCT_ID'] ?? null,
98 'VARIATION_ID_LIST' => $variationIdList,
99 'COPY_PRODUCT_ID' => $this->params['COPY_PRODUCT_ID'] ?? null,
100 'EXTERNAL_FIELDS' => $this->params['EXTERNAL_FIELDS'] ?? null,
101 'PATH_TO' => $this->params['PATH_TO'] ?? [],
102 ];
103 }
104
105 protected function getVariationGridSignedParameters(): string
106 {
110 );
111 }
112
113 protected function getCardSettingsItems(): array
114 {
116 }
117
118 protected function showCatalogProductFields(): bool
119 {
120 return true;
121 }
122
123 protected function showSpecificCatalogParameters(): bool
124 {
125 return true;
126 }
127
128 protected function buildDescriptions(): array
129 {
130 return array_merge(
131 parent::buildDescriptions(),
132 $this->getPriceDescriptions(),
135 );
136 }
137
138 protected function getPriceDescriptions(): array
139 {
140 $descriptions = [];
141 $priceTypeList = Catalog\GroupTable::getTypeList();
142
143 if (!empty($priceTypeList))
144 {
145 foreach ($priceTypeList as $priceType)
146 {
147 $title = !empty($priceType['NAME_LANG']) ? $priceType['NAME_LANG'] : $priceType['NAME'];
148 $priceFieldName = static::formatFieldName(BaseForm::PRICE_FIELD_PREFIX.$priceType['ID']);
149
151 'NAME' => $priceFieldName.'_FIELD',
152 'TYPE_ID' => (int)$priceType['ID'],
153 'TITLE' => $title,
154 'PRICE_FIELD' => $priceFieldName,
155 'CURRENCY_FIELD' => static::formatFieldName(BaseForm::CURRENCY_FIELD_PREFIX.$priceType['ID']),
156 ]);
157 }
158 }
159
160 $purchasingPriceFieldName = static::formatFieldName('PURCHASING_PRICE');
161 if ($this->isPurchasingPriceAllowed())
162 {
163 $purchasingPriceDescription = $this->preparePriceDescription([
164 'NAME' => $purchasingPriceFieldName.'_FIELD',
165 'TYPE_ID' => 'PURCHASING_PRICE',
166 'TITLE' => Loc::getMessage('CATALOG_C_F_VARIATION_SETTINGS_PURCHASING_PRICE_FIELD_TITLE'),
167 'PRICE_FIELD' => $purchasingPriceFieldName,
168 'CURRENCY_FIELD' => static::formatFieldName('PURCHASING_CURRENCY'),
169 ]);
170
171 if (State::isUsedInventoryManagement())
172 {
173 $purchasingPriceDescription['editable'] = false;
174 }
175
176 $descriptions[] = $purchasingPriceDescription;
177 }
178
179 return $descriptions;
180 }
181
182 protected function preparePriceDescription(array $fields = []): array
183 {
184 return [
185 'name' => $fields['NAME'],
186 'title' => $fields['TITLE'],
187 'type' => 'money',
188 'entity' => 'money',
189 'priceTypeId' => $fields['TYPE_ID'],
190 'editable' => $this->isPricesEditable(),
191 'data' => [
192 'affectedFields' => [
193 $fields['PRICE_FIELD'],
194 $fields['CURRENCY_FIELD'],
195 ],
196 'currency' => [
197 'name' => $fields['CURRENCY_FIELD'],
198 'items' => $this->getCurrencyList(),
199 ],
200 'amount' => $fields['PRICE_FIELD'],
201 'formatted' => 'FORMATTED_'.$fields['PRICE_FIELD'].'_PRICE',
202 'formattedWithCurrency' => 'FORMATTED_'.$fields['PRICE_FIELD'].'_WITH_CURRENCY',
203 ],
204 ];
205 }
206
207 protected function getMeasureRatioDescription(): array
208 {
209 return [
210 [
211 'entity' => 'measure_ratio',
212 'name' => static::formatFieldName('MEASURE_RATIO'),
213 'title' => Loc::getMessage('CATALOG_C_F_VARIATION_SETTINGS_MEASURE_RATIO_TITLE'),
214 'type' => 'number',
215 'editable' => $this->isAllowedEditFields(),
216 'required' => false,
217 'defaultValue' => 1,
218 ],
219 ];
220 }
221
222 protected function getFieldValue(array $field)
223 {
224 if ($field['entity'] === 'price')
225 {
226 return $this->getPriceFieldValue($field);
227 }
228
229 if ($field['entity'] === 'currency')
230 {
231 return $this->getCurrencyFieldValue($field);
232 }
233
234 if ($field['entity'] === 'measure_ratio')
235 {
236 return $this->getMeasureRatioFieldValue();
237 }
238
239 return parent::getFieldValue($field);
240 }
241
242 protected function getHiddenPropertyCodes(): array
243 {
244 return [self::MORE_PHOTO];
245 }
246
247 protected function getPriceFieldValue(array $field)
248 {
249 if ($field['priceTypeId'] === 'PURCHASING_PRICE')
250 {
251 return $this->entity->getField('PURCHASING_PRICE');
252 }
253
254 $price = $this->entity
255 ->getPriceCollection()
256 ->findByGroupId($field['priceTypeId'])
257 ;
258
259 return $price ? $price->getPrice() : null;
260 }
261
262 protected function getCurrencyFieldValue(array $field): string
263 {
264 $currency = null;
265
266 if ($field['priceTypeId'] === 'PURCHASING_PRICE')
267 {
268 $currency = $this->entity->getField('PURCHASING_CURRENCY');
269 }
270 else
271 {
272 $price = $this->entity
273 ->getPriceCollection()
274 ->findByGroupId($field['priceTypeId'])
275 ;
276 if ($price)
277 {
278 $currency = $price->getCurrency();
279 }
280 }
281
282
283 return $currency ?: CurrencyManager::getBaseCurrency();
284 }
285
286 protected function getMeasureRatioFieldValue()
287 {
288 $measureRatio = $this->entity
289 ->getMeasureRatioCollection()
290 ->findDefault()
291 ;
292
293 return $measureRatio ? $measureRatio->getRatio() : null;
294 }
295
296 protected function getAdditionalValues(array $values, array $descriptions = []): array
297 {
298 $additionalValues = parent::getAdditionalValues($values, $descriptions);
299 foreach ($descriptions as $description)
300 {
301 if ($description['entity'] === 'money' && \Bitrix\Main\Loader::includeModule('currency'))
302 {
303 $amount = $this->getPriceFieldValue($description);
304 $currency = $this->getCurrencyFieldValue($description);
305
306 $descriptionData = $description['data'];
307 $additionalValues[$descriptionData['currency']['name']] = $currency;
308 $additionalValues[$descriptionData['amount']] = $amount;
309 $additionalValues[$descriptionData['formatted']] = \CCurrencyLang::CurrencyFormat($amount, $currency, false);
310 $additionalValues[$descriptionData['formattedWithCurrency']] = \CCurrencyLang::CurrencyFormat($amount, $currency, true);
311 }
312 }
313
314 $additionalValues['VARIATION_GRID_SIGNED_PARAMETERS'] = $this->getVariationGridSignedParameters();
315
316 return $additionalValues;
317 }
318
319 protected function getCatalogProductFieldsList(): array
320 {
321 $fieldList = parent::getCatalogProductFieldsList();
322 $fieldList[] = 'AVAILABLE';
323
324 return $fieldList;
325 }
326}
getAdditionalValues(array $values, array $descriptions=[])
static signParameters($componentName, $parameters)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29