• Модуль: crmmobile
  • Путь к файлу: ~/bitrix/modules/crmmobile/lib/Command/SaveEntityCommand.php
  • Класс: BitrixCrmMobileCommandSaveEntityCommand
  • Вызов: SaveEntityCommand::saveFactoryBasedEntities
private function saveFactoryBasedEntities(array $fields): Result
{
	$result = new Result();

	$entityId = $this->entity->getId();
	$isNew = $entityId === 0;
	if ($isNew)
	{
		$operation = $this->factory->getAddOperation($this->entity, $this->context);
	}
	else
	{
		$operation = $this->factory->getUpdateOperation($this->entity, $this->context);
	}

	$productRows = $this->extractProductRowsData($fields);
	if (is_array($productRows))
	{
		$this->setProductRows($productRows);
		$res = (new UpdateCatalogProductsCommand($productRows))->execute();
		if (!$res->isSuccess())
		{
			$result->addErrors($res->getErrors());
			return $result;
		}
	}

	$this->entity->setFromCompatibleData($fields);

	$res = $operation->launch();
	if ($res->isSuccess())
	{
		$result->setData(['ID' => $this->entity->getId()]);

		$this->onSavedFactoryBasedEntities($fields);
	}
	else
	{
		$result->addErrors($res->getErrors());
	}

	return $result;
}