Пример #1
0
 public static function createType($type)
 {
     $res = Location\TypeTable::add($type);
     if (!$res->isSuccess()) {
         throw new Main\SystemException('Type creation failed: ' . implode(', ', $res->getErrorMessages()));
     }
     return $res->getId();
 }
Пример #2
0
 public static function createType($type)
 {
     $map = Location\TypeTable::getMap($type);
     if (is_array($type)) {
         foreach ($type as $fld => $val) {
             if (!isset($map[$fld])) {
                 unset($type[$fld]);
             }
         }
     }
     $res = Location\TypeTable::add($type);
     if (!$res->isSuccess()) {
         throw new Main\SystemException('Type creation failed: ' . implode(', ', $res->getErrorMessages()));
     }
     return $res->getId();
 }
Пример #3
0
 public static function createBaseTypes()
 {
     $types = array('COUNTRY' => array('CODE' => 'COUNTRY', 'SORT' => 100, 'DISPLAY_SORT' => 700, 'NAME' => array()), 'REGION' => array('CODE' => 'REGION', 'SORT' => 300, 'DISPLAY_SORT' => 500, 'NAME' => array()), 'CITY' => array('CODE' => 'CITY', 'SORT' => 600, 'DISPLAY_SORT' => 100, 'NAME' => array()));
     $langs = array();
     $res = \Bitrix\Main\Localization\LanguageTable::getList();
     while ($item = $res->Fetch()) {
         $MESS = array();
         @(include $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/sale/lang/' . $item['LID'] . '/lib/location/migration/migrate.php');
         if (!empty($MESS)) {
             $types['COUNTRY']['NAME'][$item['LID']]['NAME'] = $MESS['SALE_LOCATION_TYPE_COUNTRY'];
             $types['REGION']['NAME'][$item['LID']]['NAME'] = $MESS['SALE_LOCATION_TYPE_REGION'];
             $types['CITY']['NAME'][$item['LID']]['NAME'] = $MESS['SALE_LOCATION_TYPE_CITY'];
         }
         $langs[$item['LID']] = true;
     }
     $typeCode2Id = array();
     $res = Location\TypeTable::getList(array('select' => array('ID', 'CODE')));
     while ($item = $res->Fetch()) {
         $typeCode2Id[$item['CODE']] = $item['ID'];
     }
     foreach ($types as $code => &$type) {
         foreach ($langs as $lid => $f) {
             $type['NAME'][$lid] = \Bitrix\Sale\Location\Admin\NameHelper::getTranslatedName($type['NAME'], $lid);
         }
         if (!isset($typeCode2Id[$type['CODE']])) {
             $typeCode2Id[$type['CODE']] = Location\TypeTable::add($type);
         } else {
             // ensure it has all appropriate translations
             // we can not use ::updateMultipleForOwner() here, because user may rename types manually
             Location\Name\TypeTable::addAbsentForOwner($typeCode2Id[$type['CODE']], $type['NAME']);
         }
     }
     return $typeCode2Id;
 }
Пример #4
0
 public function createTypes()
 {
     $res = \Bitrix\Main\Localization\LanguageTable::getList();
     $types = array('COUNTRY' => array('CODE' => 'COUNTRY', 'SORT' => 100, 'NAME' => array()), 'REGION' => array('CODE' => 'REGION', 'SORT' => 300, 'NAME' => array()), 'CITY' => array('CODE' => 'CITY', 'SORT' => 600, 'NAME' => array()));
     while ($item = $res->Fetch()) {
         $MESS = array();
         include $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/sale/lang/' . $item['LID'] . '/lib/location/migration/migrate.php';
         $types['COUNTRY']['NAME'][$item['LID']]['NAME'] = $MESS['SALE_LOCATION_TYPE_COUNTRY'];
         $types['REGION']['NAME'][$item['LID']]['NAME'] = $MESS['SALE_LOCATION_TYPE_REGION'];
         $types['CITY']['NAME'][$item['LID']]['NAME'] = $MESS['SALE_LOCATION_TYPE_CITY'];
     }
     $res = Location\TypeTable::getList();
     while ($item = $res->Fetch()) {
         unset($types[$item['CODE']]);
     }
     foreach ($types as $type) {
         $res = Location\TypeTable::add($type);
         if (!($this->data['TYPE'][$type['CODE']] = $res->getId())) {
             throw new Main\SystemException('Cannot add location type: ' . implode(', ', $res->getErrors()), 0, __FILE__, __LINE__);
         }
     }
 }