32 #####################################
34 #####################################
44 'name' =>
'Bitrix\Sale\Location\Location',
50 'excludedColumns' => array()
55 'name' =>
'Bitrix\Sale\Location\Name\Location',
58 'includedColumns' => array(
'NAME',
'SHORT_NAME')
61 'includedColumns' => array(
'NAME',
'SHORT_NAME')
66 'name' =>
'Bitrix\Sale\Location\External',
69 'includedColumns' => array(
'ID',
'XML_ID',
'SERVICE_ID')
76 ##############################################
77 ##############################################
78 ##############################################
82 $columns = static::getColumns(
'list');
83 foreach($columns as $code => &$col)
85 $col[
'DEFAULT'] = in_array($code, array(
'ID',
'TYPE_ID',
'NAME_'.ToUpper(LANGUAGE_ID),
'SORT'));
93 $columns = static::getFilterColumns();
94 unset($columns[
'PARENT_ID']);
102 $parameters = parent::getParametersForList($proxed);
104 if(isset($parameters[
'order'][
'TYPE_ID']))
106 $parameters[
'order'][
'TYPE.SORT'] = $parameters[
'order'][
'TYPE_ID'];
107 unset($parameters[
'order'][
'TYPE_ID']);
115 $formData = parent::getFormData($id);
118 $formData = array_merge($formData, static::getExternalData($id));
123 ##############################################
124 ##############################################
125 ##############################################
130 $errors = parent::validateUpdateRequest($data);
134 $typeId = (int)($data[
'TYPE_ID'] ?? 0);
137 $type = Location\TypeTable::getRow([
158 $errors[] =
Loc::getMessage(
'SALE_LOCATION_ADMIN_LOCATION_HELPER_ENTITY_TYPE_ID_UNKNOWN_ERROR');
162 if (!empty($data[
'EXTERNAL']) && is_array($data[
'EXTERNAL']))
166 foreach ($data[
'EXTERNAL'] as $external)
168 if (!isset($services[$external[
'SERVICE_ID']]))
170 $errors[] =
Loc::getMessage(
'SALE_LOCATION_ADMIN_LOCATION_HELPER_ENTITY_UNKNOWN_EXTERNAL_SERVICE_ID_ERROR');
176 if (!empty($data[
'NAME']) && is_array($data[
'NAME']))
178 $hasValidName =
false;
180 foreach($data[
'NAME'] as $fields)
182 if (!empty($fields[
'NAME']))
184 $hasValidName =
true;
191 $errors[] =
Loc::getMessage(
'SALE_LOCATION_ADMIN_LOCATION_HELPER_ENTITY_NAME_EMPTY_ERROR');
200 $externals = $data[
'EXTERNAL'];
201 unset($data[
'EXTERNAL']);
203 if(is_array($externals) && !empty($externals))
205 foreach($externals as $eId => $external)
207 if($external[
'XML_ID'] ==
'')
208 unset($externals[$eId]);
212 $data = parent::proxyUpdateRequest($data);
214 if(!empty($externals))
215 $data[
'EXTERNAL'] = $externals;
222 $parameters = parent::proxyListRequest($page);
226 if(!isset($parameters[
'filter'][
'=PARENT_ID']))
229 $parameters[
'filter'][
'=PARENT_ID'] = intval($_REQUEST[
'PARENT_ID']);
231 $parameters[
'filter'][
'=PARENT_ID'] = 0;
235 if(isset($parameters[
'order'][
'TYPE_ID']))
237 $parameters[
'order'][
'TYPE.SORT'] = $parameters[
'order'][
'TYPE_ID'];
238 unset($parameters[
'order'][
'TYPE_ID']);
245 public static function update($primary, $data, $batch =
false)
248 $entityClass = static::getEntityClass();
250 $data = static::convertToArray($data);
251 $data = static::proxyUpdateRequest($data);
252 $errors = static::validateUpdateRequest($data);
256 $res = $entityClass::update($primary, $data, array(
'RESET_LEGACY' => !$batch));
257 if(!$res->isSuccess())
260 $errors = $res->getErrorMessages();
267 'success' => $success,
273 public static function delete($primary, $batch =
false)
277 $entityClass = static::getEntityClass();
279 $res = $entityClass::deleteExtended($primary, array(
'RESET_LEGACY' => !$batch));
280 if(!$res->isSuccess())
283 $errors = $res->getErrorMessages();
287 'success' => $success,
292 #####################################
294 #####################################
298 return \Bitrix\Main\Config\Option::get(
'sale',
'sale_locationpro_import_performed',
'') ==
'Y';
303 if(!($id = intval($id)))
306 $class = static::getEntityClass(
'main');
307 $item = $class::getList(array(
308 'filter' => array(
'=ID' => $id),
309 'select' => array(
'PARENT_ID')
312 return $item[
'PARENT_ID'];
317 $res = Location\LocationTable::getExternalData($id);
319 while($item = $res->Fetch())
320 $result[
'EXTERNAL'][$item[
'ID']] = $item;
329 if($services ==
null)
331 $res = Location\ExternalServiceTable::getList();
333 while($item = $res->Fetch())
334 $services[$item[
'ID']] = $item;
347 if ($result ===
null)
351 $yandexMarketEs = Location\ExternalServiceTable::getList([
352 'filter' => [
'=CODE' => \CSaleYMLocation::EXTERNAL_SERVICE_CODE]
357 $result = (int)$yandexMarketEs[
'ID'];
376 $typesWithNames = Location\Admin\TypeHelper::getTypes();
377 foreach($typesWithNames as $type)
379 $types[intval($type[
'ID'])] = $type[
'NAME_CURRENT'];
388 return static::readMap(
'external',
'detail');
393 return mb_strpos(($_REQUEST[
'admin_mnu_menu_id'] ??
''), self::MENU_ITEMS_QUERY_STRING_TAG) !==
false;
403 $requiredToShow =
false;
407 if(self::checkRequestIsMenuRequest())
409 $requiredToShow =
true;
410 $id = $queryParams[
'ID'];
415 $page =
$GLOBALS[
'APPLICATION']->GetCurPage();
416 if($page ==
'/bitrix/admin/'.self::LIST_PAGE_URL || $page ==
'/bitrix/admin/'.self::EDIT_PAGE_URL)
418 $requiredToShow =
true;
420 $parentId = (int)($_REQUEST[
'PARENT_ID'] ?? 0);
423 $parentId = (int)($_REQUEST[
'parent_id'] ?? 0);
439 'LOCATION_NAME' =>
'NAME.NAME',
445 '=NAME.LANGUAGE_ID' => LANGUAGE_ID
448 'LOCATION_NAME' =>
'asc'
456 $res = Location\LocationTable::getParentTree($id, $parameters, array(
'SHOW_CHILDREN' =>
true));
465 $res = Location\LocationTable::getChildren(
false, $parameters);
469 while($item = $res->Fetch())
471 $index[$item[
'PARENT_ID']][$item[
'ID']] = array(
472 'NAME' => htmlspecialcharsbx($item[
'LOCATION_NAME']),
473 'PARENT_ID' => intval($item[
'PARENT_ID']),
474 'CHILD_CNT' => intval($item[
'CHILD_CNT'])
492 $query = array(self::MENU_ITEMS_QUERY_STRING_TAG, intval($parameters[
'ID']));
493 if(isset($parameters[
'LIMIT']))
494 $query[] = intval($parameters[
'LIMIT']);
497 if(self::checkRequestIsMenuRequest() && isset($inRequest[
'LIMIT']))
498 $query[] = intval($inRequest[
'LIMIT']);
503 if(isset($parameters[
'SHOW_CHECKBOX']))
504 $query[] = $parameters[
'SHOW_CHECKBOX'] ?
'1' :
'0';
507 if(self::checkRequestIsMenuRequest() && isset($inRequest[
'SHOW_CHECKBOX']))
508 $query[] = $inRequest[
'SHOW_CHECKBOX'] ?
'1' :
'0';
513 return implode(self::MENU_ITEMS_QUERY_STRING_DELIMITER, $query);
518 $path = explode(self::MENU_ITEMS_QUERY_STRING_DELIMITER, ($_REQUEST[
'admin_mnu_menu_id'] ??
''));
521 'ID' => (isset($path[1]) && intval($path[1])) ? intval($path[1]) :
false,
522 'LIMIT' => isset($path[2]) ? intval($path[2]) : 0,
523 'SHOW_CHECKBOX' => isset($path[3]) ? (!!$path[3]) :
false,
527 public static function getListUrl($parent =
false, $parameters = array())
529 if(!is_array($parameters))
530 $parameters = array();
532 if($parent !==
false)
536 $parameters[static::URL_PARAM_PARENT_ID] = intval($parent);
540 return parent::getListUrl($parameters);
543 public static function getEditUrl($node =
false, $parameters = array())
545 if(!is_array($parameters))
546 $parameters = array();
549 $parameters[static::URL_PARAM_ID] = $node;
551 return self::getUrl(static::EDIT_PAGE_URL, $parameters);
564 if(is_array($index[$attachWhat]))
566 foreach($index[$attachWhat] as $id => $item)
568 if($limit && (!$overflow && $i >= $limit) || ($overflow && $inChain))
574 "url" => static::getListUrl(intval($item[
'PARENT_ID'])),
575 "module_id" =>
"sale",
576 "parent_menu" => self::packItemsQueryString(array(
'ID' => $item[
'PARENT_ID'],
'LIMIT' => $limit,
'SHOW_CHECKBOX' => $queryParams[
'SHOW_CHECKBOX'])),
580 $inChain = isset($index[$id]);
582 if(!$overflow || $inChain)
585 "text" => ($queryParams[
'SHOW_CHECKBOX'] ?
'<input type="checkbox" value="'.intval($id).
'" /> ' :
'').$item[
'NAME'],
586 "fav_id" => intval($id),
587 "url" => \CHTTP::urlAddParams(static::getListUrl(intval($id)), [
"apply_filter" =>
"y"]),
588 "module_id" =>
"sale",
589 "items_id" =>
self::packItemsQueryString(array(
'ID' => $id,
'LIMIT' => $limit,
'SHOW_CHECKBOX' => $queryParams[
'SHOW_CHECKBOX'])),
591 "parent_menu" =>
self::packItemsQueryString(array(
'ID' => $item[
'PARENT_ID'],
'LIMIT' => $limit,
'SHOW_CHECKBOX' => $queryParams[
'SHOW_CHECKBOX'])),
593 self::getEditUrl(intval($id)),
594 self::getEditUrl(
false, array(
'parent_id' => intval($id)))
598 if($item[
'CHILD_CNT'])
600 $node[
'dynamic'] =
true;
601 $node[
'items'] = array();
615 public static function getLocationStringById($primary, $behaviour = array(
'INVERSE' =>
false,
'DELIMITER' =>
', ',
'LANGUAGE_ID' => LANGUAGE_ID))
617 return static::getLocationStringByCondition(array(
'=ID' => $primary), $behaviour);
620 public static function getLocationStringByCode($primary, $behaviour = array(
'INVERSE' =>
false,
'DELIMITER' =>
', ',
'LANGUAGE_ID' => LANGUAGE_ID))
622 return static::getLocationStringByCondition(array(
'=CODE' => $primary), $behaviour);
625 protected static function getLocationStringByCondition($condition, $behaviour = array(
'INVERSE' =>
false,
'DELIMITER' =>
', ',
'LANGUAGE_ID' => LANGUAGE_ID))
627 if(isset($behaviour) && !is_array($behaviour))
628 $behaviour = array();
630 if(!isset($behaviour[
'DELIMITER']))
631 $behaviour[
'DELIMITER'] =
', ';
633 if(!isset($behaviour[
'LANGUAGE_ID']))
634 $behaviour[
'LANGUAGE_ID'] = LANGUAGE_ID;
638 $res = Location\LocationTable::getPathToNodeByCondition($condition, array(
'select' => array(
'LNAME' =>
'NAME.NAME'),
'filter' => array(
'=NAME.LANGUAGE_ID' => $behaviour[
'LANGUAGE_ID'])));
640 while($item = $res->fetch())
642 $path[] = $item[
'LNAME'];
645 if($behaviour[
'INVERSE'])
646 $path = array_reverse($path);
648 return implode($behaviour[
'DELIMITER'], $path);
660 if(!is_array($parameters))
661 $parameters = array();
663 $parameters[
'filter'][] = array(
665 array(
'=SERVICE.CODE' =>
'ZIP'),
666 array(
'=SERVICE.CODE' =>
'ZIP_LOWER')
669 $parameters[
'filter'][
'=XML_ID'] = $zip;
670 $parameters[
'order'][
'SERVICE_CODE'] =
'ASC';
671 $parameters[
'select'][] =
'*';
672 $parameters[
'select'][
'SERVICE_CODE'] =
'SERVICE.CODE';
674 return \Bitrix\Sale\Location\ExternalTable::getList($parameters);
679 if($locationCode ==
'')
680 return new \Bitrix\Main\DB\ArrayResult(array());
682 if(!is_array($parameters))
683 $parameters = array();
685 $parameters[
'filter'][] = array(
687 array(
'=SERVICE.CODE' =>
'ZIP'),
688 array(
'=SERVICE.CODE' =>
'ZIP_LOWER')
690 $parameters[
'order'][
'SERVICE_CODE'] =
'ASC';
691 $parameters[
'filter'][
'=LOCATION.CODE'] = $locationCode;
692 $parameters[
'select'][] =
'*';
693 $parameters[
'select'][
'SERVICE_CODE'] =
'SERVICE.CODE';
695 return \Bitrix\Sale\Location\ExternalTable::getList($parameters);
700 return Main\Config\Option::get(
'sale',
'sale_locationpro_migrated',
'') ==
'Y';
706 return static::checkLocationMigrated();
712 static::deleteInformer(
'SALE_LOCATIONPRO_DATABASE_FAILURE');
715 "MESSAGE" =>
Loc::getMessage(
'SALE_LOCATION_ADMIN_LOCATION_HELPER_DATABASE_FAILURE', array(
716 '#ANCHOR_IMPORT_URL#' =>
'<a target="_blank" href="'.static::getImportUrl().
'">',
717 '#ANCHOR_END#' =>
'</a>'
719 "TAG" =>
'SALE_LOCATIONPRO_DATABASE_FAILURE',
720 "MODULE_ID" =>
"sale",
721 "ENABLE_CLOSE" =>
"Y",
722 "PUBLIC_SECTION" =>
"N"
724 \CAdminNotify::Add($fields);
728 if((
string) $informerTag ==
'')
731 $rsAdminNotify = \CAdminNotify::GetList(array(), array(
'MODULE_ID'=>
'sale',
'TAG' => $informerTag));
732 if ($arAdminNotify = $rsAdminNotify->Fetch())
734 \CAdminNotify::DeleteByTag($informerTag);
746 if((
string) $primary === (
string) intval($primary))
747 return static::getLocationStringById($primary);
749 return static::getLocationStringByCode($primary);
static isInternalRequest()
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getLocationPathDisplay($primary)
const URL_PARAM_PARENT_ID
static proxyListRequest($page='list')
static getEntityRoadMap()
static getLocationsByZip($zip, $parameters=array())
static deleteInformer($informerTag)
static getExternalServicesList()
const MENU_ITEMS_QUERY_STRING_TAG
static getLocationStringByCode($primary, $behaviour=array('INVERSE'=> false, 'DELIMITER'=> ', ', 'LANGUAGE_ID'=> LANGUAGE_ID))
static informAdminLocationDatabaseFailure()
static proxyUpdateRequest($data)
const MENU_LOCATION_PARENT_TAG
static checkFirstImportDone()
static getListUrl($parent=false, $parameters=array())
const MENU_ITEMS_QUERY_STRING_DELIMITER
static appendMenuChildren(&$attachTo, $attachWhat, $index, $queryParams)
static update($primary, $data, $batch=false)
static getFilterColumns()
static getExternalData($id)
static getZipByLocation($locationCode, $parameters=array())
static checkLocationEnabled()
static getLocationStringByCondition($condition, $behaviour=array('INVERSE'=> false, 'DELIMITER'=> ', ', 'LANGUAGE_ID'=> LANGUAGE_ID))
static getLocationSubMenu()
static unPackItemsQueryString()
static getListGridColumns()
static getParametersForList($proxed)
static packItemsQueryString($parameters=array())
static checkLocationMigrated()
static checkRequestIsMenuRequest()
static validateUpdateRequest($data)
static getYandexMarketExternalServiceId()
static getLocationStringById($primary, $behaviour=array('INVERSE'=> false, 'DELIMITER'=> ', ', 'LANGUAGE_ID'=> LANGUAGE_ID))
static getEditUrl($node=false, $parameters=array())
$GLOBALS['____1444769544']