• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/compatible/eventcompatibility.php
  • Класс: BitrixSaleCompatibleEventCompatibility
  • Вызов: EventCompatibility::onShipmentTrackingNumberChange
static function onShipmentTrackingNumberChange(MainEvent $event)
{
	if (static::$disableEvent === true)
	{
		return new MainEventResult( MainEventResult::SUCCESS, null, 'sale');
	}

	$parameters = $event->getParameters();

	/** @var SaleShipment $basketItem */
	$shipment = $parameters['ENTITY'];
	$oldValues = $parameters['VALUES'];
	if (!$shipment instanceof SaleShipment)
	{
		return new MainEventResult(
			MainEventResult::ERROR,
			new SaleResultError(MainLocalizationLoc::getMessage('SALE_EVENT_COMPATIBILITY_WRONG_SHIPMENT'), 'SALE_EVENT_COMPATIBILITY_SHIPMENT_TRACKING_NUMBER_CHANGE_WRONG_SHIPMENT'),
			'sale'
		);
	}

	/** @var SaleShipmentCollection $shipmentCollection */
	if (!$shipmentCollection = $shipment->getCollection())
	{
		throw new MainObjectNotFoundException('Entity "ShipmentCollection" not found');
	}

	/** @var SaleOrder $order */
	if (!$order = $shipmentCollection->getOrder())
	{
		throw new MainObjectNotFoundException('Entity "Order" not found');
	}

	static::setDisableEvent(true);
	foreach(GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ON_TRACKING_NUMBER_CHANGE, true) as $oldEvent)
	{
		ExecuteModuleEventEx($oldEvent, Array($order->getId(), $shipment->getField('TRACKING_NUMBER')));
	}
	static::setDisableEvent(false);

	if (array_key_exists('TRACKING_NUMBER', $oldValues) && strval($shipment->getField('TRACKING_NUMBER')) != ''
		&& $oldValues["TRACKING_NUMBER"] != $shipment->getField('TRACKING_NUMBER'))
	{

		$registry = SaleRegistry::getInstance($shipment::getRegistryType());

		/** @var SaleNotify $notifyClassName */
		$notifyClassName = $registry->getNotifyClassName();
		$notifyClassName::sendShipmentTrackingNumberChange($shipment);
	}

	return new MainEventResult( MainEventResult::SUCCESS, null, 'sale');
}