• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/delivery/externallocationmap.php
  • Класс: BitrixSaleDeliveryfor
  • Вызов: for::setMap
static function setMap(array $cities)
{
	$result = new Result();

	if(empty($cities))
		throw new ArgumentNullException('cities');

	$xmlIdExist = array();
	$locationIdExist = array();
	$xmlIds = array_keys($cities);
	$srvId = static::getExternalServiceId();

	$res = ExternalTable::getList(array(
			'filter' => array(
					'=SERVICE_ID' => $srvId
			)
	));

	while($map = $res->fetch())
	{
		$xmlIdExist[] = $map['XML_ID'];
		$locationIdExist[] = $map['LOCATION_ID'];

		//we already have this location
		if(in_array($map['XML_ID'], $xmlIds))
			unset($cities[$map['XML_ID']]);
	}

	//nothing to import
	if(empty($cities))
		return $result;

	foreach($cities as $city)
	{
		$xmlId = $city[self::CITY_XML_ID_IDX];
		$locId = static::getLocationIdByNames($city[static::CITY_NAME_IDX], '', '', $city[static::REGION_NAME_IDX]);

		if(intval($locId) > 0 && !in_array($xmlId, $xmlIdExist) && !in_array($locId, $locationIdExist))
		{
			ExternalTable::add(array(
				'SERVICE_ID' => $srvId,
				'LOCATION_ID' => $locId,
				'XML_ID' => $xmlId
			));

			$xmlIdExist[] = $xmlId;
			$locationIdExist[] = $locId;
		}

		unset($cities[$xmlId]);
	}

	return $result;
}