3namespace Bitrix\Sale\Delivery\Services;
5use Bitrix\Currency\CurrencyManager;
6use Bitrix\Main\SystemException;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\ArgumentNullException;
9use Bitrix\Sale\Shipment;
11Loc::loadMessages(__FILE__);
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)
122 if(empty($v[
"GROUP"]) || $v[
"GROUP"] != $this->profileId)
128 if($actualizeProfiles && !$this->profileOldConfigActualized)
130 $this->profileOldConfig = $this->actualizeProfilesConfig($this->profileOldConfig);
131 $this->profileOldConfigActualized =
true;
144 $actualizedCodes =
array();
146 foreach($profiles as $id =>
$fields)
153 if(
$fields[
'CODE'] == $this->code)
156 if(in_array(
$fields[
'CODE'], $actualizedCodes))
166 $serviceProfileId =
$config[
'MAIN'][
'ITEMS'][
'PROFILE_ID'][
'VALUE'];
168 if($serviceProfileId == $this->profileId)
174 if(isset($v[
'GROUP']) && $v[
'GROUP'] == $serviceProfileId)
177 $actualizedCodes[] =
$fields[
'CODE'];
186 if($this->profileConfig ===
null)
191 foreach($configStructure as
$key => $configSection)
194 if($this->profileId <>
'')
199 foreach($newConfig as $groupId => $groupParams)
200 if($groupId != $this->profileId)
201 unset($newConfig[$groupId]);
214 return Loc::getMessage(
"SALE_DLVR_HANDL_AUTP_NAME");
219 return Loc::getMessage(
"SALE_DLVR_HANDL_AUTP_DESCRIPTION");
224 $result = $this->parentAutomatic->calculateProfile($this->profileId, $this->
getOldConfig(
true), $shipment);
235 if($this->config[
"MAIN"][
"MARGIN_TYPE"] ==
"%")
236 $marginPrice = $price * floatval($this->config[
"MAIN"][
"MARGIN_VALUE"]) / 100;
238 $marginPrice = floatval($this->config[
"MAIN"][
"MARGIN_VALUE"]);
245 static $profiles =
null;
247 if($profiles ===
null)
249 $profiles =
array(
"" =>
"");
251 foreach($this->parentHandlerInitParams[
"PROFILES"] as
$profileId => $profileParams)
252 if($profileParams[
"TITLE"] <>
'')
258 "TITLE" => Loc::getMessage(
"SALE_DLVR_HANDL_AUTP_CONF_MAIN_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] ??
'',
279 if(\
Bitrix\
Main\Loader::includeModule(
'currency'))
281 $currencyList = CurrencyManager::getCurrencyList();
283 if (isset($currencyList[$this->currency]))
286 unset($currencyList);
289 $marginTypes =
array(
291 "CURRENCY" => $serviceCurrency
296 "NAME" => Loc::getMessage(
"SALE_DLVR_HANDL_AUT_MARGIN_VALUE"),
302 "NAME" => Loc::getMessage(
"SALE_DLVR_HANDL_AUT_MARGIN_TYPE"),
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)
323 unset($oldAutoConfig[
"CONFIG"][
$key]);
327 unset($oldAutoConfig[
"CONFIG"][
$key]);
336 if(isset(
$oldConfig[
"CONFIG_GROUPS"][
"MAIN"]))
351 $parentAutoConfig = $this->parentAutomatic->getConfigValues();
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);
378 "MAIN" => $configMain
381 $fields[
"CONFIG"][
"MAIN"][
"OLD_SETTINGS"] = $strOldSettings;
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])
408 return $this->parentAutomatic->isProfileCompatible($this->profileId, $this->
getOldConfig(
true), $shipment);
413 return self::$isProfile;
426 return $this->parentAutomatic->getAdditionalInfoShipmentEdit($shipment);
431 return $this->parentAutomatic->processAdditionalInfoShipmentEdit($shipment, $requestData);
436 return $this->parentAutomatic->getAdditionalInfoShipmentView($shipment);
static convertNewSettingsToOld(array $newSettings=array())
static convertOldConfigToNew($oldConfig)
static createConfig($initHandlerParams, $settings, $siteId=false)
getOldConfig($actualizeProfiles=false)
$profileOldConfigActualized
isCompatible(Shipment $shipment)
static getClassDescription()
__construct(array $initParams)
prepareFieldsForSaving(array $fields)
calculateConcrete(\Bitrix\Sale\Shipment $shipment)
getAdditionalInfoShipmentEdit(Shipment $shipment)
processAdditionalInfoShipmentEdit(Shipment $shipment, array $requestData)
getAdditionalInfoShipmentView(Shipment $shipment)
static getObjectById($deliveryId)
static getByParentId($parentId)
static getPooledObject(array $fields)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']