34 if(!isset($initParams[
"PARENT_ID"]))
39 if(!$this->parentAutomatic || !($this->parentAutomatic instanceof
Automatic))
40 throw new SystemException(
"Can't initialize AutomaticProfile's id: ".$initParams[
"ID"].
" parent Automatic parent_id: ".$initParams[
"PARENT_ID"]);
42 $this->parentSid = $this->parentAutomatic->getSid();
44 if($this->parentSid ==
'')
45 throw new SystemException(
"Can't determine AutomaticProfile's SID. profile id: ".$initParams[
"ID"].
" parent Automatic id: ".$initParams[
"PARENT_ID"]);
47 $this->parentHandlerInitParams = $this->parentAutomatic->getHandlerInitParams($this->parentSid);
49 if($this->parentHandlerInitParams ===
false)
50 throw new SystemException(
"Can't get init services params of Automatic delivery service with sid: ".$this->parentSid);
52 parent::__construct($initParams);
54 if(isset($initParams[
'PROFILE_ID']) && $initParams[
'PROFILE_ID'] <>
'')
55 $this->profileId = $initParams[
'PROFILE_ID'];
56 elseif(isset($this->config[
"MAIN"][
"PROFILE_ID"]))
57 $this->profileId = $this->config[
"MAIN"][
"PROFILE_ID"];
59 if($this->profileId <>
'' && !array_key_exists($this->profileId, $this->parentHandlerInitParams[
"PROFILES"]))
60 throw new SystemException(
"Profile \"".$this->profileId.
"\" is not part of Automatic delivery service with sid: ".$this->parentSid);
62 if($this->name ==
'' && isset($this->parentHandlerInitParams[
'PROFILES'][$this->profileId][
'TITLE']))
63 $this->name = $this->parentHandlerInitParams[
'PROFILES'][
$this->profileId][
'TITLE'];
65 if($this->description ==
'' && isset($this->parentHandlerInitParams[
'PROFILES'][$this->profileId][
'DESCRIPTION']))
66 $this->description = $this->parentHandlerInitParams[
'PROFILES'][
$this->profileId][
'DESCRIPTION'];
68 if(!empty($this->parentHandlerInitParams[
"PROFILES"][$this->profileId][
"TRACKING_CLASS_NAME"]))
69 $this->trackingClass = $this->parentHandlerInitParams[
"PROFILES"][
$this->profileId][
"TRACKING_CLASS_NAME"];
76 if($this->name ==
'') $this->name = $this->parentAutomatic->getName();
77 if(intval($this->logotip) <= 0) $this->logotip = $this->parentAutomatic->getLogotip();
78 if($this->description ==
'') $this->description = $this->parentAutomatic->getDescription();
79 if($this->trackingClass ==
'') $this->trackingClass = $this->parentAutomatic->getTrackingClass();
81 $parentTP = $this->parentAutomatic->getTrackingParams();
83 if(is_array($parentTP) && !empty($parentTP))
85 if(empty($this->trackingParams) || !is_array($this->trackingParams))
87 $this->trackingParams = $parentTP;
91 foreach($this->trackingParams as $k => $v)
92 if(empty($v) && !empty($parentTP[$k]))
93 $this->trackingParams[$k] = $parentTP[$k];
106 if($this->profileOldConfig ===
null)
112 "CONFIG" => array_merge(
113 isset($parent[
"CONFIG"]) && is_array($parent[
"CONFIG"]) ? $parent[
"CONFIG"] : array(),
114 isset($own[
"CONFIG"]) && is_array($own[
"CONFIG"]) ? $own[
"CONFIG"] : array()
117 isset($parent[
"CONFIG_GROUPS"]) && is_array($parent[
"CONFIG"])? $parent[
"CONFIG_GROUPS"] : array()
120 if(isset($own[
"CONFIG"]) && is_array($own[
"CONFIG"]))
121 foreach($own[
"CONFIG"] as $k => $v)
128 if($actualizeProfiles && !$this->profileOldConfigActualized)
130 $this->profileOldConfig = $this->actualizeProfilesConfig($this->profileOldConfig);
131 $this->profileOldConfigActualized =
true;
186 if($this->profileConfig ===
null)
191 foreach($configStructure as $key => $configSection)
192 $profileConfig[$key] = $this->glueValuesToConfig($configSection, isset($this->config[$key]) ? $this->config[$key] : array());
194 if($this->profileId <>
'')
199 foreach($newConfig as $groupId => $groupParams)
200 if($groupId != $this->profileId)
201 unset($newConfig[$groupId]);
245 static $profiles =
null;
247 if($profiles ===
null)
249 $profiles = array(
"" =>
"");
251 foreach($this->parentHandlerInitParams[
"PROFILES"] as
$profileId => $profileParams)
252 if($profileParams[
"TITLE"] <>
'')
259 "DESCRIPTION" =>
Loc::getMessage(
"SALE_DLVR_HANDL_AUTP_CONF_MAIN_DESCR"),
261 "PROFILE_ID" => array(
263 "NAME" =>
"PROFILE_ID",
265 "DEFAULT" => $this->profileId
267 "PROFILE_NAME" => array(
269 "NAME" =>
Loc::getMessage(
"SALE_DLVR_HANDL_AUTP_CONF_MAIN_PROFILE_ID"),
270 "DEFAULT" => $profiles[$this->profileId] ??
'',
277 $serviceCurrency = $this->currency;
279 if(\
Bitrix\Main\Loader::includeModule(
'currency'))
281 $currencyList = CurrencyManager::getCurrencyList();
283 if (isset($currencyList[$this->currency]))
284 $serviceCurrency = $currencyList[$this->currency];
286 unset($currencyList);
289 $marginTypes = array(
291 "CURRENCY" => $serviceCurrency
294 $result[
"MAIN"][
"ITEMS"][
"MARGIN_VALUE"] = array(
300 $result[
"MAIN"][
"ITEMS"][
"MARGIN_TYPE"] = array(
304 "OPTIONS" => $marginTypes
307 $configProfileIds = array_keys($this->parentHandlerInitParams[
"PROFILES"]);
309 if($this->profileId <>
'' && in_array($this->profileId, $configProfileIds))
311 $oldAutoConfig = $this->parentAutomatic->getOldConfig();
313 if($oldAutoConfig && isset($oldAutoConfig[
"CONFIG_GROUPS"]) && is_array($oldAutoConfig[
"CONFIG_GROUPS"]))
315 foreach($oldAutoConfig[
"CONFIG_GROUPS"] as $key => $groupId)
316 if($this->profileId != $groupId)
317 unset($oldAutoConfig[
"CONFIG_GROUPS"][$key]);
319 foreach($oldAutoConfig[
"CONFIG"] as $key => $params)
321 if (!isset($params[
"CONFIG"]))
323 unset($oldAutoConfig[
"CONFIG"][$key]);
325 elseif ($this->profileId != $params[
"CONFIG"])
327 unset($oldAutoConfig[
"CONFIG"][$key]);
336 if(isset(
$oldConfig[
"CONFIG_GROUPS"][
"MAIN"]))
351 $parentAutoConfig = $this->parentAutomatic->getConfigValues();
353 if(isset($fields[
"CONFIG"]) && is_array($fields[
"CONFIG"]))
354 $fields[
"CONFIG"] = array_merge($parentAutoConfig, $fields[
"CONFIG"]);
356 $configMain = $fields[
"CONFIG"][
"MAIN"];
359 if (isset($handler[
"DBSETSETTINGS"]) && is_callable($handler[
"DBSETSETTINGS"]))
361 $oldSettings = $fields[
"CONFIG"];
362 unset($oldSettings[
"MAIN"]);
364 if(is_array($oldSettings))
367 if (!$strOldSettings = call_user_func($handler[
"DBSETSETTINGS"], $oldSettings))
368 throw new SystemException(
"Can't save delivery services's old settings");
372 $strOldSettings =
"";
375 $strOldSettings = serialize($strOldSettings);
377 $fields[
"CONFIG"] = array(
378 "MAIN" => $configMain
381 $fields[
"CONFIG"][
"MAIN"][
"OLD_SETTINGS"] = $strOldSettings;
382 $fields = parent::prepareFieldsForSaving($fields);
385 if(!empty($fields[
'TRACKING_PARAMS']) && is_array($fields[
'TRACKING_PARAMS']))
387 $parentTP = $this->parentAutomatic->getTrackingParams();
389 foreach($fields[
'TRACKING_PARAMS'] as $k => $v)
391 if (!empty($parentTP[$k]) && $v == $parentTP[$k])
393 $fields[
'TRACKING_PARAMS'][$k] =
'';