예제 #1
0
 /**
  * <p>Метод удаляет все местоположения из базы. Метод динамичный.</p> <br><br>
  *
  *
  * @return mixed 
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalelocation/csalelocation__deleteall.1cda6559.php
  * @author Bitrix
  */
 public static function DeleteAll()
 {
     global $DB;
     foreach (GetModuleEvents("sale", "OnBeforeLocationDeleteAll", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent) === false) {
             return false;
         }
     }
     if (self::isLocationProMigrated()) {
         //main
         $DB->Query("DELETE FROM " . Location\LocationTable::getTableName());
         $DB->Query("DELETE FROM " . Location\GroupTable::getTableName());
         $DB->Query("DELETE FROM " . Location\TypeTable::getTableName());
         //names
         $DB->Query("DELETE FROM " . Location\Name\LocationTable::getTableName());
         $DB->Query("DELETE FROM " . Location\Name\GroupTable::getTableName());
         $DB->Query("DELETE FROM " . Location\Name\TypeTable::getTableName());
         //links
         $DB->Query("DELETE FROM " . Location\GroupLocationTable::getTableName());
         $DB->Query("DELETE FROM " . Location\SiteLocationTable::getTableName());
         $DB->Query("DELETE FROM " . Delivery\DeliveryLocationTable::getTableName());
         //other
         $DB->Query("DELETE FROM " . Location\DefaultSiteTable::getTableName());
         $DB->Query("DELETE FROM " . Location\ExternalTable::getTableName());
         $DB->Query("DELETE FROM " . Location\ExternalServiceTable::getTableName());
     }
     $DB->Query("DELETE FROM b_sale_location2location_group");
     $DB->Query("DELETE FROM b_sale_location_group_lang");
     $DB->Query("DELETE FROM b_sale_location_group");
     $DB->Query("DELETE FROM b_sale_delivery2location");
     $DB->Query("DELETE FROM b_sale_location");
     $DB->Query("DELETE FROM b_sale_location_city_lang");
     $DB->Query("DELETE FROM b_sale_location_city");
     $DB->Query("DELETE FROM b_sale_location_country_lang");
     $DB->Query("DELETE FROM b_sale_location_country");
     $DB->Query("DELETE FROM b_sale_location_region_lang");
     $DB->Query("DELETE FROM b_sale_location_region");
     $DB->Query("DELETE FROM b_sale_location_zip");
     foreach (GetModuleEvents("sale", "OnLocationDeleteAll", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent);
     }
 }
예제 #2
0
 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');
             }
         }
     }
 }
예제 #3
0
	/**
	 * 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;
	}