public static function copyDefaultLocations() { $sRes = Main\SiteTable::getList(); $sites = array(); while ($site = $sRes->fetch()) { $sites[] = $site['LID']; } $existed = array(); $res = Location\DefaultSiteTable::getList(); while ($item = $res->fetch()) { $existed[$item['SITE_ID']][$item['LOCATION_CODE']] = true; } $res = \CSaleLocation::GetList(array(), array('LID' => 'en', 'LOC_DEFAULT' => 'Y'), false, false, array('ID')); while ($item = $res->fetch()) { foreach ($sites as $site) { if (isset($existed[$site][$item['ID']])) { continue; } $opRes = Location\DefaultSiteTable::add(array('SITE_ID' => $site, 'LOCATION_CODE' => $item['ID'])); if (!$opRes->isSuccess()) { throw new Main\SystemException('Cannot add default location'); } } } }
/** * Read some data from database, using cache * @return void */ protected function obtainDataDefaultLocations(&$cachedData) { if(!$this->arParams['SHOW_DEFAULT_LOCATIONS']) return; $res = Location\DefaultSiteTable::getList(array( 'filter' => array( 'SITE_ID' => $this->arParams['FILTER_SITE_ID'], 'LOCATION.NAME.LANGUAGE_ID' => LANGUAGE_ID ), 'order' => array( 'SORT' => 'asc' ), 'select' => array( 'CODE' => 'LOCATION.CODE', 'ID' => 'LOCATION.ID', 'PARENT_ID' => 'LOCATION.PARENT_ID', 'TYPE_ID' => 'LOCATION.TYPE_ID', 'LATITUDE' => 'LOCATION.LATITUDE', 'LONGITUDE' => 'LOCATION.LONGITUDE', 'NAME' => 'LOCATION.NAME.NAME', 'SHORT_NAME' => 'LOCATION.NAME.SHORT_NAME', 'LEFT_MARGIN' => 'LOCATION.LEFT_MARGIN', 'RIGHT_MARGIN' => 'LOCATION.RIGHT_MARGIN' ) )); $defaults = array(); while($item = $res->Fetch()) $defaults[$item['ID']] = $item; if($this->filterBySite && !empty($defaults)) { // check default locations to be REALLY connected with a site $linkTypeMap = Location\SiteLocationTable::getLinkStatusForMultipleNodes($defaults, $this->arParams['FILTER_SITE_ID'], $cachedData['TEMP']['CONNECTORS']); foreach($defaults as $id => $default) { if(!in_array($linkTypeMap[$id], array(Location\Connector::LSTAT_IS_CONNECTOR, Location\Connector::LSTAT_BELOW_CONNECTOR))) unset($defaults[$id]); } } foreach($defaults as &$default) { unset($default['LEFT_MARGIN']); unset($default['RIGHT_MARGIN']); } $cachedData['DEFAULT_LOCATIONS'] = $defaults; }