Esempio n. 1
0
 protected function stageIntegrityPreserve()
 {
     $lay = $this->getRemoteLayout(true);
     $this->restoreIndexes('IX_B_SALE_LOC_PARENT');
     $res = Location\LocationTable::getList(array('select' => array('ID', 'CODE'), 'filter' => array('=PARENT_ID' => 0)));
     $relations = array();
     $code2id = array();
     while ($item = $res->fetch()) {
         if (isset($lay[$item['CODE']]) && (string) $lay[$item['CODE']]['PARENT_CODE'] != '') {
             $relations[$item['CODE']] = $lay[$item['CODE']]['PARENT_CODE'];
         }
         // relations is a match between codes from the layout file
         $code2id[$item['CODE']] = $item['ID'];
     }
     $parentCode2id = $this->getLocationCodeToIdMap($relations);
     foreach ($code2id as $code => $id) {
         if (isset($parentCode2id[$relations[$code]]) && (string) $parentCode2id[$relations[$code]] != '') {
             $res = Location\LocationTable::update($id, array('PARENT_ID' => $parentCode2id[$relations[$code]]));
             if (!$res->isSuccess()) {
                 throw new Main\SystemException('Cannot make element become a child of its legal parent');
             }
         }
     }
     $this->nextStage();
 }
Esempio n. 2
0
 protected static function RebindLocationTriplet($fields = array())
 {
     $country = intval($fields['COUNTRY_ID']);
     $region = intval($fields['REGION_ID']);
     $city = intval($fields['CITY_ID']);
     foreach (GetModuleEvents('sale', 'OnBeforeLocationAdd', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($fields)) === false) {
             return false;
         }
     }
     if ($region && $country) {
         $uRes = \Bitrix\Sale\Location\LocationTable::update($region, array('PARENT_ID' => $country));
     }
     if ($city) {
         if ($region) {
             $uRes = \Bitrix\Sale\Location\LocationTable::update($city, array('PARENT_ID' => $region));
         } elseif ($country) {
             $uRes = \Bitrix\Sale\Location\LocationTable::update($city, array('PARENT_ID' => $country));
         }
     }
     if (intval($fields['SORT'])) {
         $loc2Update = $city ? $city : ($region ? $region : ($country ? $country : false));
         if ($loc2Update) {
             $uRes = \Bitrix\Sale\Location\LocationTable::update($loc2Update, array('SORT' => $fields['SORT']));
         }
     }
     foreach (GetModuleEvents('sale', 'OnLocationAdd', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($loc2Update, $fields));
     }
     return $loc2Update;
 }
Esempio n. 3
0
 /**
  * <p>Метод добавляет новое местоположение на основании параметров массива <i> arFields</i>. Метод динамичный.</p> <p class="note"><b>Внимание!</b> Начиная с версии 14.10.0 метод не обновляется и обратная совместимость не поддерживается. Рекомендуется использовать методы нового ядра D7. Примеры работы с новым ядром можно увидеть <a href="https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&amp;LESSON_ID=3570" >здесь</a>.</p>
  *
  *
  * @param array $arFields  Ассоциативный массив параметров местоположения с ключами: <ul> <li>
  * <b>SORT</b> - индекс сортировки; </li> <li> <b>COUNTRY_ID</b> - код страны;</li> <li>
  * <b>REGION_ID</b> - код региона;</li> <li> <b>CITY_ID</b> - код города.</li> </ul>
  *
  * @return int <p>Возвращается код добавленного местоположения или <i>false</i> у
  * случае ошибки.</p> <a name="examples"></a>
  *
  * <h4>Example</h4> 
  * <pre>
  * Параметры вызова
  * </h
  * <tr>
  * <th width="15%">Параметр</th>
  * <th>Описание</th>
  * </tr>
  * <tr>
  * <td>arFields</td>
  * <td>Ассоциативный массив параметров местоположения с ключами:
  * <ul>
  * <li>
  * <b>SORT</b> - индекс сортировки; </li>
  * 	<li>
  * <b>COUNTRY_ID</b> - код страны;</li>
  * 	<li>
  * <b>REGION_ID</b> - код региона;</li>
  * 	<li>
  * <b>CITY_ID</b> - код города.</li>
  * </ul>
  * </td>
  * </tr>
  * 
  * 
  * 
  * &lt;?
  * // Добавим местоположение из страны с кодом 2 и города с кодом 10
  * $ID = CSaleLocation::AddLocation(
  *       array(
  *          "COUNTRY_ID" =&gt; 2,
  *          "CITY_ID" =&gt; 10
  *          )
  *       );
  * ?&gt;
  * </pre>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalelocation/csalelocation__addlocation.21fe0465.php
  * @author Bitrix
  */
 public static function AddLocation($arFields)
 {
     global $DB;
     if (!CSaleLocation::LocationCheckFields("ADD", $arFields)) {
         return false;
     }
     if (self::isLocationProMigrated()) {
         return self::RebindLocationTriplet($arFields);
     }
     // make IX_B_SALE_LOC_CODE feel happy
     $arFields['CODE'] = 'randstr' . rand(999, 99999);
     foreach (GetModuleEvents('sale', 'OnBeforeLocationAdd', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($arFields)) === false) {
             return false;
         }
     }
     $arInsert = $DB->PrepareInsert("b_sale_location", $arFields);
     $strSql = "INSERT INTO b_sale_location(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = IntVal($DB->LastID());
     // make IX_B_SALE_LOC_CODE feel happy
     Location\LocationTable::update($ID, array('CODE' => $ID));
     foreach (GetModuleEvents('sale', 'OnLocationAdd', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arFields));
     }
     return $ID;
 }
