• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/import/import.php
  • Класс: BitrixSaleLocationImportImportProcess
  • Вызов: ImportProcess::importBlock
protected function importBlock(&$block)
{
	if(empty($block))
		return;

	$gid = $this->getCurrentGid();

	foreach($block as $i => $data)
	{
		$code = $data['CODE'];

		if(isset($this->data['existedlocs']['static'][$code]) || isset($this->data['existedlocs'][$gid][$code])) // already exists
			continue;

		if(!isset($this->data['types']['allowed'][$data['TYPE_CODE']])) // disallowed
			continue;

		// have to check existence first
		if(!$this->data['TABLE_WERE_EMPTY'])
		{
			$existedId = $this->checkLocationCodeExists($code);

			if(intval($existedId))
			{
				$this->data['existedlocs'][$gid][$code] = $existedId;
				continue;
			}
		}

		///////////////////////////////////////////
		// transform parent
		if(strlen($data['PARENT_CODE']))
		{
			if(isset($this->data['existedlocs']['static'][$data['PARENT_CODE']]))
			{
				$data['PARENT_ID'] = $this->data['existedlocs']['static'][$data['PARENT_CODE']];
			}
			elseif(isset($this->data['existedlocs'][$gid][$data['PARENT_CODE']]))
			{
				$data['PARENT_ID'] = $this->data['existedlocs'][$gid][$data['PARENT_CODE']];
			}
			else
				$data['PARENT_ID'] = 0;
		}
		else
			$data['PARENT_ID'] = 0;

		unset($data['PARENT_CODE']);

		///////////////////////////////////////////
		// transform type
		$data['TYPE_ID'] = $this->data['types']['code2id'][$data['TYPE_CODE']];
		unset($data['TYPE_CODE']);

		///////////////////////////////////////////
		// add
		$names = $data['NAME'];
		unset($data['NAME']);

		$external = $data['EXT'];
		unset($data['EXT']);

		$data['LONGITUDE'] = floatval($data['LONGITUDE']);
		$data['LATITUDE'] = floatval($data['LATITUDE']);
		if(!$this->checkExternalServiceAllowed('GEODATA'))
		{
			$data['LONGITUDE'] = 0;
			$data['LATITUDE'] = 0;
		}

		$locationId = $this->hitData['HANDLES']['LOCATION']->insert($data);

		// store for further PARENT_CODE to PARENT_ID mapping
		//if(!strlen($this->data['types']['last']) || $this->data['types']['last'] != $data['TYPE_CODE'])
			$this->data['existedlocs'][$gid][$data['CODE']] = $locationId;

		///////////////////////////////////////////
		// add names
		if(is_array($names) && !empty($names))
		{
			foreach($names as $lid => $name)
			{
				if(strlen($name['NAME']))
				{
					$this->hitData['HANDLES']['NAME']->insert(array(
						'NAME' => $name['NAME'],
						'NAME_UPPER' => ToUpper($name['NAME']),
						'LANGUAGE_ID' => ToLower($lid),
						'LOCATION_ID' => $locationId
					));
				}
			}
		}

		///////////////////////////////////////////
		// add external
		if(is_array($external) && !empty($external))
		{
			foreach($external as $sCode => $values)
			{
				if($this->checkExternalServiceAllowed($sCode))
				{
					$serviceId = $this->data['externalService']['code2id'][$sCode];
					if(!$serviceId)
						throw new MainSystemException('Location import failed: external service doesnt exist');

					foreach($values as $val)
					{
						if(!strlen($val))
							continue;

						$this->hitData['HANDLES']['EXTERNAL']->insert(array(
							'SERVICE_ID' => 	$serviceId,
							'XML_ID' => 		$val,
							'LOCATION_ID' => 	$locationId
						));
					}
				}
			}
		}
	}
}