Exemplo n.º 1
0
 public function getLocation()
 {
     if (!$this->getLocationId()) {
         throw new \Exception('Не указано место доставки ' . __METHOD__);
     }
     $retval = false;
     $res = \CSaleLocation::GetList(array(), array('LID' => LANGUAGE_ID, 'ID' => $this->getLocationId()));
     while ($city = $res->GetNext()) {
         if (!\Bitrix\Sale\SalesZone::checkCityId($city['CITY_ID'], SITE_ID)) {
             continue;
         }
         if (empty($city['CITY_NAME'])) {
             continue;
         }
         $retval = $city;
     }
     return $retval;
 }
Exemplo n.º 2
0
 public static function GetLocationString($locationId, $siteId = SITE_ID, $langId = LANGUAGE_ID)
 {
     $locationString = '';
     if (!\Bitrix\Sale\SalesZone::checkLocationId($locationId, $siteId)) {
         $locationId = 0;
     }
     $countryId = $regionId = $cityId = 0;
     if ($locationId > 0) {
         if ($arLocation = CSaleLocation::GetByID($locationId)) {
             $countryId = $arLocation["COUNTRY_ID"];
             $regionId = $arLocation["REGION_ID"];
             $cityId = $arLocation["CITY_ID"];
         }
     }
     //check in location city
     $bEmptyCity = "N";
     $arCityFilter = array("!CITY_ID" => "NULL", ">CITY_ID" => "0");
     if ($countryId > 0) {
         $arCityFilter["COUNTRY_ID"] = $countryId;
     }
     $rsLocCount = CSaleLocation::GetList(array(), $arCityFilter, false, false, array("ID"));
     if (!$rsLocCount->Fetch()) {
         $bEmptyCity = "Y";
     }
     //check in location region
     $bEmptyRegion = "N";
     $arRegionFilter = array("!REGION_ID" => "NULL", ">REGION_ID" => "0");
     if ($countryId > 0 && $regionId > 0) {
         $arRegionFilter["COUNTRY_ID"] = $countryId;
     }
     if ($regionId > 0) {
         $arRegionFilter["REGION_ID"] = $regionId;
     }
     $rsLocCount = CSaleLocation::GetList(array(), $arRegionFilter, false, false, array("ID"));
     if (!$rsLocCount->Fetch()) {
         $bEmptyRegion = "Y";
     }
     //check if exist another city
     if ($bEmptyCity == "Y" && $bEmptyRegion == "Y") {
         $arCityFilter = array("!CITY_ID" => "NULL", ">CITY_ID" => "0");
         $rsLocCount = CSaleLocation::GetList(array(), $arCityFilter, false, false, array("ID"));
         if ($rsLocCount->Fetch()) {
             $bEmptyCity = "N";
         }
     }
     //location value
     if ($locationId > 0) {
         if ($arLocation = CSaleLocation::GetByID($locationId)) {
             if ($bEmptyRegion == "Y" && $bEmptyCity == "Y") {
                 $countryId = $locationId;
             } else {
                 $countryId = $arLocation["COUNTRY_ID"];
             }
             if ($bEmptyCity == "Y") {
                 $regionId = $arLocation["ID"];
             } else {
                 $regionId = $arLocation["REGION_ID"];
             }
             $cityId = $locationId;
         }
     }
     //select country
     $arCountryList = array();
     if ($bEmptyRegion == "Y" && $bEmptyCity == "Y") {
         $rsCountryList = CSaleLocation::GetList(array("SORT" => "ASC", "NAME_LANG" => "ASC"), array("LID" => $langId), false, false, array("ID", "COUNTRY_ID", "COUNTRY_NAME_LANG"));
     } else {
         $rsCountryList = CSaleLocation::GetCountryList(array("SORT" => "ASC", "NAME_LANG" => "ASC"));
     }
     while ($arCountry = $rsCountryList->GetNext()) {
         if (!\Bitrix\Sale\SalesZone::checkCountryId($arCountry["ID"], $siteId)) {
             continue;
         }
         if ($bEmptyRegion == "Y" && $bEmptyCity == "Y") {
             $arCountry["NAME_LANG"] = $arCountry["COUNTRY_NAME_LANG"];
         }
         $arCountryList[] = $arCountry;
         if ($arCountry["ID"] == $countryId && strlen($arCountry["NAME_LANG"]) > 0) {
             $locationString .= $arCountry["NAME_LANG"];
         }
     }
     if (count($arCountryList) <= 0) {
         $arCountryList = array();
     } elseif (count($arCountryList) == 1) {
         $countryId = $arCountryList[0]["ID"];
     }
     //select region
     $arRegionList = array();
     if ($countryId > 0 || count($arCountryList) <= 0) {
         $arRegionFilter = array("LID" => $langId, "!REGION_ID" => "NULL", "!REGION_ID" => "0");
         if ($countryId > 0) {
             $arRegionFilter["COUNTRY_ID"] = IntVal($countryId);
         }
         if ($bEmptyCity == "Y") {
             $rsRegionList = CSaleLocation::GetList(array("SORT" => "ASC", "NAME_LANG" => "ASC"), $arRegionFilter, false, false, array("ID", "REGION_ID", "REGION_NAME_LANG"));
         } else {
             $rsRegionList = CSaleLocation::GetRegionList(array("SORT" => "ASC", "NAME_LANG" => "ASC"), $arRegionFilter);
         }
         while ($arRegion = $rsRegionList->GetNext()) {
             if (!\Bitrix\Sale\SalesZone::checkRegionId($arRegion["ID"], $siteId)) {
                 continue;
             }
             if ($bEmptyCity == "Y") {
                 $arRegion["NAME_LANG"] = $arRegion["REGION_NAME_LANG"];
             }
             $arRegionList[] = $arRegion;
             if ($arRegion["ID"] == $regionId && strlen($arRegion["NAME_LANG"]) > 0) {
                 $locationString = $arRegion["NAME_LANG"] . ", " . $locationString;
             }
         }
     }
     if (count($arRegionList) <= 0) {
         $arRegionList = array();
     } elseif (count($arRegionList) == 1) {
         $regionId = $arRegionList[0]["ID"];
     }
     //select city
     $arCityList = array();
     if ($bEmptyCity == "N" && (count($arCountryList) > 0 && count($arRegionList) > 0 && $countryId > 0 && $regionId > 0 || count($arCountryList) <= 0 && count($arRegionList) > 0 && $regionId > 0 || count($arCountryList) > 0 && count($arRegionList) <= 0 && $countryId > 0 || count($arCountryList) <= 0 && count($arRegionList) <= 0)) {
         $arCityFilter = array("LID" => $langId);
         if ($countryId > 0) {
             $arCityFilter["COUNTRY_ID"] = $countryId;
         }
         if ($regionId > 0) {
             $arCityFilter["REGION_ID"] = $regionId;
         }
         $rsLocationsList = CSaleLocation::GetList(array("SORT" => "ASC", "COUNTRY_NAME_LANG" => "ASC", "CITY_NAME_LANG" => "ASC"), $arCityFilter, false, false, array("ID", "CITY_ID", "CITY_NAME"));
         while ($arCity = $rsLocationsList->GetNext()) {
             if (!\Bitrix\Sale\SalesZone::checkCityId($arCity["CITY_ID"], $siteId)) {
                 continue;
             }
             $arCityList[] = array("ID" => $arCity["ID"], "CITY_ID" => $arCity['CITY_ID'], "CITY_NAME" => $arCity["CITY_NAME"]);
             if ($arCity["ID"] == $cityId) {
                 $locationString = (strlen($arCity["CITY_NAME"]) > 0 ? $arCity["CITY_NAME"] . ", " : "") . $locationString;
             }
         }
         //end while
     }
     return $locationString;
 }
