- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/paysystem/cashbox/events/updatecashboxesonbusinessvalueupdate.php
- Класс: BitrixSalePaySystemCashboxEventsUpdateCashboxesOnBusinessValueUpdate
- Вызов: UpdateCashboxesOnBusinessValueUpdate::executeEvent
public function executeEvent(): SaleResult
{
$valueUnchanged =
isset($this->oldMapping['PROVIDER_VALUE'], $this->newMapping['PROVIDER_VALUE'])
&& $this->oldMapping['PROVIDER_VALUE'] === $this->newMapping['PROVIDER_VALUE']
;
$isPaySystemValue = isset($this->consumerKey) && mb_strpos($this->consumerKey, Service::PAY_SYSTEM_PREFIX) === 0;
if (empty($this->oldMapping) || $valueUnchanged || !$isPaySystemValue)
{
return new SaleResult();
}
$paySystemIterator = SalePaySystemManager::getList([
'filter' => [
'=ACTIVE' => 'Y',
]
]);
while ($paySystemItem = $paySystemIterator->fetch())
{
$this->currentPaySystemService = new Service($paySystemItem);
if ($this->currentPaySystemService->getConsumerName() !== $this->consumerKey || !($this->currentPaySystemService->isSupportPrintCheck()))
{
continue;
}
/** @var SaleCashboxCashboxPaySystem $cashboxClass */
$cashboxClass = $this->currentPaySystemService->getCashboxClass();
$paySystemCodeForKkm = $cashboxClass::getPaySystemCodeForKkm();
if ($paySystemCodeForKkm !== $this->codeKey)
{
continue;
}
$cashboxesToChange = $this->getListOfCashboxesToChange();
$newKkmId = $this->newMapping['PROVIDER_VALUE'];
if ($this->valueHasBeenCleared())
{
$newKkmId = $this->getNewKkmId();
/*
* if we can't set a new ID, then it's
* impossible to use an existing cashbox
* or create a new one, so we have to
* delete the old cashbox
*/
if (empty($newKkmId))
{
$this->deleteCashboxesToChange();
continue;
}
$existingCashboxes = SaleCashboxManager::getList([
'select' => ['ID', 'KKM_ID'],
'filter' => [
'=HANDLER' => $cashboxClass,
'=KKM_ID' => $newKkmId,
],
]);
/**
* If any cashboxes with the default ID exist, we can use them
* We don't need any cashboxes with the old ids, and we
* also don't need to edit any cashboxes as the needed ones
* exist already
*/
if ($existingCashboxes->fetch())
{
$this->deleteCashboxesToChange();
continue;
}
}
foreach ($cashboxesToChange as $cashboxItem)
{
SaleCashboxManager::update($cashboxItem['ID'], ['KKM_ID' => $newKkmId]);
}
}
return new SaleResult();
}