• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/import/compiler/compiler.php
  • Класс: BitrixSaleLocationImportCompilerCompiler
  • Вызов: Compiler::generateExportTreeUSA
private function generateExportTreeUSA()
{
	$this->eTreeDB->dropCodeIndex();
	$this->eTreeDB->restoreExportOffset();

	$this->eTreeDB->switchIndexes(false);

	$csv = new ImportCSVReader();
	$csv->loadFile($_SERVER['DOCUMENT_ROOT'].'/locations_data/'.self::USA_SOURCE);
	
	$lastOnes = array();

	while($item = $csv->Fetch())
	{
		$item = explode(',', $item[0]);

		if(!isset($item[1])) // its a language marker
			continue;

		$parentId = '';

		if($item[0] == 'S')
			$type = 'COUNTRY';
		if($item[0] == 'R')
			$type = 'REGION';
		if($item[0] == 'T')
			$type = 'CITY';

		$id = implode(':', $item);

		if($type == 'REGION')
			$parentId = $lastOnes['COUNTRY'];
		elseif($type == 'CITY')
			$parentId = $lastOnes['PARENT'];
		else
			$parentId = '';

		if($type != 'CITY')
		{
			$lastOnes[$type] = $id;
			$lastOnes['PARENT'] = $id;
		}

		if($item['2'] == 'USA')
			$item['4'] = 'США';

		$this->eTreeDB->insert(array(
			'TYPE_CODE' => 		$type,
			'NAME' => 			$item[4],
			'LANGNAMES' => 		serialize(array(
				'RU' => array('NAME' => $item[4]),
				'EN' => array('NAME' => $item[2])
			)),
			'EXTERNALS' =>		'',
			'SOURCE' => 		self::SOURCE_LEGACY,

			'SYS_CODE' => $this->mapETCodeAsLegacy($id),
			'PARENT_SYS_CODE' => strlen($parentId) ? $this->mapETCodeAsLegacy($parentId) : ''
		));
	}

	$this->eTreeDB->doneInsert();
	$this->eTreeDB->switchIndexes(true);
}