Esempio n. 4
0
	private static function AddLocationPart($creat, $type, $parent, $sort)
	{
		$langs = self::getLanguages();
		$types = self::getTypes();

		$creatFlds = array();
		if(is_numeric($creat))
		{

			// check whether location exists...
			$res = Location\LocationTable::getList(array('filter' => array('='.$type.'_ID' => $creat, 'TYPE_ID' => $types[$type]), 'select' => array('ID'), 'limit' => 1))->fetch();
			if($res['ID'])
			{
				$parent = intval($res['ID']);
			}
			else
			{
				if($type == 'COUNTRY')
					$res = self::GetCountryByID($creat); //!!!
				elseif($type == 'REGION')
					$res = self::GetRegionByID($creat); //!!!
				elseif($type == 'CITY')
					$res = self::GetCityByID($creat); //!!!

				if(!$res) // no such type exists, smth strange
					throw new Exception('No such '.$type);

				// create location using type found
				$creatFlds[$type.'_ID'] = $res['ID'];

				$creatFlds['NAME'] = array();
				foreach($langs as $lid)
				{
					if($type == 'COUNTRY')
						$name = self::GetCountryLangByID($res['ID'], $lid); //!!!
					elseif($type == 'REGION')
						$name = self::GetRegionLangByID($res['ID'], $lid); //!!!
					elseif($type == 'CITY')
						$name = self::GetCityLangByID($res['ID'], $lid); //!!!

					$creatFlds['NAME'][$lid] = array(
						'NAME' => $name['NAME'],
						'SHORT_NAME' => $name['SHORT_NAME']
					);
				}
			}
		}
		elseif(is_array($creat)) // should create type
		{
			$creatFlds[$type.'_ID'] = self::getFreeId($type);
			$creatFlds['NAME'] = array();

			foreach($creat as $lid => $name)
			{
				$creatFlds['NAME'][$lid] = array(
					'NAME' => $name['NAME'],
					'SHORT_NAME' => $name['SHORT_NAME']
				);
			}
		}

		if(!empty($creatFlds))
		{
			$creatFlds['PARENT_ID'] = $parent;
			$creatFlds['TYPE_ID'] = $types[$type];

			$creatFlds['CODE'] = rand(999,99999999);

			if($sort !== false)
				$creatFlds['SORT'] = $sort;

			$res = Location\LocationTable::add($creatFlds);
			if(!$res->isSuccess())
				throw new Exception('Cannot add location');

			$parent = $res->getId();
			Location\LocationTable::update($parent, array('CODE' => $parent));
		}

		return $parent;
	}
Esempio n. 5
0
	function AddLocation($arFields)
	{
		global $DB;

		if (!CSaleLocation::LocationCheckFields("ADD", $arFields))
			return false;

		// make IX_B_SALE_LOC_CODE feel happy
		$arFields['CODE'] = 'randstr'.rand(999, 99999);

		$db_events = GetModuleEvents("sale", "OnBeforeLocationAdd");
		while ($arEvent = $db_events->Fetch())
			if (ExecuteModuleEventEx($arEvent, array($arFields))===false)
				return false;

		$arInsert = $DB->PrepareInsert("b_sale_location", $arFields);
		$strSql =
			"INSERT INTO b_sale_location(".$arInsert[0].") ".
			"VALUES(".$arInsert[1].")";
		$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

		$ID = IntVal($DB->LastID());

		// make IX_B_SALE_LOC_CODE feel happy
		Location\LocationTable::update($ID, array('CODE' => $ID));

		$events = GetModuleEvents("sale", "OnLocationAdd");
		while ($arEvent = $events->Fetch())
			ExecuteModuleEventEx($arEvent, array($ID, $arFields));

		return $ID;
	}