2namespace Bitrix\Sale\Delivery\Pecom;
7use Bitrix\Main\Text\Encoding;
8use Bitrix\Sale\Location\Comparator;
9use Bitrix\Main\ArgumentNullException;
10use Bitrix\Sale\Location\ExternalTable;
11use Bitrix\Sale\Location\LocationTable;
12use Bitrix\Sale\Delivery\ExternalLocationMap;
14Loader::registerAutoLoadClasses(
17 'Bitrix\\Sale\\Delivery\\Pecom\\Replacement' =>
'ru/delivery/pecom/replacement.php'
28 const CSV_FILE_PATH =
'/bitrix/modules/sale/ru/delivery/pecom/location.csv';
30 public static function compare($startKey = 0, $timeout = 0, $updateExist =
false)
36 if(intval($srvId) <= 0)
40 $res = static::getAllLocations();
44 $locations =
$res->getData();
46 if(is_array($locations) && !empty($locations))
48 $lastKey = static::mapByNames($locations, $srvId, $startKey, $timeout, $updateExist);
50 'LAST_KEY' => $lastKey
72 protected static function mapByNames($locations, $srvId, $startKey = 0, $timeout = 0, $updateExist =
false)
79 $xmlIdExist =
array();
80 $locationIdExist =
array();
86 '=SERVICE_ID' => $srvId
92 $xmlIdExist[] =
$map[
'XML_ID'];
93 $locationIdExist[] =
$map[
'LOCATION_ID'];
101 $xmlId =
$location[self::CITY_XML_ID_IDX];
103 if($startKey <= 0 || $key >= $startKey)
105 if(!in_array($xmlId, $xmlIdExist))
107 $cityName =
$location[static::CITY_NAME_IDX];
110 $locationId = static::getLocationIdByNames($cityName,
'', $districtName,
$location[static::REGION_NAME_IDX],
'',
true);
113 $locationId = static::getLocationIdByNames($cityName,
'', $districtName,
$location[static::REGION_NAME_IDX],
'',
false);
115 if(intval($locationId) > 0 && !in_array($locationId, $locationIdExist))
125 unset($locations[
$key]);
127 if($timeout > 0 && (mktime(
true)-
$startTime) >= $timeout)
131 return intval(
$key) > 0 ? intval(
$key) : 0;
145 $http = new \Bitrix\Main\Web\HttpClient(
array(
147 "socketTimeout" => 30,
148 "streamTimeout" => 30,
151 "disableSslVerification" =>
true
154 $jsnData = $http->get(
"https://www.pecom.ru/ru/calc/towns.php");
157 if (!$jsnData && !empty(
$errors))
159 foreach(
$errors as $errorCode => $errMes)
165 $data = json_decode($jsnData,
true);
170 $cityRegionSame =
array();
173 $emptyRegions =
array();
178 foreach(
$data as $regionCity => $city)
180 $regionCity = mb_strtoupper($regionCity);
181 $regionName = !empty($regions[$regionCity][
'REGION']) ? $regions[$regionCity][
'REGION'] :
'';
183 if($regionName ==
'')
187 if($regionCity == $cName)
189 $regionName = $rName;
195 foreach($city as $cityId => $cityName)
197 $cityName = mb_strtoupper($cityName);
200 if(mb_strpos($cityName,
'(') !==
false && mb_strpos($cityName,
')') !==
false)
202 elseif($cityName == $regionCity)
204 elseif($regionCity ==
'' || $regionCity ==
'-' || $regionCity ==
'--')
222 $result->addError(
new Error(
"Can decode pecom cities data!"));
236 if(empty($cityNames))
246 '=NAME.NAME_UPPER' => $cityNames,
247 '=NAME.LANGUAGE_ID' => LANGUAGE_ID,
248 '=PARENTS.NAME.LANGUAGE_ID' => LANGUAGE_ID
251 'NAME_UPPER' =>
'NAME.NAME_UPPER',
252 'PARENTS_TYPE_CODE' =>
'PARENTS.TYPE.CODE' ,
253 'PARENTS_NAME_UPPER' =>
'PARENTS.NAME.NAME_UPPER'
257 while($loc =
$res->fetch())
259 if(!isset(
$result[$loc[
'NAME_UPPER']]))
262 $result[$loc[
'NAME_UPPER']][$loc[
'PARENTS_TYPE_CODE']] = $loc[
'PARENTS_NAME_UPPER'];
278 if(preg_match(
'/(.*)\s*\((.*)\)/iu', $cityName,
$matches))
285 if(!preg_match(
'/('.$mark.
'){1}/iu',
$result))
static setExternalLocation($srvId, $locationId, $xmlId, $updateExist=false)
static getExternalServiceId()
static fillNormalizedTable($startId=false, $timeout=0)
const EXTERNAL_SERVICE_CODE
static extractDistrict(&$cityName)
static compare($startKey=0, $timeout=0, $updateExist=false)
static getParents(array $cityNames)
static mapByNames($locations, $srvId, $startKey=0, $timeout=0, $updateExist=false)
static setMap(array $cities)
static getRegionExceptions()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key