• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/entityaddress.php
  • Класс: Bitrix\Crm\EntityAddress
  • Вызов: EntityAddress::onLocationAddressUpdate
static function onLocationAddressUpdate(/** @var $event Main\ORM\Event */ $event)
{
	$param = $event->getParameter('id');
	$locationAddressId = isset($param['ID']) ? (int)$param['ID'] : 0;
	if ($locationAddressId > 0 && static::isLocationModuleIncluded())
	{
		$res = AddressTable::getList(
			['filter' => ['=LOC_ADDR_ID' => $locationAddressId]]
		);
		while ($row = $res->fetch())
		{
			$locationAddress = Address::load($locationAddressId);
			if ($locationAddress instanceof Address)
			{
				$data = static::getFieldsByLocationAddress($locationAddress);
				$country = isset($data['COUNTRY']) ? $data['COUNTRY'] : '';
				$countryCode = $row['COUNTRY_CODE'];
				if ($country !== $row['COUNTRY'])
				{
					$countryCode = isset($data['COUNTRY_CODE']) ? $data['COUNTRY_CODE'] : '';
					if ($countryCode !== ''
						&& ($country === '' || !self::checkCountryCaption($countryCode, $country)))
					{
						$countryCode = '';
					}
				}
				$fields = [
					'TYPE_ID' => $row['TYPE_ID'],
					'ENTITY_TYPE_ID' => $row['ENTITY_TYPE_ID'],
					'ENTITY_ID' => $row['ENTITY_ID'],
					'ANCHOR_TYPE_ID' => $row['ANCHOR_TYPE_ID'],
					'ANCHOR_ID' => $row['ANCHOR_ID'],
					'ADDRESS_1' => isset($data['ADDRESS_1']) ? $data['ADDRESS_1'] : '',
					'ADDRESS_2' => isset($data['ADDRESS_2']) ? $data['ADDRESS_2'] : '',
					'CITY' => isset($data['CITY']) ? $data['CITY'] : '',
					'POSTAL_CODE' => isset($data['POSTAL_CODE']) ? $data['POSTAL_CODE'] : '',
					'REGION' => isset($data['REGION']) ? $data['REGION'] : '',
					'PROVINCE' => isset($data['PROVINCE']) ? $data['PROVINCE'] : '',
					'COUNTRY' => $country,
					'COUNTRY_CODE' => $countryCode,
					'LOC_ADDR_ID' => $locationAddressId,
					'IS_DEF' => ($row['IS_DEF'] == 1 || $row['IS_DEF'] === true)
				];

				AddressTable::upsert($fields);

				//region Register volatile duplicate criterion fields
				DuplicateVolatileCriterion::register(
					(int)$row['ENTITY_TYPE_ID'],
					(int)$row['ENTITY_ID'],
					[FieldCategory::ADDRESS]
				);
				//endregion Register volatile duplicate criterion fields

				//region Send event
				$event = new Main\Event('crm', 'OnAfterAddressRegister', array('fields' => $fields));
				$event->send();
				//endregion Send event
			}
		}
	}
}