27 return Loc::getMessage(
'CATALOG_PRODUCT_SYSTEMFIELD_PRODUCTMAPPING_SET_DEFAULT_VALUE_STEPPER_TITLE');
41 $fieldDescription = ProductMapping::getUserFieldBaseParam();
44 if (!isset($option[
'is_started']))
46 return $this->firstRun($option);
49 if (empty($option[
'count']))
55 $defaultValues = $this->getDefaultValues();
61 $lastId = (int)($option[
'last_id'] ?? 0);
62 $products = $this->getProductsWithEmptyValue($lastId);
69 $db->startTransaction();
72 $fieldId = $fieldDescription[
'FIELD_NAME'];
73 foreach ($products as $row)
75 $productId = (int)$row[
'id'];
76 $userFieldManager->Update(
80 $fieldId => $defaultValues,
87 $db->commitTransaction();
91 $db->rollbackTransaction();
101 $option[
'steps'] += $stepCount;
102 $option[
'last_id'] = $lastId;
114 private function firstRun(array & $option): bool
117 $helper = $connection->getSqlHelper();
119 $existUfTable = $connection->query(
"SHOW TABLES LIKE 'b_uts_product'")->getSelectedRowsCount() > 0;
125 $existUfColumn = $connection->query(
126 "SHOW COLUMNS FROM " . $helper->quote(
'b_uts_product') .
" LIKE 'UF_PRODUCT_MAPPING'"
127 )->getSelectedRowsCount() > 0;
133 if (!$this->isNotEmptyProducts())
138 $count = $this->getProductsToBeProcessedTotalCount();
144 $option[
'count'] = $count;
146 $option[
'is_started'] =
true;
147 $option[
'last_id'] =
null;
160 private function getProductsQuery(
bool $isCountSelect =
false,
int $lastId = 0): string
163 $helper = $connection->getSqlHelper();
165 $typeIds = join(
',', [
171 $select =
'b_catalog_product.id as ' . $helper->quote(
'id');
174 $select =
'COUNT(b_catalog_product.id)';
180 $where =
new SqlExpression(
"AND b_catalog_product.id > ?i", $lastId);
185 FROM b_catalog_product
186 LEFT JOIN b_uts_product ON b_catalog_product.id = b_uts_product.value_id
187 WHERE b_catalog_product.TYPE in ({$typeIds})
188 AND b_uts_product.UF_PRODUCT_MAPPING IS NULL {$where}
189 " . ($isCountSelect ?
"" :
"ORDER BY b_catalog_product.id ASC") .
"
199 private function getProductsWithEmptyValue(
int $lastId): Result
202 $sql = $this->getProductsQuery(
false, $lastId);
212 private function getProductsToBeProcessedTotalCount(): int
214 $sql = $this->getProductsQuery(
true);
219 private function isNotEmptyProducts(): bool
233 private function getDefaultValues(): ?array
235 $config = ProductMapping::getConfig();
236 $tableName = $config[
'HIGHLOADBLOCK'][
'TABLE_NAME'] ??
null;
244 new SqlExpression(
"SELECT ID FROM ?# WHERE UF_XML_ID = 'LANDING'", $tableName)
252 $option = \Bitrix\Main\Config\Option::get(
253 'main.stepper.catalog',
259 if ($option !==
null)
265 if (!CheckSerializedData($option))
271 $option = unserialize($option, [
'allowed_classes' =>
false]);
272 if (empty($option) || !is_array($option))
278 if (empty($option[
'count']))
288 \Bitrix\Main\Config\Option::delete(
289 'main.stepper.catalog',
static getConnection($name="")
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getRow(array $parameters)