Skip to content

Instantly share code, notes, and snippets.

@yakubenko
Created August 23, 2016 05:44
Show Gist options
  • Save yakubenko/4a7330a001af6c0a683374afa2066e2f to your computer and use it in GitHub Desktop.
Save yakubenko/4a7330a001af6c0a683374afa2066e2f to your computer and use it in GitHub Desktop.
Bitrix get locations group
<?php
function getLocationGroup() {
// из конфига config.php
global $defaultLocationsGroup;
$obCache = new CPHPCache;
if($obCache->InitCache(7200, "cities", "/klamas/all")) {
$locationsCache = $obCache->getVars();
$locations = $locationsCache['cities'];
} elseif($obCache->StartDataCache()) {
$locations = array();
$db_res = CSaleLocationGroup::GetLocationList(array("LOCATION_GROUP_ID"=>$defaultLocationsGroup));
while($ar_res = $db_res->Fetch()) {
$locations[$ar_res["LOCATION_ID"]] = CSaleLocation::GetByID($ar_res["LOCATION_ID"]);
}
foreach($locations as $location) {
// РЕГИОН
if(empty($location['CITY_NAME_ORIG'])) {
$locations['REGIONS'][$location['REGION_ID']] = $location;
} else {
$locations['REGIONS'][$location['REGION_ID']]['CITIES'][$location['CITY_ID']] = $location;
}
unset($locations[$location['ID']]);
}
$obCache->EndDataCache(array('cities'=>$locations));
}
return $locations;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment