76 if(!self::isLocationProEnabled())
85 <form action=
"" method=
"post">
127 <form action=
"" method=
"post">
129 <button name=
"l2migrated" value=
"<?=($l2migrated ? 'OFF' : 'ON')?>"><?=($l2migrated ?
'Go Down' :
'Go Up')?></button>
132 <form action=
"" method=
"post">
134 <button name=
"l2switch" value=
"<?=($l2enabled ? 'OFF' : 'ON')?>"><?=($l2enabled ?
'Turn OFF' :
'Turn ON')?></button>
137 <form action=
"" method=
"post">
139 <button name=
"l2debug" value=
"<?=($l2debug ? 'OFF' : 'ON')?>"><?=($l2debug ?
'Turn OFF' :
'Turn ON')?></button>
151 if(self::isLocationProEnabled())
153 if(!is_array($additionalParams))
154 $additionalParams =
array();
156 $parametersProxed = array_merge(
array(
157 "ID" => $parameters[
"LOCATION_VALUE"],
159 "INPUT_NAME" => $parameters[
"CITY_INPUT_NAME"],
161 "CACHE_TIME" =>
"36000000",
162 "PROVIDE_LINK_BY" =>
"id",
163 "SEARCH_BY_PRIMARY" =>
"N",
164 "SHOW_DEFAULT_LOCATIONS" =>
"N",
167 ), $additionalParams);
169 $siteExists = isset($parameters[
'SITE_ID']) && $parameters[
'SITE_ID'];
171 $siteExists || !defined(
'ADMIN_SECTION') ||
ADMIN_SECTION !=
'Y'
174 $parametersProxed[
"FILTER_BY_SITE"] =
"Y";
175 $parametersProxed[
"FILTER_SITE_ID"] = $siteExists ? $parameters[
'SITE_ID'] :
SITE_ID;
178 if($wrapNewComponentWith <>
'')
180 print(
'<div class="'.$wrapNewComponentWith.
'">');
184 $appearance = \Bitrix\Sale\Location\Admin\Helper::getWidgetAppearance();
187 $appearance =
'steps';
190 $appearance =
'search';
193 $GLOBALS[
"APPLICATION"]->IncludeComponent(
194 "bitrix:sale.location.selector.".$appearance,
198 array(
'HIDE_ICONS' => $hideIcons ?
'Y' :
'N')
201 if($wrapNewComponentWith)
206 $GLOBALS[
"APPLICATION"]->IncludeComponent(
207 'bitrix:sale.ajax.locations',
211 array(
'HIDE_ICONS' => $hideIcons ?
'Y' :
'N')
242 $item = Location\LocationTable::getList(
array(
265 $item = Location\LocationTable::getList(
array(
'filter' =>
array(
'=ID' => $id),
'select' =>
array(
'ID',
'CODE')))->fetch();
270 return $item[
'CODE'];
278 return ((
string) $id !== (
string) intval($id));
288 if($id !=
'' && $id === (
string) intval($id))
291 $location = \Bitrix\Sale\Location\LocationTable::getList(
array(
'filter' =>
array(
'=ID' => $id),
'select' =>
array(
'ID',
'CODE')))->fetch();
301 if($locationId <>
'')
308 array(
'=ID' => intval($locationId)),
309 array(
'=CODE' => $locationId)
331 $res = Location\TypeTable::getList(
array(
'select' =>
array(
'CODE',
'ID'),
'order' =>
array(
'SORT' =>
'asc')));
334 while($item =
$res->fetch())
336 if($item[
'CODE'] ==
'CITY')
340 $tail[$item[
'ID']] =
true;
347 private static function getLanguages()
350 $res = Localization\LanguageTable::getList();
351 while($item =
$res->fetch())
361 while($item =
$res->fetch())
374 $res = Location\TypeTable::getList();
375 while($item =
$res->fetch())
376 $types[$item[
'CODE']] = $item[
'ID'];
382 private static function getZipId()
384 $res = Location\ExternalServiceTable::getList(
array(
'filter' =>
array(
'=CODE' => self::ZIP_EXT_SERVICE_CODE),
'limit' => 1))->fetch();
392 private static function refineFieldsForSaveCRC($id,
$arFields)
394 if(!is_array(
$arFields[self::ORIGIN_NAME_LANGUAGE_ID]))
398 'LID' => self::ORIGIN_NAME_LANGUAGE_ID,
405 foreach(self::getLanguages() as $lid)
420 private static function getLocationIdByCountryId($legacyId)
422 $res = $item = Location\LocationTable::getList(
array(
424 '=TYPE.CODE' =>
'COUNTRY',
425 '=COUNTRY_ID' => intval($legacyId),
426 '=REGION_ID' =>
false,
437 private static function getLocationIdByCityId($legacyId)
439 $res = Location\LocationTable::getList(
array(
441 '=TYPE.CODE' =>
'CITY',
442 '=CITY_ID' => intval($legacyId),
452 private static function getLocationIdByRegionId($legacyId)
454 $res = Location\LocationTable::getList(
array(
456 '=TYPE.CODE' =>
'REGION',
457 '=REGION_ID' => intval($legacyId),
468 private static function checkLangPresenceInSelect(
$type,
$fields)
470 return in_array(
$type.
'_NAME_',
$fields,
true) || in_array(
$type.
'_SHORT_NAME',
$fields,
true) || in_array(
$type.
'_NAME',
$fields,
true) || in_array(
$type.
'_NAME_LANG',
$fields,
true) || in_array(
$type.
'_LID',
$fields,
true);
486 return ((
string) intval(
$val) === (
string)
$val);
492 $arSqlSearch = Array();
494 if(!in_array($typeCode,
array(
'COUNTRY',
'REGION',
'CITY')))
502 if(!isset($types[$typeCode]))
509 $arSqlSearch[] =
"L.TYPE_ID = '".intval($types[$typeCode]).
"'";
512 $filter_keys = Array();
519 $countFilterKey =
count($filter_keys);
520 for(
$i=0;
$i < $countFilterKey;
$i++)
523 if (
$val ==
'')
continue;
534 switch(mb_strtoupper(
$key))
538 if(self::checkIsRealInt(
$val))
549 $arSqlSearch[] =
"L.".$field.
" ".($bInvert?
"<>":
"=").
" '".
$val.
"' ";
552 $arSqlSearch[] =
"LLN.NAME ".($bInvert?
"<>":
"=").
" '".
$val.
"' ";
556 if(self::checkIsRealInt(
$val))
559 $arSqlSearch[] =
"L.COUNTRY_ID ".($bInvert?
"<>":
"=").
" '".
$val.
"' ";
565 $arSqlSearch[] =
"LCO.CODE ".($bInvert?
"<>":
"=").
" '".
$val.
"' ";
572 if(self::checkIsRealInt(
$val))
575 $arSqlSearch[] =
"L.REGION_ID ".($bInvert?
"<>":
"=").
" '".
$val.
"' ";
581 $arSqlSearch[] =
"LRE.CODE ".($bInvert?
"<>":
"=").
" '".
$val.
"' ";
589 $countSqlSearch =
count($arSqlSearch);
590 for(
$i=0;
$i < $countSqlSearch;
$i++)
592 $strSqlSearch .=
" AND ";
593 $strSqlSearch .=
" (".$arSqlSearch[
$i].
") ";
603 "SELECT L.ID as ID, L.CODE as CODE, LN.NAME as NAME_ORIG, LLN.SHORT_NAME as SHORT_NAME, LLN.NAME as NAME, L.SORT as SORT, ".
604 " CASE WHEN LLN.LOCATION_ID IS NULL THEN LN.NAME ELSE LLN.NAME END as NAME_LANG ".
605 "FROM b_sale_location L ".
606 " LEFT JOIN b_sale_loc_name LN ON (L.ID = LN.LOCATION_ID AND LN.LANGUAGE_ID = 'en') ".
607 " LEFT JOIN b_sale_loc_name LLN ON (L.ID = LLN.LOCATION_ID AND LLN.LANGUAGE_ID = '".$DB->ForSql($strLang, 2).
"') ".
610 " INNER JOIN b_sale_location LCO ON (L.COUNTRY_ID = LCO.ID) " :
614 " INNER JOIN b_sale_location LRE ON (L.REGION_ID = LRE.ID) " :
617 " WHERE 1 = 1 ".$strSqlSearch.
" ";
619 $arSqlOrder = Array();
620 foreach ($arOrder as $by=>
$order)
622 $by = mb_strtoupper($by);
626 if ($by ==
"SORT") $arSqlOrder[] =
" L.SORT ".$order;
627 elseif ($by ==
"ID") $arSqlOrder[] =
" L.ID ".$order.
" ";
628 elseif ($by ==
"NAME") $arSqlOrder[] =
" LN.NAME ".$order.
" ";
629 elseif ($by ==
"SHORT_NAME") $arSqlOrder[] =
" LN.SHORT_NAME ".$order.
" ";
632 $arSqlOrder[] =
" LLN.NAME ".$order.
" ";
639 $countSqlOrder =
count($arSqlOrder);
640 for (
$i=0;
$i < $countSqlOrder;
$i++)
643 $strSqlOrder =
" ORDER BY ";
645 $strSqlOrder .=
", ";
647 $strSqlOrder .= $arSqlOrder[
$i];
650 $strSql .= $strSqlOrder;
658 $res = Location\LocationTable::getById($id)->fetch();
660 return intval(
$res[
'ID']);
667 return intval(
$res[
'ID']);
672 $class = self::SELF_ENTITY_NAME.
'Table';
673 $item = $class::getList(
array(
'select' =>
array(
$type.
'_ID'),
'limit' => 1,
'order' =>
array(
$type.
'_ID' =>
'desc')))->fetch();
675 $fromLocTable = intval($item[
$type.
'_ID']);
678 $fromTypeTable =
$res[
'ID'];
680 return max($fromLocTable, $fromTypeTable) + 1;
694 array(
'='.$ctx.
'.TYPE_ID' =>
array(
'?', $types[
'COUNTRY'])),
695 array(
'='.$ctx.
'.TYPE_ID' =>
array(
'?', $types[
'REGION'])),
696 array(
'='.$ctx.
'.TYPE_ID' =>
array(
'?', $types[
'CITY'])),
709 return array($types[
'COUNTRY'], $types[
'REGION'], $types[
'CITY']);
724 preg_match(self::KEY_PARSE_R,
$k, $found);
729 'NOT' => $found[1] ==
'!',
730 'OP' => !mb_strlen($found[2])?
'=' : $found[2],
734 if(in_array(
$f[
'OP'], static::$allowedOps))
747 $class = $entityName.
'Table';
748 $linkField = $class::getLinkField();
749 $typeField = $class::getTypeField();
750 $locationLinkField = $class::getLocationLinkField();
752 $table = $class::getTableName();
753 $useCodes = $class::getUseCodes();
764 if(intval(
$filter[$linkField][
'VALUE']))
765 $where[] =
'DL.'.$linkField.
' '.(
$filter[$linkField][
'NOT'] ?
'!' :
'').
$filter[$linkField][
'OP'].
" '".intval(
$filter[$linkField][
'VALUE']).
"'";
767 if(intval(
$filter[
'LOCATION_ID'][
'VALUE']))
768 $where[] =
'LINK.ID '.($filter[
'LOCATION_ID'][
'NOT'] ?
'!' :
'').
$filter[
'LOCATION_ID'][
'OP'].
" '".intval(
$filter[
'LOCATION_ID'][
'VALUE']).
"'";
771 $where[] =
'DL.'.$typeField.
' '.(
$filter[$typeField][
'NOT'] ?
'!' :
'').
$filter[$typeField][
'OP'].
" '".
$filter[$typeField][
'VALUE'].
"'";
777 LINK.ID as LOCATION_ID,
782 ".$locationTable.
" L on DL.".$typeField.
" = '".$locFlag.
"' and DL.".$locationLinkField.
" = L.".($useCodes ?
'CODE' :
'ID').
"
784 ".$locationTable.
" LINK on LINK.LEFT_MARGIN >= L.LEFT_MARGIN and LINK.RIGHT_MARGIN <= L.RIGHT_MARGIN
786 ".(!empty($where) ?
'where '.implode(
' and ', $where) :
'').
"
792 LINK.ID as LOCATION_ID,
797 ".$groupTable.
" LINK on DL.".$typeField.
" = '".$grpFlag.
"' and DL.".$locationLinkField.
" = LINK.".($useCodes ?
'CODE' :
'ID').
"
799 ".(!empty($where) ?
'where '.implode(
' and ', $where) :
'').
"
804 return $DB->query($sql);
814 $locationString =
'';
819 $countryId = $regionId = $cityId = 0;
832 $arCityFilter =
array(
"!CITY_ID" =>
"NULL",
">CITY_ID" =>
"0");
834 $arCityFilter[
"COUNTRY_ID"] = $countryId;
836 if (!$rsLocCount->Fetch())
841 $arRegionFilter =
array(
"!REGION_ID" =>
"NULL",
">REGION_ID" =>
"0");
842 if ($countryId > 0 && $regionId > 0)
843 $arRegionFilter[
"COUNTRY_ID"] = $countryId;
845 $arRegionFilter[
"REGION_ID"] = $regionId;
847 if (!$rsLocCount->Fetch())
851 if ($bEmptyCity ==
"Y" && $bEmptyRegion ==
"Y")
853 $arCityFilter =
array(
"!CITY_ID" =>
"NULL",
">CITY_ID" =>
"0");
855 if ($rsLocCount->Fetch())
860 if ($locationId > 0 )
864 if ($bEmptyRegion ==
"Y" && $bEmptyCity ==
"Y")
865 $countryId = $locationId;
869 if ($bEmptyCity ==
"Y")
874 $cityId = $locationId;
879 $arCountryList =
array();
881 if ($bEmptyRegion ==
"Y" && $bEmptyCity ==
"Y")
886 while ($arCountry = $rsCountryList->GetNext())
891 if ($bEmptyRegion ==
"Y" && $bEmptyCity ==
"Y")
892 $arCountry[
"NAME_LANG"] = $arCountry[
"COUNTRY_NAME_LANG"];
894 $arCountryList[] = $arCountry;
895 if ($arCountry[
"ID"] == $countryId && $arCountry[
"NAME_LANG"] <>
'')
896 $locationString .= $arCountry[
"NAME_LANG"];
899 if (
count($arCountryList) <= 0)
900 $arCountryList =
array();
902 $countryId = $arCountryList[0][
"ID"];
905 $arRegionList =
array();
906 if ($countryId > 0 ||
count($arCountryList) <= 0)
908 $arRegionFilter =
array(
"LID" => $langId,
"!REGION_ID" =>
"NULL",
"!REGION_ID" =>
"0");
910 $arRegionFilter[
"COUNTRY_ID"] = intval($countryId);
912 if ($bEmptyCity ==
"Y")
913 $rsRegionList =
CSaleLocation::GetList(
array(
"SORT" =>
"ASC",
"NAME_LANG" =>
"ASC"), $arRegionFilter,
false,
false,
array(
"ID",
"REGION_ID",
"REGION_NAME_LANG"));
917 while ($arRegion = $rsRegionList->GetNext())
922 if ($bEmptyCity ==
"Y")
923 $arRegion[
"NAME_LANG"] = $arRegion[
"REGION_NAME_LANG"];
925 $arRegionList[] = $arRegion;
926 if ($arRegion[
"ID"] == $regionId && $arRegion[
"NAME_LANG"] <>
'')
927 $locationString = $arRegion[
"NAME_LANG"].
", ".$locationString;
930 if (
count($arRegionList) <= 0)
931 $arRegionList =
array();
933 $regionId = $arRegionList[0][
"ID"];
936 $arCityList =
array();
939 && ((
count($arCountryList) > 0 &&
count($arRegionList) > 0 && $countryId > 0 && $regionId > 0)
940 || (
count($arCountryList) <= 0 &&
count($arRegionList) > 0 && $regionId > 0)
941 || (
count($arCountryList) > 0 &&
count($arRegionList) <= 0 && $countryId > 0)
942 || (
count($arCountryList) <= 0 &&
count($arRegionList) <= 0))
945 $arCityFilter =
array(
"LID" => $langId);
947 $arCityFilter[
"COUNTRY_ID"] = $countryId;
949 $arCityFilter[
"REGION_ID"] = $regionId;
954 "COUNTRY_NAME_LANG" =>
"ASC",
955 "CITY_NAME_LANG" =>
"ASC"
961 "ID",
"CITY_ID",
"CITY_NAME"
965 while ($arCity = $rsLocationsList->GetNext())
970 $arCityList[] =
array(
971 "ID" => $arCity[
"ID"],
972 "CITY_ID" => $arCity[
'CITY_ID'],
973 "CITY_NAME" => $arCity[
"CITY_NAME"],
975 if ($arCity[
"ID"] == $cityId)
976 $locationString = ($arCity[
"CITY_NAME"] <>
'' ? $arCity[
"CITY_NAME"].
", " :
"").$locationString;
980 return $locationString;
1011 foreach (
GetModuleEvents(
"sale",
"OnBeforeCountryUpdate",
true) as $arEvent)
1017 if(self::isLocationProMigrated())
1022 $locId = self::getLocationIdByCountryId(
$ID);
1029 self::refineFieldsForSaveCRC($locId,
$arFields),
1030 array(
'REBALANCE' =>
false)
1033 if(
$res->isSuccess())
1045 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location_country",
$arFields);
1046 $strSql =
"UPDATE b_sale_location_country SET ".$strUpdate.
" WHERE ID = ".
$ID.
"";
1047 $DB->Query($strSql);
1050 while ($arLang = $db_lang->Fetch())
1054 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location_country_lang",
$arFields[$arLang[
"LID"]]);
1055 $strSql =
"UPDATE b_sale_location_country_lang SET ".$strUpdate.
" WHERE ID = ".$arCntLang[
"ID"].
"";
1059 $arInsert =
$DB->PrepareInsert(
"b_sale_location_country_lang",
$arFields[$arLang[
"LID"]]);
1061 "INSERT INTO b_sale_location_country_lang(COUNTRY_ID, ".$arInsert[0].
") ".
1062 "VALUES(".$ID.
", ".$arInsert[1].
")";
1064 $DB->Query($strSql);
1070 foreach (
GetModuleEvents(
"sale",
"OnCountryUpdate",
true) as $arEvent)
1081 foreach (
GetModuleEvents(
"sale",
"OnBeforeCountryDelete",
true) as $arEvent)
1085 if(self::isLocationProMigrated())
1111 $DB->Query(
"DELETE FROM b_sale_location_country_lang WHERE COUNTRY_ID = ".
$ID.
"",
true);
1112 $bDelete =
$DB->Query(
"DELETE FROM b_sale_location_country WHERE ID = ".
$ID.
"",
true);
1114 foreach (
GetModuleEvents(
"sale",
"OnCountryDelete",
true) as $arEvent)
1122 if(self::isLocationProMigrated())
1126 $res = Location\LocationTable::getList(
array(
1128 '=TYPE.CODE' =>
'COUNTRY',
1129 '=ID' => intval(
$ID),
1130 '=NAME.LANGUAGE_ID' => self::ORIGIN_NAME_LANGUAGE_ID
1134 'LNAME' =>
'NAME.NAME',
1135 'SHORT_NAME' =>
'NAME.SHORT_NAME'
1138 $res->addReplacedAliases(
array(
'LNAME' =>
'NAME'));
1140 $item =
$res->fetch();
1159 "FROM b_sale_location_country ".
1160 "WHERE ID = ".$ID.
" ";
1174 if(self::isLocationProMigrated())
1178 $res = Location\LocationTable::getList(
array(
1180 '=TYPE.CODE' =>
'COUNTRY',
1181 '=ID' => intval(
$ID),
1182 '=NAME.LANGUAGE_ID' => trim($strLang)
1187 'LID' =>
'NAME.LANGUAGE_ID',
1188 'LNAME' =>
'NAME.NAME',
1189 'SHORT_NAME' =>
'NAME.SHORT_NAME',
1193 $item =
$res->fetch();
1198 'ID' => $item[
'ID_'],
1199 'COUNTRY_ID' => $item[
'ID'],
1200 'LID' => $item[
'LID'],
1201 'NAME' => $item[
'LNAME'],
1202 'SHORT_NAME' => $item[
'SHORT_NAME'],
1219 $strLang = Trim($strLang);
1223 "FROM b_sale_location_country_lang ".
1224 "WHERE COUNTRY_ID = ".$ID.
" ".
1225 " AND LID = '".$DB->ForSql($strLang, 2).
"' ";
1255 foreach (
GetModuleEvents(
"sale",
"OnBeforeRegionUpdate",
true) as $arEvent)
1259 if(self::isLocationProMigrated())
1263 $locId = self::getLocationIdByRegionId(
$ID);
1270 self::refineFieldsForSaveCRC($locId,
$arFields),
1271 array(
'REBALANCE' =>
false)
1274 if(
$res->isSuccess())
1286 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location_region",
$arFields);
1287 $strSql =
"UPDATE b_sale_location_region SET ".$strUpdate.
" WHERE ID = ".
$ID.
"";
1288 $DB->Query($strSql);
1291 while ($arLang = $db_lang->Fetch())
1295 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location_region_lang",
$arFields[$arLang[
"LID"]]);
1297 $strSql =
"UPDATE b_sale_location_region_lang SET ".$strUpdate.
" WHERE ID = ".$arCntLang[
"ID"].
"";
1301 $arInsert =
$DB->PrepareInsert(
"b_sale_location_region_lang",
$arFields[$arLang[
"LID"]]);
1303 "INSERT INTO b_sale_location_region_lang(REGION_ID, ".$arInsert[0].
") ".
1304 "VALUES(".$ID.
", ".$arInsert[1].
")";
1306 $DB->Query($strSql);
1323 foreach (
GetModuleEvents(
"sale",
"OnBeforeRegionDelete",
true) as $arEvent)
1327 if(self::isLocationProMigrated())
1353 $DB->Query(
"DELETE FROM b_sale_location_region_lang WHERE REGION_ID = ".
$ID.
"",
true);
1354 $bDelete =
$DB->Query(
"DELETE FROM b_sale_location_region WHERE ID = ".
$ID.
"",
true);
1364 if(self::isLocationProMigrated())
1368 $res = Location\LocationTable::getList(
array(
1370 '=TYPE.CODE' =>
'REGION',
1371 '=ID' => intval(
$ID),
1372 'NAME.LANGUAGE_ID' => self::ORIGIN_NAME_LANGUAGE_ID
1376 'LNAME' =>
'NAME.NAME',
1377 'SHORT_NAME' =>
'NAME.SHORT_NAME',
1380 $res->addReplacedAliases(
array(
'LNAME' =>
'NAME'));
1382 $item =
$res->fetch();
1401 "FROM b_sale_location_region ".
1402 "WHERE ID = ".$ID.
" ";
1415 if(self::isLocationProMigrated())
1419 $res = Location\LocationTable::getList(
array(
1421 '=TYPE.CODE' =>
'REGION',
1422 '=ID' => intval(
$ID),
1423 'NAME.LANGUAGE_ID' => trim($strLang)
1428 'LID' =>
'NAME.LANGUAGE_ID',
1429 'LNAME' =>
'NAME.NAME',
1430 'SHORT_NAME' =>
'NAME.SHORT_NAME',
1433 $res->addReplacedAliases(
array(
'LNAME' =>
'NAME'));
1435 $item =
$res->fetch();
1440 'ID' => $item[
'ID_'],
1441 'REGION_ID' => $item[
'ID'],
1442 'LID' => $item[
'LID'],
1443 'NAME' => $item[
'LNAME'],
1444 'SHORT_NAME' => $item[
'SHORT_NAME'],
1460 $strLang = Trim($strLang);
1464 "FROM b_sale_location_region_lang ".
1465 "WHERE REGION_ID = ".$ID.
" ".
1466 " AND LID = '".$DB->ForSql($strLang, 2).
"' ";
1505 foreach (
GetModuleEvents(
"sale",
"OnBeforeCityUpdate",
true) as $arEvent)
1509 if(self::isLocationProMigrated())
1513 $locId = self::getLocationIdByCityId(
$ID);
1520 self::refineFieldsForSaveCRC($locId,
$arFields),
1521 array(
'REBALANCE' =>
false)
1524 if(
$res->isSuccess())
1536 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location_city",
$arFields);
1537 $strSql =
"UPDATE b_sale_location_city SET ".$strUpdate.
" WHERE ID = ".
$ID.
"";
1538 $DB->Query($strSql);
1541 while ($arLang = $db_lang->Fetch())
1545 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location_city_lang",
$arFields[$arLang[
"LID"]]);
1546 $strSql =
"UPDATE b_sale_location_city_lang SET ".$strUpdate.
" WHERE ID = ".$arCntLang[
"ID"].
"";
1550 $arInsert =
$DB->PrepareInsert(
"b_sale_location_city_lang",
$arFields[$arLang[
"LID"]]);
1552 "INSERT INTO b_sale_location_city_lang(CITY_ID, ".$arInsert[0].
") ".
1553 "VALUES(".$ID.
", ".$arInsert[1].
")";
1555 $DB->Query($strSql);
1572 foreach (
GetModuleEvents(
"sale",
"OnBeforeCityDelete",
true) as $arEvent)
1576 if(self::isLocationProMigrated())
1603 $DB->Query(
"DELETE FROM b_sale_location_city_lang WHERE CITY_ID = ".
$ID.
"",
true);
1604 $bDelete =
$DB->Query(
"DELETE FROM b_sale_location_city WHERE ID = ".
$ID.
"",
true);
1614 if(self::isLocationProMigrated())
1623 $res = \Bitrix\Sale\Location\TypeTable::getList(
array(
'filter' =>
array(
'=CODE' =>
'REGION'),
'select' =>
array(
'ID')))->fetch();
1627 $regionId =
$res[
'ID'];
1635 'data_type' =>
'\Bitrix\Sale\Location\Location',
1636 'reference' =>
array(
1637 '<=ref.LEFT_MARGIN' =>
'this.LEFT_MARGIN',
1638 '>=ref.RIGHT_MARGIN' =>
'this.RIGHT_MARGIN',
1639 '=ref.TYPE_ID' =>
array(
'?', $regionId)
1641 'join_type' =>
"left"
1645 $params[
'select'][
'PREGION_ID'] =
'P.ID';
1649 '=TYPE.CODE' =>
'CITY',
1650 '=ID' => intval(
$ID),
1651 '=NAME.LANGUAGE_ID' =>
'en',
1656 'LNAME' =>
'NAME.NAME',
1657 'SHORT_NAME' =>
'NAME.SHORT_NAME',
1660 $res = \Bitrix\Sale\Location\LocationTable::getList(
$params);
1661 $res->addReplacedAliases(
array(
'LNAME' =>
'NAME',
'PREGION_ID' =>
'REGION_ID'));
1663 $item =
$res->fetch();
1684 "FROM b_sale_location_city ".
1685 "WHERE ID = ".$ID.
" ";
1698 if(self::isLocationProMigrated())
1702 $res = Location\LocationTable::getList(
array(
1704 '=TYPE.CODE' =>
'CITY',
1705 '=ID' => intval(
$ID),
1706 'NAME.LANGUAGE_ID' => trim($strLang)
1711 'LID' =>
'NAME.LANGUAGE_ID',
1712 'LNAME' =>
'NAME.NAME',
1713 'SHORT_NAME' =>
'NAME.SHORT_NAME',
1716 $res->addReplacedAliases(
array(
'LNAME' =>
'NAME'));
1718 $item =
$res->fetch();
1723 'ID' => $item[
'ID_'],
1724 'CITY_ID' => $item[
'ID'],
1725 'LID' => $item[
'LID'],
1726 'NAME' => $item[
'LNAME'],
1727 'SHORT_NAME' => $item[
'SHORT_NAME'],
1743 $strLang = Trim($strLang);
1747 "FROM b_sale_location_city_lang ".
1748 "WHERE CITY_ID = ".$ID.
" ".
1749 " AND LID = '".$DB->ForSql($strLang, 2).
"' ";
1762 private static function processOrderForGetList($arOrder, $fieldMap =
array(), $fieldProxy =
array())
1764 if(is_array($arOrder))
1766 $arOrderParsed =
array();
1767 $fieldProxy = array_flip($fieldProxy);
1770 $arOrder = array_change_key_case($arOrder, CASE_UPPER);
1778 if(isset($fieldProxy[$fld]))
1779 $fld = $fieldProxy[$fld];
1781 if(!isset($fieldMap[$fld]))
1784 $fld = $fieldMap[$fld];
1789 return $arOrderParsed;
1799 $filterFieldsClean =
array();
1800 $arFilterParsed =
array();
1801 $pseudoFields =
array();
1802 $fieldProxy = array_flip($fieldProxy);
1805 $dbHelper = $dbConnection->getSqlHelper();
1812 $fld = preg_replace(self::LEADING_TILDA_SEARCH_R,
'', $fld);
1815 preg_match(self::MODIFIER_SEARCH_R, $fld, $found);
1817 $modifier = $found[1] <>
''? $found[1] :
'';
1818 $fldClean = preg_replace(self::MODIFIER_SEARCH_R,
'', $fld);
1820 if(isset($fieldProxy[$fldClean]))
1821 $fldClean = $fieldProxy[$fldClean];
1823 if(!isset($fieldMap[$fldClean]))
1826 $fldClean = $fieldMap[$fldClean];
1828 if($modifier ==
'+')
1834 if(is_array($value))
1836 foreach($value as
$i => $v)
1838 $value[
$i] =
"'".$dbHelper->forSql($v).
"'";
1840 $value =
'in ('.implode(
', ', $value).
')';
1843 $value =
'= '.$dbHelper->forSql($value);
1845 $query->registerRuntimeField(
'PLUS_'.$fldClean,
array(
1846 'data_type' =>
'integer',
1847 'expression' =>
array(
1848 "case when ((%s ".$value.
") or (%s is null) or (%s = 0)) then 1 else 0 end",
1854 $arFilterParsed[
'=PLUS_'.$fldClean] = 1;
1860 $arFilterParsed[$modifier.$fldClean] = $value;
1861 $filterFieldsClean[] = $fldClean;
1864 return array($arFilterParsed, $filterFieldsClean, $pseudoFields);
1873 if(is_array($arSelectFields) && !empty($arSelectFields) && !in_array(
'*', $arSelectFields,
true))
1875 $arSelectFields = array_map(
"strtoupper", $arSelectFields);
1876 foreach($arSelectFields as $fld)
1878 if(isset($fieldMap[$fld]))
1888 if($fldFrom == $fldTo)
1897 private static function proxyFieldsInResult(
$res, $fieldProxy =
array())
1899 if(!is_array($fieldProxy) || empty($fieldProxy))
1903 while($item =
$res->fetch())
1906 foreach($item as
$k => $v)
1908 if(isset($fieldProxy[
$k]))
1909 $pItem[$fieldProxy[
$k]] = $v;
1917 return new DB\ArrayResult(
$result);
1920 private static function stripModifiers(
$filter)
1927 $k = preg_replace(self::MODIFIER_SEARCH_R,
'',
$k);
1941 if(self::isLocationProMigrated())
1947 if(intval($types[
'COUNTRY']))
1948 $arFilter[
'TYPE_ID'][] = intval($types[
'COUNTRY']);
1950 if(intval($types[
'REGION']))
1951 $arFilter[
'TYPE_ID'][] = intval($types[
'REGION']);
1953 if(intval($types[
'CITY']))
1954 $arFilter[
'TYPE_ID'][] = intval($types[
'CITY']);
1964 $additionalFilterLCL =
'';
1965 $additionalFilterLRL =
'';
1966 $additionalFilterLGL =
'';
1971 if(self::isLocationProMigrated())
1973 $additionalFilterLCL =
" AND COL.LANGUAGE_ID = '".$siteId.
"'";
1974 $additionalFilterLRL =
" AND REL.LANGUAGE_ID = '".$siteId.
"'";
1975 $additionalFilterLGL =
" AND CIL.LANGUAGE_ID = '".$siteId.
"'";
1979 $additionalFilterLCL =
" AND LCL.LID = '".$siteId.
"'";
1980 $additionalFilterLRL =
" AND LRL.LID = '".$siteId.
"'";
1981 $additionalFilterLGL =
" AND LGL.LID = '".$siteId.
"'";
1984 if(self::isLocationProMigrated())
1991 "LOC_DEFAULT" =>
array(
"FIELD" =>
"CASE WHEN DEF.LOCATION_CODE IS NULL THEN 'N' ELSE 'Y' END",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN ".$tableDefault.
" DEF ON (DEF.LOCATION_CODE = L.CODE)"),
2003 "COUNTRY_NAME_ORIG" =>
array(
"FIELD" =>
"COO.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COO ON (L.COUNTRY_ID = COO.LOCATION_ID and COO.LANGUAGE_ID = 'en')"),
2004 "COUNTRY_SHORT_NAME" =>
array(
"FIELD" =>
"COO.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COO ON (L.COUNTRY_ID = COO.LOCATION_ID and COO.LANGUAGE_ID = 'en')"),
2007 "COUNTRY_NAME" =>
array(
"FIELD" =>
"COL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COL ON (L.COUNTRY_ID = COL.LOCATION_ID".$additionalFilterLCL.
")"),
2008 "COUNTRY_LID" =>
array(
"FIELD" =>
"COL.LANGUAGE_ID",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COL ON (L.COUNTRY_ID = COL.LOCATION_ID".$additionalFilterLCL.
")"),
2009 "COUNTRY_NAME_LANG" =>
array(
"FIELD" =>
"COL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COL ON (L.COUNTRY_ID = COL.LOCATION_ID".$additionalFilterLCL.
")"),
2010 "COUNTRY_SHORT_NAME_LANG" =>
array(
"FIELD" =>
"COL.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COL ON (L.COUNTRY_ID = COL.LOCATION_ID".$additionalFilterLCL.
")"),
2014 "CITY_NAME_ORIG" =>
array(
"FIELD" =>
"CIO.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIO ON (L.CITY_ID = CIO.LOCATION_ID and CIO.LANGUAGE_ID = 'en')"),
2015 "CITY_SHORT_NAME" =>
array(
"FIELD" =>
"CIO.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIO ON (L.CITY_ID = CIO.LOCATION_ID and CIO.LANGUAGE_ID = 'en')"),
2018 "CITY_NAME" =>
array(
"FIELD" =>
"CIL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIL ON (L.CITY_ID = CIL.LOCATION_ID".$additionalFilterLGL.
")"),
2019 "CITY_LID" =>
array(
"FIELD" =>
"CIL.LANGUAGE_ID",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIL ON (L.CITY_ID = CIL.LOCATION_ID".$additionalFilterLGL.
")"),
2020 "CITY_NAME_LANG" =>
array(
"FIELD" =>
"CIL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIL ON (L.CITY_ID = CIL.LOCATION_ID".$additionalFilterLGL.
")"),
2021 "CITY_SHORT_NAME_LANG" =>
array(
"FIELD" =>
"CIL.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIL ON (L.CITY_ID = CIL.LOCATION_ID".$additionalFilterLGL.
")"),
2025 "REGION_NAME_ORIG" =>
array(
"FIELD" =>
"REO.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REO ON (L.REGION_ID = REO.LOCATION_ID and REO.LANGUAGE_ID = 'en')"),
2026 "REGION_SHORT_NAME" =>
array(
"FIELD" =>
"REO.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REO ON (L.REGION_ID = REO.LOCATION_ID and REO.LANGUAGE_ID = 'en')"),
2029 "REGION_NAME" =>
array(
"FIELD" =>
"REL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REL ON (L.REGION_ID = REL.LOCATION_ID".$additionalFilterLRL.
")"),
2030 "REGION_LID" =>
array(
"FIELD" =>
"REL.LANGUAGE_ID",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REL ON (L.REGION_ID = REL.LOCATION_ID".$additionalFilterLRL.
")"),
2031 "REGION_NAME_LANG" =>
array(
"FIELD" =>
"REL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REL ON (L.REGION_ID = REL.LOCATION_ID".$additionalFilterLRL.
")"),
2032 "REGION_SHORT_NAME_LANG" =>
array(
"FIELD" =>
"REL.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REL ON (L.REGION_ID = REL.LOCATION_ID".$additionalFilterLRL.
")"),
2034 "COUNTRY" =>
array(
"FIELD" =>
"COL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name COL ON (L.COUNTRY_ID = COL.LOCATION_ID".$additionalFilterLCL.
")"),
2035 "CITY" =>
array(
"FIELD" =>
"CIL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name CIL ON (L.CITY_ID = CIL.LOCATION_ID".$additionalFilterLGL.
")"),
2036 "REGION" =>
array(
"FIELD" =>
"REL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_loc_name REL ON (L.REGION_ID = REL.LOCATION_ID".$additionalFilterLRL.
")"),
2038 "TYPE_ID" =>
array(
"FIELD" =>
"L.TYPE_ID",
"TYPE" =>
"int")
2047 "LOC_DEFAULT" =>
array(
"FIELD" =>
"L.LOC_DEFAULT",
"TYPE" =>
"string"),
2049 "COUNTRY_NAME_ORIG" =>
array(
"FIELD" =>
"LC.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country LC ON (L.COUNTRY_ID = LC.ID)"),
2050 "COUNTRY_SHORT_NAME" =>
array(
"FIELD" =>
"LC.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country LC ON (L.COUNTRY_ID = LC.ID)"),
2052 "CITY_NAME_ORIG" =>
array(
"FIELD" =>
"LG.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city LG ON (L.CITY_ID = LG.ID)"),
2053 "CITY_SHORT_NAME" =>
array(
"FIELD" =>
"LG.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city LG ON (L.CITY_ID = LG.ID)"),
2055 "REGION_NAME_ORIG" =>
array(
"FIELD" =>
"LR.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region LR ON (L.REGION_ID = LR.ID)"),
2056 "REGION_SHORT_NAME" =>
array(
"FIELD" =>
"LR.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region LR ON (L.REGION_ID = LR.ID)"),
2058 "COUNTRY_LID" =>
array(
"FIELD" =>
"LCL.LID",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country_lang LCL ON (L.COUNTRY_ID = LCL.COUNTRY_ID".$additionalFilterLCL.
")"),
2059 "COUNTRY_NAME" =>
array(
"FIELD" =>
"LCL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country_lang LCL ON (L.COUNTRY_ID = LCL.COUNTRY_ID".$additionalFilterLCL.
")"),
2060 "COUNTRY_NAME_LANG" =>
array(
"FIELD" =>
"LCL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country_lang LCL ON (L.COUNTRY_ID = LCL.COUNTRY_ID".$additionalFilterLCL.
")"),
2061 "COUNTRY_SHORT_NAME_LANG" =>
array(
"FIELD" =>
"LCL.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country_lang LCL ON (L.COUNTRY_ID = LCL.COUNTRY_ID".$additionalFilterLCL.
")"),
2063 "REGION_LID" =>
array(
"FIELD" =>
"LRL.LID",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region_lang LRL ON (L.REGION_ID = LRL.REGION_ID".$additionalFilterLRL.
")"),
2064 "REGION_NAME" =>
array(
"FIELD" =>
"LRL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region_lang LRL ON (L.REGION_ID = LRL.REGION_ID".$additionalFilterLRL.
")"),
2065 "REGION_NAME_LANG" =>
array(
"FIELD" =>
"LRL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region_lang LRL ON (L.REGION_ID = LRL.REGION_ID".$additionalFilterLRL.
")"),
2066 "REGION_SHORT_NAME_LANG" =>
array(
"FIELD" =>
"LRL.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region_lang LRL ON (L.REGION_ID = LRL.REGION_ID".$additionalFilterLRL.
")"),
2068 "CITY_LID" =>
array(
"FIELD" =>
"LGL.LID",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city_lang LGL ON (L.CITY_ID = LGL.CITY_ID".$additionalFilterLGL.
")"),
2069 "CITY_NAME" =>
array(
"FIELD" =>
"LGL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city_lang LGL ON (L.CITY_ID = LGL.CITY_ID".$additionalFilterLGL.
")"),
2070 "CITY_NAME_LANG" =>
array(
"FIELD" =>
"LGL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city_lang LGL ON (L.CITY_ID = LGL.CITY_ID".$additionalFilterLGL.
")"),
2071 "CITY_SHORT_NAME_LANG" =>
array(
"FIELD" =>
"LGL.SHORT_NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city_lang LGL ON (L.CITY_ID = LGL.CITY_ID".$additionalFilterLGL.
")"),
2073 "COUNTRY" =>
array(
"FIELD" =>
"LCL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_country_lang LCL ON (L.COUNTRY_ID = LCL.COUNTRY_ID".$additionalFilterLCL.
")"),
2074 "CITY" =>
array(
"FIELD" =>
"LGL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_city_lang LGL ON (L.CITY_ID = LGL.CITY_ID".$additionalFilterLGL.
")"),
2075 "REGION" =>
array(
"FIELD" =>
"LRL.NAME",
"TYPE" =>
"string",
"FROM" =>
"LEFT JOIN b_sale_location_region_lang LRL ON (L.REGION_ID = LRL.REGION_ID".$additionalFilterLRL.
")")
2080 return array_merge(
array(
2081 "ID" =>
array(
"FIELD" =>
"L.ID",
"TYPE" =>
"int"),
2082 "CODE" =>
array(
"FIELD" =>
"L.CODE",
"TYPE" =>
"string"),
2083 "COUNTRY_ID" =>
array(
"FIELD" =>
"L.COUNTRY_ID",
"TYPE" =>
"int"),
2084 "CITY_ID" =>
array(
"FIELD" =>
"L.CITY_ID",
"TYPE" =>
"int"),
2085 "REGION_ID" =>
array(
"FIELD" =>
"L.REGION_ID",
"TYPE" =>
"int"),
2086 "SORT" =>
array(
"FIELD" =>
"L.SORT",
"TYPE" =>
"int")
2109 $dbHelper = $dbConnection->getSqlHelper();
2112 $typeCode = mb_strtoupper($dbHelper->forSql($typeCode));
2113 $strLang = mb_substr($dbHelper->forSql($strLang), 0, 2);
2115 $mappedTypes =
array(
"'".intval($types[$typeCode]).
"'");
2117 if($typeCode ==
'CITY' && intval($types[
'VILLAGE']))
2119 $mappedTypes[] =
"'".intval($types[
'VILLAGE']).
"'";
2124 N.NAME as ".$typeCode.
"_NAME,
2125 N.SHORT_NAME as ".$typeCode.
"_SHORT_NAME,
2126 L.ID as ".$typeCode.
"_ID
2129 inner join b_sale_location L on
2130 N.LOCATION_ID = L.ID
2132 N.LANGUAGE_ID = '".$strLang.
"'
2134 L.LEFT_MARGIN <= '".intval($item[
'LEFT_MARGIN']).
"'
2136 L.RIGHT_MARGIN >= '".intval($item[
'RIGHT_MARGIN']).
"'
2138 L.TYPE_ID in (".implode(
', ', $mappedTypes).
")
2142 if(!is_array($item))
2147 $item[$typeCode.
'_NAME_ORIG'] = $item[$typeCode.
'_NAME'];
2148 $item[$typeCode.
'_NAME_LANG'] = $item[$typeCode.
'_NAME'];
2154 '0000073738' =>
'0000028025',
2155 '0000103664' =>
'0000028043',
2162 $primary = trim($primary);
2167 $noRegion = empty($loc);
2170 $noRegion = (int)($loc[
'REGION_ID'] ?? 0) <= 0;
2175 if(isset(self::$city2RegionMap[(
string) $primary]))
2179 elseif(!empty($loc[
'CODE']) && !empty(self::$city2RegionMap[(
string) $loc[
'CODE']]))
2185 $nameNang = (string)($loc[
'CITY_NAME_LANG'] ??
'');
2187 if ($nameNang !==
'')
2189 $name = mb_strtoupper(trim($loc[
'CITY_NAME_LANG']));
2190 $regionName =
false;
2192 foreach (self::$specialCities as $city)
2200 if ($regionName !==
false)
2204 [
'~REGION_NAME_LANG' => $regionName .
'%',
'LID' => $strLang],
2207 [
'REGION_ID',
'REGION_NAME',
'REGION_SHORT_NAME',
'REGION_NAME_ORIG',
'REGION_NAME_LANG']
2214 if($regLoc !==
false)
2216 if(intval($regLoc[
'REGION_ID']))
2218 $loc[
'REGION_ID'] = $regLoc[
'REGION_ID'];
2219 $loc[
'REGION_NAME'] = $regLoc[
'REGION_NAME'];
2220 $loc[
'REGION_SHORT_NAME'] = $regLoc[
'REGION_SHORT_NAME'];
2221 $loc[
'REGION_NAME_ORIG'] = $regLoc[
'REGION_NAME_ORIG'];
2222 $loc[
'REGION_NAME_LANG'] = $regLoc[
'REGION_NAME_LANG'];
2229 public static function GetByID($primary, $strLang = LANGUAGE_ID)
2237 $item = Location\LocationTable::getList(
array(
'filter' =>
array(
2238 array(
'=CODE' => $primary)
2240 array(
'ID',
'SORT',
'LEFT_MARGIN',
'RIGHT_MARGIN',
'CODE')
2243 if(!is_array($item))
2246 $item = Location\LocationTable::getList(
array(
'filter' =>
array(
2247 array(
'=ID' => $primary)
2249 array(
'ID',
'SORT',
'LEFT_MARGIN',
'RIGHT_MARGIN',
'CODE')
2258 if(!is_array($item) || !intval($item[
'ID']))
2267 unset($item[
'LEFT_MARGIN']);
2268 unset($item[
'RIGHT_MARGIN']);
2295 foreach (
GetModuleEvents(
"sale",
"OnBeforeLocationUpdate",
true) as $arEvent)
2299 $strUpdate =
$DB->PrepareUpdate(
"b_sale_location",
$arFields);
2300 $strSql =
"UPDATE b_sale_location SET ".$strUpdate.
" WHERE ID = ".
$ID.
"";
2301 $DB->Query($strSql);
2303 foreach (
GetModuleEvents(
"sale",
"OnLocationUpdate",
true) as $arEvent)
2329 private static function AddLocationPart($creat,
$type, $parent, $sort)
2331 $langs = self::getLanguages();
2334 $creatFlds =
array();
2335 if(is_numeric($creat))
2339 $res = Location\LocationTable::getList(
array(
'filter' =>
array(
'='.
$type.
'_ID' => $creat,
'TYPE_ID' => $types[
$type]),
'select' =>
array(
'ID'),
'limit' => 1))->fetch();
2342 $parent = intval(
$res[
'ID']);
2346 if(
$type ==
'COUNTRY')
2354 throw new Exception('No such '.
$type);
2359 $creatFlds['NAME'] =
array();
2362 if(
$type ==
'COUNTRY')
2363 $name = self::GetCountryLangByID(
$res[
'ID'], $lid);
2369 $creatFlds['NAME'][$lid] =
array(
2370 'NAME' =>
$name['NAME'],
2371 'SHORT_NAME' =>
$name['SHORT_NAME']
2379 $creatFlds[
'NAME'] =
array();
2381 foreach($creat as $lid =>
$name)
2383 $creatFlds[
'NAME'][$lid] =
array(
2384 'NAME' =>
$name[
'NAME'],
2385 'SHORT_NAME' =>
$name[
'SHORT_NAME']
2390 if(!empty($creatFlds))
2392 $creatFlds[
'PARENT_ID'] = $parent;
2393 $creatFlds[
'TYPE_ID'] = $types[
$type];
2395 $creatFlds[
'CODE'] = rand(999,99999999);
2398 $creatFlds[
'SORT'] = $sort;
2400 $res = Location\LocationTable::add($creatFlds);
2401 if(!
$res->isSuccess())
2402 throw new Exception(
'Cannot add location');
2404 $parent =
$res->getId();
2405 Location\LocationTable::update($parent,
array(
'CODE' => $parent));
2418 if(self::isLocationProMigrated())
2424 $city = self::getTypeValueToStore(
'CITY',
$arFields);
2447 $parent = self::AddLocationPart(
$country,
'COUNTRY', $parent, $sort);
2452 $parent = self::AddLocationPart(
$region,
'REGION', $parent, $sort);
2457 $parent = self::AddLocationPart($city,
'CITY', $parent, $sort);
2473 if (intval(
$arFields[
"COUNTRY_ID"])<=0)
return false;
2485 if (intval(
$arFields[
"REGION_ID"])<=0)
return false;
2504 if (intval(
$arFields[
"CITY_ID"])<=0)
return false;
2526 if(self::isLocationProMigrated())
2551 if (intval(
$arFields[
"COUNTRY_ID"])<=0)
return false;
2565 if (intval($arLocRes[
"CITY_ID"])>0)
2572 if (intval(
$arFields[
"CITY_ID"])<=0)
return false;
2591 if (
count($arRegion) > 1)
2592 $arFields[
"REGION_ID"] = $arRegion[
"ID"];
2600 UnSet($arFieldsTmp[
"CITY_ID"]);
2629 foreach (
GetModuleEvents(
"sale",
"OnBeforeLocationDelete",
true) as $arEvent)
2633 if (intval($arLocRes[
"CITY_ID"]) > 0)
2636 $bDelCountry = True;
2638 array(
"SORT" =>
"ASC"),
2639 array(
"COUNTRY_ID" => $arLocRes[
"COUNTRY_ID"],
"!ID"=>
$ID),
2643 $bDelCountry =
false;
2645 if ($bDelCountry && intval($arLocRes[
"COUNTRY_ID"]) > 0)
2650 array(
"SORT" =>
"ASC"),
2651 array(
"REGION_ID" => $arLocRes[
"REGION_ID"],
"!ID"=>
$ID),
2655 $bDelRegion =
false;
2657 if ($bDelRegion && intval($arLocRes[
"REGION_ID"]) > 0)
2660 $DB->Query(
"DELETE FROM b_sale_location2location_group WHERE LOCATION_ID = ".
$ID.
"",
true);
2661 $DB->Query(
"DELETE FROM b_sale_delivery2location WHERE LOCATION_ID = ".
$ID.
" AND LOCATION_TYPE = 'L'",
true);
2662 $DB->Query(
"DELETE FROM b_sale_location_zip WHERE LOCATION_ID = ".
$ID.
"",
true);
2664 if(self::isLocationProMigrated())
2669 if(!
$res->isSuccess())
2681 $bDelete =
$DB->Query(
"DELETE FROM b_sale_location WHERE ID = ".
$ID.
"",
true);
2684 foreach (
GetModuleEvents(
"sale",
"OnLocationDelete",
true) as $arEvent)
2694 if(self::isLocationProMigrated())
2701 $DB->Query(
"DELETE FROM b_sale_location_city_lang WHERE LID = '".
$DB->ForSql($strLang).
"'",
true);
2702 $DB->Query(
"DELETE FROM b_sale_location_country_lang WHERE LID = '".
$DB->ForSql($strLang).
"'",
true);
2711 foreach (
GetModuleEvents(
"sale",
"OnBeforeLocationDeleteAll",
true) as $arEvent)
2715 if(self::isLocationProMigrated())
2738 $DB->Query(
"DELETE FROM b_sale_location2location_group");
2739 $DB->Query(
"DELETE FROM b_sale_location_group_lang");
2740 $DB->Query(
"DELETE FROM b_sale_location_group");
2742 $DB->Query(
"DELETE FROM b_sale_delivery2location");
2743 $DB->Query(
"DELETE FROM b_sale_location");
2745 $DB->Query(
"DELETE FROM b_sale_location_city_lang");
2746 $DB->Query(
"DELETE FROM b_sale_location_city");
2748 $DB->Query(
"DELETE FROM b_sale_location_country_lang");
2749 $DB->Query(
"DELETE FROM b_sale_location_country");
2751 $DB->Query(
"DELETE FROM b_sale_location_region_lang");
2752 $DB->Query(
"DELETE FROM b_sale_location_region");
2754 $DB->Query(
"DELETE FROM b_sale_location_zip");
2756 foreach (
GetModuleEvents(
"sale",
"OnLocationDeleteAll",
true) as $arEvent)
2763 if(self::isLocationProMigrated())
2770 return Location\ExternalTable::getList(
array(
2772 '=SERVICE.CODE' => self::ZIP_EXT_SERVICE_CODE,
2790 return $DB->Query(
"SELECT ZIP FROM b_sale_location_zip WHERE LOCATION_ID='".
$DB->ForSql(
$location).
"'");
2796 if(self::isLocationProMigrated())
2803 $res = Location\ExternalTable::getList(
array(
2805 '=SERVICE.CODE' => self::ZIP_EXT_SERVICE_CODE,
2814 if($item =
$res->fetch())
2828 $dbRes =
$DB->Query(
'SELECT LOCATION_ID FROM b_sale_location_zip WHERE ZIP=\''.
$DB->ForSql($zip).
'\'');
2840 if(self::isLocationProMigrated())
2846 $query =
"DELETE FROM b_sale_location_zip WHERE LOCATION_ID='".$DB->ForSql(
$location).
"'";
2857 if(self::isLocationProMigrated())
2863 $DB->Query(
"DELETE FROM b_sale_location_zip");
2869 if(self::isLocationProMigrated())
2875 $res = Location\ExternalTable::getList(
array(
2877 '=SERVICE.CODE' => self::ZIP_EXT_SERVICE_CODE,
2901 $zipId = self::getZipId();
2904 Location\ExternalTable::add(
array(
2907 'SERVICE_ID' => $zipId
2923 "ZIP" => intval($ZIP),
2929 'b_sale_location_zip',
2931 "WHERE LOCATION_ID='".$arInsert[
"LOCATION_ID"].
"' AND ZIP='".$arInsert[
"ZIP"].
"'"
2942 $DB->Insert(
'b_sale_location_zip', $arInsert);
2953 if (is_array($arZipList))
2962 foreach ($arZipList as $ZIP)
2974 if(self::isLocationProMigrated())
2983 'RID' =>
'REGION_ID',
2985 'RNAME' =>
'NAME.NAME',
2986 'RSHORT_NAME' =>
'NAME.SHORT_NAME'
2993 'RNAME' => $arRegNames,
2994 'RSHORT_NAME' => $arRegNames,
2996 '=TYPE_ID' => $types[
'REGION'],
2997 '!=REGION_ID' =>
'0'
3000 if($countryId = intval($countryId))
3004 $orderFields =
array(
3006 'RSHORT_NAME' =>
'asc'
3010 $groupFields =
array(
3014 $nameJoinCondition =
array(
3015 '=this.ID' =>
'ref.LOCATION_ID',
3019 $nameJoinCondition[
'=ref.LANGUAGE_ID'] =
array(
'?', $strLang);
3022 $query->registerRuntimeField(
3025 'data_type' => self::NAME_ENTITY_NAME,
3026 'reference' => $nameJoinCondition,
3027 'join_type' =>
'left'
3033 $query->setOrder($orderFields);
3034 $query->setGroup($groupFields);
3039 while($item =
$res->fetch())
3041 $result[$item[
'RNAME'] <>
''? $item[
'RNAME'] : $item[
'RSHORT_NAME']] = $item[
'RID'];
3056 $arQueryFields =
array(
'RL.NAME',
'RL.SHORT_NAME');
3058 if(is_array($arRegNames))
3060 foreach ($arRegNames as $regName)
3062 $regName =
$DB->ForSql($regName);
3063 foreach ($arQueryFields as $field)
3064 $arWhere[] = $field.
" LIKE '".$regName.
"'";
3067 if (
count($arWhere) > 0)
3069 $strWhere = implode(
' OR ', $arWhere);
3071 $query =
" SELECT RL.REGION_ID, RL.NAME, RL.SHORT_NAME
3072 FROM b_sale_location_region_lang RL ";
3076 $strWhere =
'L.COUNTRY_ID=\''.intval($countryId).
'\' AND (
'.$strWhere.')
';
3077 $query .= "LEFT JOIN b_sale_location L ON L.REGION_ID=RL.REGION_ID ";
3080 $query .= "WHERE ".$strWhere;
3081 $query .= " GROUP BY RL.REGION_ID";
3082 $query .= " ORDER BY RL.NAME, RL.SHORT_NAME";
3084 $dbList = $DB->Query($query);
3086 $arRegionsLang = array();
3088 while($arRegion = $dbList->Fetch())
3090 if($arRegion["NAME"] <> '')
3091 $idx = $arRegion["NAME"];
3093 $idx = $arRegion["SHORT_NAME"];
3095 $arResult[$idx] = $arRegion["REGION_ID"];
3105 public static function GetRegionsNamesByIds($arIds, $lang = LANGUAGE_ID)
3107 if(self::isLocationProMigrated())
3111 if(!is_array($arIds) || empty($arIds))
3112 throw new Exception();
3114 $arIds = array_unique($arIds);
3115 $parsedList = array();
3116 foreach($arIds as $id)
3119 $parsedList[] = intval($id);
3123 $lang = LANGUAGE_ID;
3125 $arResult = array();
3126 foreach ($parsedList as $id)
3128 $res = self::GetLocationTypeList(
3130 array('NAME
' => 'asc
', 'SHORT_NAME
' => 'asc
'),
3135 while($arRegion = $res->fetch())
3137 $arResult[$arRegion["ID"]] = $arRegion["NAME"] ?: $arRegion["SHORT_NAME"];
3151 $arResult = array();
3155 $lang = LANGUAGE_ID;
3157 if(!empty($arIds) && is_array($arIds))
3159 foreach ($arIds as $id)
3162 $arWhere[] = intval($id);
3165 if (!empty($arWhere))
3167 $query = "select RL.REGION_ID, RL.NAME, RL.SHORT_NAME from b_sale_location_region_lang RL";
3168 $query .= " where REGION_ID IN(".implode(',
', $arWhere).") and RL.LID='".$DB->ForSql($lang, 2)."'";
3169 $query .= " order by RL.NAME, RL.SHORT_NAME";
3171 $dbList = $DB->Query($query);
3173 while($arRegion = $dbList->Fetch())
3174 $arResult[$arRegion["REGION_ID"]] = $arRegion["NAME"] <> '' ? $arRegion["NAME"] : $arRegion["SHORT_NAME"];
3182 // location import is overwritten, and it is enabled when self::isLocationProMigrated() == true, so no proxy provided for the obsolete methods below
3184 public static function _GetZIPImportStats()
3188 $query = "SELECT COUNT(*) AS CNT, COUNT(DISTINCT LOCATION_ID) AS CITY_CNT FROM b_sale_location_zip";
3189 $rsStats = $DB->Query($query);
3190 $arStat = $rsStats->Fetch();
3195 public static function _GetCityImport($arCityName, $country_id = false)
3199 $arQueryFields = array('LCL.NAME
', 'LCL.SHORT_NAME
');
3202 foreach ($arCityName as $city_name)
3204 $city_name = $DB->ForSql($city_name);
3205 foreach ($arQueryFields as $field)
3208 $arWhere[] = $field."='".$city_name."'";
3212 if (count($arWhere) <= 0) return false;
3213 $strWhere = implode(' OR
', $arWhere);
3217 $strWhere = 'L.COUNTRY_ID=\
''.intval($country_id).
'\' AND (
'.$strWhere.')
';
3221SELECT L.ID, L.CITY_ID
3222FROM b_sale_location L
3223LEFT JOIN b_sale_location_city_lang LCL ON L.CITY_ID=LCL.CITY_ID
3226 $dbList = $DB->Query($query);
3228 if ($arCity = $dbList->Fetch())
3234 protected static function AddLocationUnattached($typeCode, $names = array())
3240 $types = self::getTypes();
3243 if(!intval($types[$typeCode])) // no such type
3248 foreach (GetModuleEvents('sale
', 'OnBefore
'.ucfirst(mb_strtolower($typeCode)).'Add', true) as $arEvent)
3250 if (ExecuteModuleEventEx($arEvent, array($names))===false)
3256 if(!is_array($names))
3261 $name = $names['NAME
'];
3262 $shortName = $names['SHORT_NAME
'];
3264 unset($names['NAME
']);
3265 unset($names['SHORT_NAME
']);
3268 foreach($names as $lang => $n)
3270 $fields['NAME
'][$n['LID
']] = array(
3271 'NAME
' => $n['NAME
'],
3272 'SHORT_NAME
' => $n['SHORT_NAME
']
3276 if(!isset($fields['NAME
']['en
']))
3278 $fields['NAME
']['en
'] = array(
3280 'SHORT_NAME
' => $shortName
3284 $fields['CODE
'] = 'randstr
'.rand(999, 99999).rand(999, 99999).rand(999, 99999);
3285 $fields['TYPE_ID
'] = $types[$typeCode];
3286 $fields['PARENT_ID
'] = 0;
3289 $res = \Bitrix\Sale\Location\LocationTable::add($fields);
3290 if($res->isSuccess())
3292 $id = $res->getId();
3293 $uRes = \Bitrix\Sale\Location\LocationTable::update($id, array('CODE
' => $id));
3295 foreach (GetModuleEvents('sale
', 'On
'.ucfirst(mb_strtolower($typeCode)).'Add', true) as $arEvent)
3297 ExecuteModuleEventEx($arEvent, array($id, $names));
3304 protected static function RebindLocationTriplet($fields = array())
3306 $country = intval($fields['COUNTRY_ID
']);
3307 $region = intval($fields['REGION_ID
']);
3308 $city = intval($fields['CITY_ID
']);
3310 foreach (GetModuleEvents('sale
', 'OnBeforeLocationAdd
', true) as $arEvent)
3312 if (ExecuteModuleEventEx($arEvent, array($fields))===false)
3318 if($region && $country) // set country as PARENT_ID for region
3320 $uRes = \Bitrix\Sale\Location\LocationTable::update($region, array('PARENT_ID
' => $country));
3324 if($region) // set region as PARENT_ID for city
3326 $uRes = \Bitrix\Sale\Location\LocationTable::update($city, array('PARENT_ID
' => $region));
3328 elseif($country) // set country as PARENT_ID for city
3330 $uRes = \Bitrix\Sale\Location\LocationTable::update($city, array('PARENT_ID
' => $country));
3334 if(intval($fields['SORT
']))
3336 $loc2Update = $city ? $city : ($region ? $region : ($country ? $country : false));
3339 $uRes = \Bitrix\Sale\Location\LocationTable::update($loc2Update, array('SORT
' => $fields['SORT
']));
3343 foreach (GetModuleEvents('sale
', 'OnLocationAdd
', true) as $arEvent)
3345 ExecuteModuleEventEx($arEvent, array($loc2Update, $fields));
static getConnection($name="")
static get($moduleId, $name, $default="", $siteId=false)
static set($moduleId, $name, $value="", $siteId="")
static getList(array $parameters=array())
static updateExtended($primary, array $data, array $additional=array())
static getByCode($code='', $parameters=array())
static checkCityId($cityId, $siteId)
static checkRegionId($regionId, $siteId)
static checkLocationId($locationId, $siteId)
static checkCountryId($countryId, $siteId)
static GetList($by="sort", $order="asc", $arFilter=[])
static locationProDebugDisable()
static parseFilter($filter=array())
static GetByID($primary, $strLang=LANGUAGE_ID)
static ClearAllLocationZIP()
static GetCountryLangByID($ID, $strLang=LANGUAGE_ID)
static SetLocationZIP($location, $arZipList)
static proxySaleAjaxLocationsComponent($parameters=array(), $additionalParams=array(), $template='', $hideIcons=true, $wrapNewComponentWith=false)
static locationProControlForm()
static RegionCheckFields($ACTION, &$arFields)
const ZIP_EXT_SERVICE_CODE
static locationProDebugEnable()
static ClearLocationZIP($location)
const LEADING_TILDA_SEARCH_R
static CityCheckFields($ACTION, &$arFields)
static OnLangDelete($strLang)
const DEFAULT_SITE_ENTITY_NAME
static getFilterForGetList($arFilter)
static processFilterForGetList($arFilter, $fieldMap=array(), $fieldProxy=array(), $query=null)
static isLocationProMigrated()
static UpdateCity($ID, $arFields)
static tryTranslateIDToCode($id)
static checkIsRealInt($val)
static getLocationCityTail()
static GetLocationString($locationId, $siteId=SITE_ID, $langId=LANGUAGE_ID)
static checkLocationCodeExists($code)
static isLocationProInDebug()
static getNameOfParentOfType($item, $typeCode, $strLang=LANGUAGE_ID)
static LocationCheckFields($ACTION, &$arFields)
static locationProDisable()
static DeleteCountry($ID)
static getLocationIDbyCODE($code)
static checkLocationIdExists($id)
static isLocationProEnabled()
static UpdateRegion($ID, $arFields)
static CheckFields($ACTION, &$arFields)
static getTypeJOINCondition($ctx='this')
static checkLocationIsAboveCity($locationId)
static CountryCheckFields($ACTION, &$arFields)
static processSelectForGetList($arSelectFields, $fieldMap)
static locationProSetMigrated()
static locationProSetRolledBack()
static GetRegionsIdsByNames($arRegNames, $countryId=false)
static GetCountryByID($ID)
static UpdateLocation($ID, $arFields)
static getTypeFilterCondition()
static getLocationCODEbyID($id)
static UpdateCountry($ID, $arFields)
static AddLocationZIP($location, $ZIP, $bSync=false)
const ORIGIN_NAME_LANGUAGE_ID
static getFieldMapForGetList($arFilter)
static GetLocationTypeList($typeCode='', $arOrder=Array("NAME_LANG"=>"ASC"), $arFilter=Array(), $strLang=LANGUAGE_ID)
static locationProEnable()
static GetByIDForLegacyDelivery($primary, $strLang=LANGUAGE_ID)
static Update($ID, $arFields)
static GetCityLangByID($ID, $strLang=LANGUAGE_ID)
static GetRegionLangByID($ID, $strLang=LANGUAGE_ID)
static GetRegionByID($ID)
static getDenormalizedLocationList($entityName, $arFilter=array())
static GetLocationZIP($location)
const LOC2_DEBUG_MODE_OPT
static locationProCheckEnabled()
static GetList($arOrder=array("SORT"=>"ASC", "COUNTRY_NAME_LANG"=>"ASC", "CITY_NAME_LANG"=>"ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
static GetByID($primary, $strLang=LANGUAGE_ID)
static AddRegion($arFields)
static AddCountry($arFields)
static AddCity($arFields)
static GetCountryList($arOrder=Array("NAME_LANG"=>"ASC"), $arFilter=Array(), $strLang=LANGUAGE_ID)
static GetRegionList($arOrder=Array("NAME_LANG"=>"ASC"), $arFilter=Array(), $strLang=LANGUAGE_ID)
static AddLocation($arFields)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Form FILTER_ACTION disabled
foreach( $arCellTemplates as $key=> $value) foreach( $arCellTemplates as $key=> $value)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
ExecuteModuleEventEx($arEvent, $arParams=[])
DelDuplicateSort(&$arSort)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
$GLOBALS['____1690880296']
if(!function_exists(__NAMESPACE__.'\\___972068685'))
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
$arLocation['REGION_NAME']