- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/location/geoip.php
- Класс: BitrixSaleLocationGeoIp
- Вызов: GeoIp::getLocationFields
static function getLocationFields(Result $geoIpData, $lang = LANGUAGE_ID)
{
if(!$geoIpData->isSuccess())
{
return [];
}
$geoData = $geoIpData->getGeoData();
if($geoData->cityName == null)
{
return [];
}
$res = LocationTable::getList([
'filter' => [
'=NAME.NAME_UPPER' => ToUpper($geoData->cityName),
'=NAME.LANGUAGE_ID' => $lang
],
'select' => ['ID', 'CODE', 'LEFT_MARGIN', 'RIGHT_MARGIN']
]);
$locations = [];
while($loc = $res->fetch())
{
$locations[$loc['ID']] = $loc;
}
$result = [];
$locationsCount = count($locations);
if($locationsCount == 1)
{
$result = current($locations);
}
elseif($locationsCount > 1)
{
$result = self::specifyLocationByParents($geoData, $locations, $lang);
}
return $result;
}