Delivery::onShipmentDeleted

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Delivery
  4. onShipmentDeleted
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/delivery.php
  • Класс: Bitrix\Crm\Activity\Provider\Delivery
  • Вызов: Delivery::onShipmentDeleted
static function onShipmentDeleted(int $shipmentId): void
{
	$shipmentBindingsList = ActivityBindingTable::getList([
		'filter' => [
			'OWNER_ID' => $shipmentId,
			'OWNER_TYPE_ID' => \CCrmOwnerType::OrderShipment,
		]
	]);
	while ($shipmentBinding = $shipmentBindingsList->fetch())
	{
		ActivityBindingTable::delete((int)$shipmentBinding['ID']);

		$activity = \CCrmActivity::GetByID((int)$shipmentBinding['ACTIVITY_ID'], false);
		if ($activity)
		{
			$shipmentIds =
				isset($activity['SETTINGS']['FIELDS']['SHIPMENT_ID'])
					? (
						is_array($activity['SETTINGS']['FIELDS']['SHIPMENT_ID'])
							? $activity['SETTINGS']['FIELDS']['SHIPMENT_ID']
							: [$activity['SETTINGS']['FIELDS']['SHIPMENT_ID']]
					)
					: []
			;

			$newShipmentIds = array_values(array_diff($shipmentIds, [$shipmentId]));
			if (empty($newShipmentIds))
			{
				\CCrmActivity::Delete((int)$activity['ID'], false);
			}
			else
			{
				$newSettings = $activity['SETTINGS'];
				$newSettings['FIELDS']['SHIPMENT_ID'] = $newShipmentIds;

				\CCrmActivity::update(
					$activity['ID'],
					['SETTINGS' => $newSettings],
					false
				);
			}
		}
	}
}

Добавить комментарий