25 return intval($fields[
'ID']) > 0 ? intval($fields[
'ID']) : 0;
43 return isset($fields[
'CODE']) && $fields[
'CODE'] !==
'' ? $fields[
'CODE'] :
'';
51 public static function getZipCode($ip, $lang = LANGUAGE_ID)
58 $result = $data->getGeoData()->zipCode <>
'' ? $data->getGeoData()->zipCode :
'';
68 protected static function getData($ip, $lang)
80 if(!$geoIpData->isSuccess())
85 $geoData = $geoIpData->getGeoData();
87 if($geoData->cityName ==
null)
92 $res = LocationTable::getList([
94 '=NAME.NAME_UPPER' => ToUpper($geoData->cityName),
95 '=NAME.LANGUAGE_ID' => $lang
97 'select' => [
'ID',
'CODE',
'LEFT_MARGIN',
'RIGHT_MARGIN']
102 while($loc = $res->fetch())
104 $locations[$loc[
'ID']] = $loc;
108 $locationsCount = count($locations);
110 if($locationsCount == 1)
112 $result = current($locations);
114 elseif($locationsCount > 1)
124 return empty($geoData->countryName) && empty($geoData->subRegionName) && empty($geoData->regionName);
129 if(empty($locations))
134 if(self::isParentsEmpty($geoData))
137 return current($locations);
140 $marginConditions = [
144 foreach($locations as $location)
146 $marginConditions[] = [
148 '<LEFT_MARGIN' => $location[
'LEFT_MARGIN'],
149 '>RIGHT_MARGIN' => $location[
'RIGHT_MARGIN']
156 'NAME.LANGUAGE_ID' => $lang,
159 'ID',
'LEFT_MARGIN',
'RIGHT_MARGIN',
160 'LOCATION_NAME_UPPER' =>
'NAME.NAME_UPPER'
164 $res = \Bitrix\Sale\Location\LocationTable::getList($params);
168 $country = $normalizer->normalize($geoData->countryName);
169 $region = $normalizer->normalize($geoData->regionName);
170 $subRegion = $normalizer->normalize($geoData->subRegionName);
172 while($loc = $res->fetch())
175 $normalizer->normalize($loc[
'LOCATION_NAME_UPPER']),
185 foreach($locationIds as $locationId)
187 if(!isset($locationId))
189 $weight[$locationId] = 0;
192 $weight[$locationId]++;
203 if(isset($locations[$id]))
205 $result = $locations[$id];
216 foreach($locations as $locationId => $location)
218 if($location[
'LEFT_MARGIN'] >= $leftMargin && $location[
'RIGHT_MARGIN'] <= $rightMargin)
220 $result[] = $location[
'ID'];
244 static $normalizer =
null;
246 if($normalizer ===
null)
251 $name = $normalizer->normalize($name);
253 return $normalizer->normalize($geoData->countryName) == $name
254 || $normalizer->normalize($geoData->regionName) == $name
255 || $normalizer->normalize($geoData->subRegionName) == $name;
274 if($country ==
'' && $region ==
'' && $subregion ==
'')
284 $result = $country === $name;
288 if((!$checked || !$result) && $region !==
'')
290 $result = $region === $name;
294 if((!$checked || !$result) && $subregion !==
'')
296 $result = $subregion === $name;
static getDataResult($ip='', $lang='', array $required=[])
static getLocationFields(Result $geoIpData, $lang=LANGUAGE_ID)
static isNameMatched(Data $geoData, $name, $lang)
static getNameNormalizer($lang)
static specifyLocationByParents(Data $geoData, array $locations, $lang)
static getData($ip, $lang)
static isParentsEmpty(Data $geoData)
static isNormalizedNamesMatched($name, $country, $region, $subregion)
static getLocationIdsByMargins(array $locations, $leftMargin, $rightMargin)
static getLocationCode($ip='', $lang=LANGUAGE_ID)
static getLocationId($ip='', $lang=LANGUAGE_ID)
static getZipCode($ip, $lang=LANGUAGE_ID)