- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/location/external.php
- Класс: BitrixSaleLocationExternalTable
- Вызов: ExternalTable::updateMultipleForOwner
static function updateMultipleForOwner($primaryOwner, $external)
{
$primaryOwner = Assert::expectIntegerPositive($primaryOwner, '$primaryOwner');
$res = self::getList(array(
'filter' => array('LOCATION_ID' => $primaryOwner)
));
$existed = array();
while($item = $res->fetch())
$existed[$item['ID']][$item['SERVICE_ID']] = $item['XML_ID'];
foreach($external as $id => $data)
{
$data['REMOVE'] ??= false;
$data['SERVICE_ID'] ??= 0;
$data['XML_ID'] = (string)($data['XML_ID'] ?? '');
$serivceId = (int)$data['SERVICE_ID'];
$id = (int)$id;
if (isset($existed[$id]))
{
if ($data['XML_ID'] === '' || !$serivceId || $data['REMOVE'])
{
// field either empty or prepared to remove
self::delete($id);
}
else
{
$res = self::update(
$id,
[
'SERVICE_ID' => $serivceId,
'XML_ID' => $data['XML_ID'],
]
);
if (!$res->isSuccess())
{
throw new MainSystemException(Loc::getMessage('SALE_LOCATION_EXTERNAL_ENTITY_CANNOT_UPDATE_DATA_EXCEPTION'));
}
}
}
else
{
if ($serivceId && $data['XML_ID'] !== '')
{
$res = self::add([
'SERVICE_ID' => $serivceId,
'XML_ID' => $data['XML_ID'],
'LOCATION_ID' => $primaryOwner,
]);
if (!$res->isSuccess())
{
throw new MainSystemException(Loc::getMessage('SALE_LOCATION_EXTERNAL_ENTITY_CANNOT_ADD_DATA_EXCEPTION'));
}
}
}
}
}