1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
variationform.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Component;
4
5use Bitrix\Catalog\Config\State;
6use Bitrix\Catalog\v2\Property\Property;
7use Bitrix\Currency\CurrencyManager;
8use Bitrix\Main\Component\ParameterSigner;
9use Bitrix\Main\Localization\Loc;
10use Bitrix\Catalog;
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 {
107 return ParameterSigner::signParameters(
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 = [];
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 return $currency ?: (string)CurrencyManager::getBaseCurrency();
283 }
284
285 protected function getMeasureRatioFieldValue()
286 {
287 $measureRatio = $this->entity
288 ->getMeasureRatioCollection()
289 ->findDefault()
290 ;
291
292 return $measureRatio ? $measureRatio->getRatio() : null;
293 }
294
295 protected function getAdditionalValues(array $values, array $descriptions = []): array
296 {
297 $additionalValues = parent::getAdditionalValues($values, $descriptions);
298 foreach ($descriptions as $description)
299 {
300 if ($description['entity'] === 'money' && \Bitrix\Main\Loader::includeModule('currency'))
301 {
302 $amount = $this->getPriceFieldValue($description);
303 $currency = $this->getCurrencyFieldValue($description);
304
305 $descriptionData = $description['data'];
306 $additionalValues[$descriptionData['currency']['name']] = $currency;
307 $additionalValues[$descriptionData['amount']] = $amount;
308 $additionalValues[$descriptionData['formatted']] = \CCurrencyLang::CurrencyFormat($amount, $currency, false);
309 $additionalValues[$descriptionData['formattedWithCurrency']] = \CCurrencyLang::CurrencyFormat($amount, $currency, true);
310 }
311 }
312
313 $additionalValues['VARIATION_GRID_SIGNED_PARAMETERS'] = $this->getVariationGridSignedParameters();
314
315 return $additionalValues;
316 }
317
318 protected function getCatalogProductFieldsList(): array
319 {
320 $fieldList = parent::getCatalogProductFieldsList();
321 $fieldList[] = 'AVAILABLE';
322
323 return $fieldList;
324 }
325}
const PRICE_FIELD_PREFIX
Определения baseform.php:51
const CURRENCY_FIELD_PREFIX
Определения baseform.php:52
array $descriptions
Определения baseform.php:77
getPropertyDescription(Property $property)
Определения variationform.php:44
static formatFieldName($name)
Определения variationform.php:17
getFieldValue(array $field)
Определения variationform.php:222
preparePriceDescription(array $fields=[])
Определения variationform.php:182
getAdditionalValues(array $values, array $descriptions=[])
Определения variationform.php:295
getPriceFieldValue(array $field)
Определения variationform.php:247
getCurrencyFieldValue(array $field)
Определения variationform.php:262
static getTypeList()
Определения group.php:273
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$name
Определения menu_edit.php:35
if(!function_exists("bx_hmac")) $amount
Определения payment.php:30
$config
Определения quickway.php:69
$currency
Определения template.php:266
$title
Определения pdf.php:123
if(!empty($XML_DATA['PRICE'])) $priceTypeList
Определения yandex_run.php:872
$fields
Определения yandex_run.php:501