• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/migration/migrate.php
  • Класс: BitrixSaleLocationMigrationCUpdaterLocationPro
  • Вызов: CUpdaterLocationPro::grabTree
private function grabTree()
{
	$this->data['LOC'] = array();

	$auxIndex = array(
		'COUNTRY' => array(),
		'REGION' => array(),
		'CITY' => array()
	);

	$this->data['LOC'] = array(
		'COUNTRY' => array(),
		'REGION' => array(),
		'CITY' => array()
	);

	// level 1: country
	$res = CSaleLocation::GetList(array(), array(
		'!COUNTRY_ID' => false,
		'REGION_ID' => false,
		'CITY_ID' => false,
		'LID' => 'en'
	));

	while($item = $res->Fetch())
	{
		if(!isset($this->data['LOC']['COUNTRY'][$item['ID']]))
		{
			$this->data['LOC']['COUNTRY'][$item['ID']] = array(
				'SUBJ_ID' => $item['COUNTRY_ID'],
				'PARENT_ID' => false,
				'PARENT_TYPE' => false
			);
			$auxIndex['COUNTRY'][$item['COUNTRY_ID']] = $item['ID'];
		}
	}

	// level 2: country - region
	$res = CSaleLocation::GetList(array(), array(
		//'!COUNTRY_ID' => false,
		'!REGION_ID' => false,
		'CITY_ID' => false,
		'LID' => 'en'
	));

	while($item = $res->Fetch())
	{
		if(!isset($this->data['LOC']['REGION'][$item['ID']]))
		{
			$this->data['LOC']['REGION'][$item['ID']] = array(
				'SUBJ_ID' => $item['REGION_ID'],
				'PARENT_ID' => $auxIndex['COUNTRY'][$item['COUNTRY_ID']],
				'PARENT_TYPE' => 'COUNTRY'
			);
			$auxIndex['REGION'][$item['REGION_ID']] = $item['ID'];
		}
	}

	// level 2: country - city
	$res = CSaleLocation::GetList(array(), array(
		//'!COUNTRY_ID' => false,
		'REGION_ID' => false,
		'!CITY_ID' => false,
		'LID' => 'en'
	));

	while($item = $res->Fetch())
	{
		if(!isset($this->data['LOC']['CITY'][$item['ID']]))
			$this->data['LOC']['CITY'][$item['ID']] = array(
				'SUBJ_ID' => $item['CITY_ID'],
				'PARENT_ID' => $auxIndex['COUNTRY'][$item['COUNTRY_ID']],
				'PARENT_TYPE' => 'COUNTRY'
			);
	}

	// level 3: country - region - city
	$res = CSaleLocation::GetList(array(), array(
		//'!COUNTRY_ID' => false,
		'!REGION_ID' => false,
		'!CITY_ID' => false,
		'LID' => 'en'
	));

	while($item = $res->Fetch())
	{
		if(!isset($this->data['LOC']['CITY'][$item['ID']]))
			$this->data['LOC']['CITY'][$item['ID']] = array(
				'SUBJ_ID' => $item['CITY_ID'],
				'PARENT_ID' => $auxIndex['REGION'][$item['REGION_ID']],
				'PARENT_TYPE' => 'REGION'
			);
	}

	// language list
	$lang = new CLanguage();
	$res = $lang->GetList();
	$this->data['LANG'] = array();
	while($item = $res->Fetch())
		$this->data['LANG'][] = $item['LID'];

	// type list
	$res = LocationTypeTable::getList();
	while($item = $res->Fetch())
		$this->data['TYPE'][$item['CODE']] = $item['ID'];
}