• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/paysystem/cashbox/events/togglecashboxesonupdatepaysystem.php
  • Класс: BitrixSalePaySystemCashboxEventsToggleCashboxesOnUpdatePaySystem
  • Вызов: ToggleCashboxesOnUpdatePaySystem::executeEvent
public function executeEvent(): SaleResult
{
	$result = new SaleResult();

	if (!$this->service || !$this->service->isSupportPrintCheck())
	{
		return $result;
	}

	if (
		!isset($this->oldFields['ACTIVE'], $this->newFields['ACTIVE'])
		||
		(
			isset($this->oldFields['ACTIVE'], $this->newFields['ACTIVE'])
			&& $this->oldFields['ACTIVE'] === $this->newFields['ACTIVE']
		)
	)
	{
		return $result;
	}

	$newStatus = $this->newFields['ACTIVE'];

	/** @var SaleCashboxCashboxPaySystem $cashboxClass */
	$cashboxClass = $this->service->getCashboxClass();

	$kkmId = $this->getKkmID();

	if ($this->isCashboxUsedByOtherPaySystems())
	{
		return $result;
	}

	$cashboxList = SaleCashboxManager::getList([
		'select' => ['ID', 'KKM_ID'],
		'filter' => [
			'=HANDLER' => $cashboxClass,
			'=KKM_ID' => $kkmId,
		],
	]);
	foreach ($cashboxList as $cashboxItem)
	{
		$updateResult = SaleCashboxManager::update($cashboxItem['ID'], ['ACTIVE' => $newStatus]);
		if (!$updateResult->isSuccess())
		{
			$result->addErrors($updateResult->getErrors());
		}
	}

	return $result;
}