Exemplo n.º 3
0
    $arParams["REGION"] = $arResult["REGION_LIST"][0]["ID"];
}
//select city
$arResult["CITY_LIST"] = array();
if ($arResult["EMPTY_CITY"] == "N" && (count($arResult["COUNTRY_LIST"]) > 0 && count($arResult["REGION_LIST"]) > 0 && $arParams["COUNTRY"] > 0 && $arParams["REGION"] > 0 || count($arResult["COUNTRY_LIST"]) <= 0 && count($arResult["REGION_LIST"]) > 0 && $arParams["REGION"] > 0 || count($arResult["COUNTRY_LIST"]) > 0 && count($arResult["REGION_LIST"]) <= 0 && $arParams["COUNTRY"] > 0 || count($arResult["COUNTRY_LIST"]) <= 0 && count($arResult["REGION_LIST"]) <= 0)) {
    $arCityFilter = array("LID" => LANGUAGE_ID);
    if ($arParams["COUNTRY"] > 0) {
        $arCityFilter["COUNTRY_ID"] = $arParams["COUNTRY"];
    }
    if ($arParams["REGION"] > 0) {
        $arCityFilter["REGION_ID"] = $arParams["REGION"];
    }
    if ($arParams['ALLOW_EMPTY_CITY'] == 'Y') {
        $rsLocationsList = CSaleLocation::GetList(array("SORT" => "ASC", "COUNTRY_NAME_LANG" => "ASC", "CITY_NAME_LANG" => "ASC"), $arCityFilter, false, false, array("ID", "CITY_ID", "CITY_NAME"));
        while ($arCity = $rsLocationsList->GetNext()) {
            if (!SalesZone::checkCityId($arCity["CITY_ID"], $arParams["SITE_ID"])) {
                continue;
            }
            $arResult["CITY_LIST"][] = array("ID" => $arCity[$arParams["CITY_OUT_LOCATION"] == "Y" ? "ID" : "CITY_ID"], "CITY_ID" => $arCity['CITY_ID'], "CITY_NAME" => $arCity["CITY_NAME"]);
            if ($arCity["ID"] == $arParams["CITY"]) {
                $locationString = (strlen($arCity["CITY_NAME"]) > 0 ? $arCity["CITY_NAME"] . ", " : "") . $locationString;
                if (IntVal($arParams["LOCATION_VALUE"]) <= 0) {
                    $arParams["LOCATION_VALUE"] = $arCity["ID"];
                }
                $arResult["LOCATION_DEFAULT"] = $arCity["ID"];
            }
        }
        //end while
    }
    //end if
}
Exemplo n.º 4
0
Loc::loadMessages(__FILE__);
$arResult = array();
if (!\Bitrix\Main\Loader::includeModule('sale')) {
    $arResult["ERROR"] = Loc::getMessage("SALE_SRV_LOCATION_CANT_INCLUDE_MODULE");
}
if (!isset($arResult["ERROR"]) && check_bitrix_sessid()) {
    $action = isset($_REQUEST['action']) ? trim($_REQUEST['action']) : '';
    $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : LANGUAGE_ID;
    $countryIds = isset($_REQUEST['countryIds']) ? $_REQUEST['countryIds'] : array();
    switch ($action) {
        case "getRegionList":
            $arResult["DATA"] = \Bitrix\Sale\SalesZone::getRegions($countryIds, $lang);
            break;
        case "getCityList":
            $regionIds = isset($_REQUEST['regionIds']) && is_array($_REQUEST['regionIds']) ? $_REQUEST['regionIds'] : array();
            $arResult["DATA"] = \Bitrix\Sale\SalesZone::getCities($countryIds, $regionIds, $lang);
            break;
    }
} else {
    if (!isset($arResult["ERROR"])) {
        $arResult["ERROR"] = Loc::getMessage("SALE_SRV_LOCATION_ACCESS_DENIED");
    }
}
if (isset($arResult["ERROR"])) {
    $arResult["RESULT"] = "ERROR";
} else {
    $arResult["RESULT"] = "OK";
}
/** @global CMain $APPLICATION */
if (strtolower(SITE_CHARSET) != 'utf-8') {
    $arResult = $APPLICATION->ConvertCharsetArray($arResult, SITE_CHARSET, 'utf-8');
Exemplo n.º 5
0
" name="sales_zone_cities[<?php 
                echo $siteList[$i]["ID"];
                ?>
][]" multiple size="10" class="sale-options-location-mselect">
								<option value=''<?php 
                echo in_array("", $sales_zone_cities) ? " selected" : "";
                ?>
><?php 
                echo GetMessage("SMO_LOCATION_ALL");
                ?>
</option>
								<?php 
                if (!in_array("", $sales_zone_regions)) {
                    ?>
									<?php 
                    $arCities = SalesZone::getCities($sales_zone_countries, $sales_zone_regions, LANGUAGE_ID);
                    ?>
									<?php 
                    foreach ($arCities as $cityId => $cityName) {
                        ?>
										<option value="<?php 
                        echo $cityId;
                        ?>
"<?php 
                        echo in_array($cityId, $sales_zone_cities) ? " selected" : "";
                        ?>
><?php 
                        echo htmlspecialcharsbx($cityName);
                        ?>
</option>
									<?php 
Exemplo n.º 6
0
 public static function convertSalesZones()
 {
     $siteList = \CSaleLocation::getSites();
     $siteList[] = '';
     // 'empty site' too
     foreach ($siteList as $siteId) {
         $countries = Sale\SalesZone::getCountriesIds($siteId);
         $regions = Sale\SalesZone::getRegionsIds($siteId);
         $cities = Sale\SalesZone::getCitiesIds($siteId);
         if (empty($countries) && empty($regions) && empty($cities)) {
             continue;
         }
         Sale\SalesZone::saveSelectedTypes(array('COUNTRY' => $countries, 'REGION' => $regions, 'CITY' => $cities), $siteId);
     }
 }
Exemplo n.º 7
0
			array("nTopCount" => 10),
			array(
				"ID", "CITY_ID", "CITY_NAME", "COUNTRY_NAME_LANG", "REGION_NAME_LANG"
			)
		);
		while ($arCity = $rsLocationsList->GetNext())
		{
			$arResult[] = array(
				"ID" => $arCity["ID"],
				"NAME" => "",
				"REGION_NAME" => $arCity["REGION_NAME_LANG"],
				"COUNTRY_NAME" => $arCity["COUNTRY_NAME_LANG"],
			);
		}

		$filter = \Bitrix\Sale\SalesZone::makeSearchFilter("country", $arParams["siteId"]);
		$filter["~COUNTRY_NAME"] = $search."%";
		$filter["LID"] = LANGUAGE_ID;
		$filter["CITY_ID"] = false;
		$filter["REGION_ID"] = false;
		$rsLocationsList = CSaleLocation::GetList(
			array(
				"COUNTRY_NAME_LANG" => "ASC",
				"SORT" => "ASC",
			),
			$filter,
			false,
			array("nTopCount" => 10),
			array(
				"ID", "COUNTRY_NAME_LANG"
			)