• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/systemfield/productmapping/setdefaultvaluestepper.php
  • Класс: BitrixCatalogProductSystemFieldProductMappingSetDefaultValueStepper
  • Вызов: SetDefaultValueStepper::execute
public function execute(array &$option)
{
	$userFieldManager = UserFieldHelper::getInstance()->getManager();

	if (!ProductMapping::isAllowed())
	{
		return self::FINISH_EXECUTION;
	}
	$fieldDescription = ProductMapping::getUserFieldBaseParam();

	// first run
	if (!isset($option['is_started']))
	{
		return $this->firstRun($option);
	}

	if (empty($option['count']))
	{
		return self::FINISH_EXECUTION;
	}

	// processing
	$defaultValues = $this->getDefaultValues();
	if (!$defaultValues)
	{
		return self::FINISH_EXECUTION;
	}

	$lastId = (int)($option['last_id'] ?? 0);
	$products = $this->getProductsWithEmptyValue($lastId);

	$stepCount = 0;

	$db = Application::getConnection();
	try
	{
		$db->startTransaction();

		$entityId = ProductTable::getUfId();
		$fieldId = $fieldDescription['FIELD_NAME'];
		foreach ($products as $row)
		{
			$productId = (int)$row['id'];
			$userFieldManager->Update(
				$entityId,
				$productId,
				[
					$fieldId => $defaultValues,
				]
			);
			$lastId = $productId;
			$stepCount++;
		}

		$db->commitTransaction();
	}
	catch (Throwable $e)
	{
		$db->rollbackTransaction();

		throw $e;
	}

	if ($stepCount === 0)
	{
		return self::FINISH_EXECUTION;
	}

	$option['steps'] += $stepCount;
	$option['last_id'] = $lastId;

	return self::CONTINUE_EXECUTION;
}