36 private Entity $productEntity;
37 private bool $isCatalogTypeProduct;
39 public static function getId(): string
41 return 'product_field';
46 return Loc::getMessage(
'CATALOG_GRID_PANEL_UI_PRODUCT_ACTION_SET_PARAMETERS_NAME');
49 private function isUsedInventoryManagement(): bool
51 return State::isUsedInventoryManagement();
54 private function canChangePurchasingPrice(): bool
56 return AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_PURCHASE_INFO_VIEW);
59 private function isCatalogTypeProduct(): bool
61 if (!isset($this->isCatalogTypeProduct))
63 $this->isCatalogTypeProduct =
false;
65 $info = CCatalogSku::GetInfoByIBlock($this->
getIblockId());
66 if (isset($info[
'CATALOG_TYPE']))
68 $this->isCatalogTypeProduct = $info[
'CATALOG_TYPE'] === CCatalogSku::TYPE_PRODUCT;
72 return $this->isCatalogTypeProduct;
75 private function getRequestFields(
HttpRequest $request): ?array
77 $controls = $request->getPost(
'controls');
78 if (!is_array($controls))
84 $fieldValue = $controls[$fieldName] ??
null;
85 if (empty($fieldName) || !is_string($fieldName) || !isset($fieldValue))
89 elseif (!$this->isAvailableField($fieldName))
95 $fieldName => $fieldValue,
98 if ($fieldName !==
'PURCHASING_PRICE')
103 $fieldValue = $controls[
'PURCHASING_CURRENCY'] ??
null;
104 if (empty($fieldValue) || !is_string($fieldValue))
108 $fields[
'PURCHASING_CURRENCY'] = $fieldValue;
117 $fields = $this->getRequestFields($request);
118 if ($fields ===
null)
123 [$elementIds, $sectionIds] = $this->prepareItemIds($request, $isSelectedAllRows, $filter);
144 $confirmMessage =
Loc::getMessage(
'CATALOG_GRID_PANEL_UI_PRODUCT_ACTION_SET_PARAMETERS_CONFIRM');
148 'ACTION' => Actions::RESET_CONTROLS,
151 'ACTION' => Actions::CREATE,
153 $this->getParametersDropdownControl(),
154 (
new Snippet)->getSendSelectedButton($confirmMessage),
160 private function getProductEntity():
Entity
164 return $this->productEntity;
167 private function getParametersDropdownControl(): array
171 if (!$this->isCatalogTypeProduct())
173 $items[] = $this->getInputDropdownItem(
'WEIGHT');
174 $items[] = $this->getSelectDropdownItem(
'MEASURE', $this->getMeasureDropdownItems());
175 $items[] = $this->getSelectDropdownItem(
'SUBSCRIBE', $this->getStatusDropdownItems(
176 Option::get(
'catalog',
'default_subscribe') !==
'N'
179 $vatItems = $this->getVatIdDropdownItems();
180 if (!empty($vatItems))
182 $items[] = $this->getSelectDropdownItem(
'VAT_ID', $vatItems);
184 $items[] = $this->getSelectDropdownItem(
'VAT_INCLUDED', $this->getStatusDropdownItems());
186 if (!$this->isUsedInventoryManagement())
188 $items[] = $this->getInputDropdownItem(
'QUANTITY');
189 $items[] = $this->getSelectDropdownItem(
'QUANTITY_TRACE', $this->getStatusDropdownItems(
190 Option::get(
'catalog',
'default_quantity_trace') ===
'Y'
192 $items[] = $this->getSelectDropdownItem(
'CAN_BUY_ZERO', $this->getStatusDropdownItems(
193 Option::get(
'catalog',
'default_can_buy_zero') ===
'Y'
196 if ($this->canChangePurchasingPrice())
198 $row = $this->getPriceDropdownItem([
199 'VALUE' =>
'PURCHASING_PRICE',
200 'UNIT' =>
'PURCHASING_CURRENCY',
211 $items = $this->appendSystemFieldItems($items);
214 'ID' =>
'product_field',
216 'TYPE' => Types::DROPDOWN,
221 private function appendSystemFieldItems(array $items): array
228 $productGroupAction =
new class($options) extends ProductGroupAction
230 public function getFormRowFieldName(
string $field): string
237 if (!empty($systemFieldsItems))
239 array_push($items, ...$systemFieldsItems);
245 private function getInputDropdownItem(
string $fieldName): array
247 $field = $this->getProductEntity()->getField($fieldName);
250 'VALUE' => $fieldName,
251 'NAME' => $field->getTitle(),
254 'ACTION' => Actions::RESET_CONTROLS,
257 'ACTION' => Actions::CREATE,
260 'ID' =>
'product_field_text_' . $fieldName,
261 'NAME' => $fieldName,
262 'TYPE' => Types::TEXT,
271 private function getSelectDropdownItem(
string $fieldName, array $dropdownItems): array
273 $field = $this->getProductEntity()->getField($fieldName);
276 'VALUE' => $fieldName,
277 'NAME' => $field->getTitle(),
280 'ACTION' => Actions::RESET_CONTROLS,
283 'ACTION' => Actions::CREATE,
286 'ID' =>
'product_field_dropdown_' . $fieldName,
287 'NAME' => $fieldName,
288 'TYPE' => Types::DROPDOWN,
290 'ITEMS' => $dropdownItems,
298 private function getPriceDropdownItem(array $fields): ?array
300 if (!isset($fields[
'VALUE']) || !isset($fields[
'UNIT']))
304 $fieldName = $fields[
'VALUE'];
305 $field = $this->getProductEntity()->getField($fieldName);
308 foreach (CurrencyManager::getCurrencyList() as $currencyId => $currencyName)
311 'VALUE' => $currencyId,
312 'NAME' => $currencyName
317 'VALUE' => $fieldName,
318 'NAME' => $field->getTitle(),
321 'ACTION' => Actions::RESET_CONTROLS,
324 'ACTION' => Actions::CREATE,
327 'ID' =>
'product_field_price_' . $fieldName,
328 'NAME' => $fieldName,
329 'TYPE' => Types::TEXT,
333 'ID' =>
'product_field_currency_' . $fieldName,
334 'NAME' => $fields[
'UNIT'],
335 'TYPE' => Types::DROPDOWN,
337 'ITEMS' => $currencyItems,
345 private function getStatusDropdownItems(?
bool $default =
null): array
352 'NAME' =>
Loc::getMessage(
'CATALOG_GRID_PANEL_UI_PRODUCT_ACTION_SET_PARAMETERS_DEFAULT_VALUE', [
353 '#VALUE#' => $default ?
Loc::getMessage(
'MAIN_YES') : Loc::getMessage(
'MAIN_NO'),
355 'VALUE' => ProductTable::STATUS_DEFAULT,
371 private function getVatIdDropdownItems(): array
389 if ($rows->getSelectedRowsCount() > 0)
393 'NAME' =>
Loc::getMessage(
'CATALOG_GRID_PANEL_UI_PRODUCT_ACTION_SET_PARAMETERS_NOT_SELECTED'),
397 foreach ($rows as $row)
400 'VALUE' => $row[
'ID'],
401 'NAME' => $row[
'NAME'],
408 private function getMeasureDropdownItems(): array
412 $rows = CCatalogMeasure::getList();
413 while ($row = $rows->Fetch())
416 'VALUE' => $row[
'ID'],
417 'NAME' => $row[
'MEASURE_TITLE'],
424 private function isAvailableField(
string $fieldName): bool
426 $dropdownItems = $this->getParametersDropdownControl()[
'ITEMS'];
427 $dropdownItemsNames = array_column($dropdownItems,
'VALUE');
429 return in_array($fieldName, $dropdownItemsNames,
true);
static getMessage($code, $replace=null, $language=null)