2namespace Sale\Handlers\Delivery;
6use Bitrix\Main\SystemException;
7use Bitrix\Sale\Delivery\Requests\Result;
9use Bitrix\Sale\Shipment;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Main\ArgumentNullException;
12use Bitrix\Sale\Delivery\Services\Manager;
13use Bitrix\Sale\Delivery\CalculationResult;
14use Bitrix\Sale\ShipmentCollection;
15use Sale\Handlers\Delivery\Additional\RestClient;
16use Sale\Handlers\Delivery\Additional\RusPost\Helper;
18Loc::loadMessages(__FILE__);
20class AdditionalProfile
extends \Bitrix\Sale\Delivery\Services\Base
23 protected $additionalHandler =
null;
25 protected $profileType =
"";
26 protected $trackingTitle =
"";
27 protected $trackingDescription =
"";
29 protected static $whetherAdminExtraServicesShow =
true;
31 protected static $isProfile =
true;
38 public function __construct(
array $initParams)
40 if(empty($initParams[
"PARENT_ID"]))
41 throw new ArgumentNullException(
'initParams[PARENT_ID]');
43 parent::__construct($initParams);
44 $this->additionalHandler = Manager::getObjectById($this->parentId);
46 if(!($this->additionalHandler instanceof AdditionalHandler))
47 throw new ArgumentNullException(
'this->additionalHandler is not instance of AdditionalHandler');
49 if(isset($initParams[
'PROFILE_ID']) && $initParams[
'PROFILE_ID'] <>
'')
50 $this->profileType = $initParams[
'PROFILE_ID'];
51 elseif(isset($this->config[
'MAIN'][
'PROFILE_TYPE']) && $this->config[
'MAIN'][
'PROFILE_TYPE'] <>
'')
52 $this->profileType = $this->config['MAIN']['PROFILE_TYPE'];
54 if($this->profileType <> '')
56 $profileParams = $this->getProfileParams();
58 if(!empty($profileParams) && $this->
id <= 0)
60 $this->name = $profileParams[
'NAME'];
61 $this->description = $profileParams[
'DESCRIPTION'];
63 if(!empty($profileParams[
'LOGOTIP']))
64 $this->logotip = $profileParams[
'LOGOTIP'];
67 if($this->isRusPost())
69 if(empty($this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED']))
71 if(isset($profileParams[
'IS_OTPRAVKA_SUPPORTED']) && $profileParams[
'IS_OTPRAVKA_SUPPORTED'] ==
'Y')
73 $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED'] =
'Y';
77 $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED'] =
'N';
83 $this->inheritParams();
89 protected function getProfileType(): string
91 return (
string)$this->profileType;
94 protected function isRusPost()
96 $parentConfig = $this->additionalHandler->getConfigValues();
97 return $parentConfig[
'MAIN'][
'SERVICE_TYPE'] ==
"RUSPOST";
103 protected function getProfileParams()
106 $list = $this->additionalHandler->getProfilesListFull();
108 if(!empty($list[$this->profileType]))
109 $result = $list[$this->profileType];
117 public static function getClassTitle()
119 return Loc::getMessage(
"SALE_DLVRS_ADDP_NAME");
125 public static function getClassDescription()
127 return Loc::getMessage(
"SALE_DLVRS_ADDP_DESCRIPTION");
135 protected function inheritParams()
137 if($this->name ==
'') $this->name = $this->additionalHandler->getName();
138 if(intval($this->logotip) <= 0) $this->logotip = $this->additionalHandler->getLogotip();
139 if($this->description ==
'') $this->description = $this->additionalHandler->getDescription();
141 $this->trackingParams = $this->additionalHandler->getTrackingParams();
142 $this->trackingClass = $this->additionalHandler->getTrackingClass();
143 $this->trackingTitle = $this->additionalHandler->getTrackingClassTitle();
144 $this->trackingDescription = $this->additionalHandler->getTrackingClassDescription();
146 if(!$this->isRusPost() || $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED'] ==
'Y')
148 $this->deliveryRequestHandler = $this->additionalHandler->getDeliveryRequestHandler();
151 $parentES = \Bitrix\Sale\Delivery\ExtraServices\Manager::getExtraServicesList($this->parentId);
153 if(!empty($parentES))
155 foreach($parentES as $esFields)
158 ($esFields[
'CODE'] <>
'' && !$this->extraServices->getItemByCode($esFields[
'CODE']))
159 || $esFields[
'CODE'] ==
''
162 $this->extraServices->addItem($esFields, $this->currency);
175 protected function calculateConcrete(Shipment $shipment)
177 $client = new \Sale\Handlers\Delivery\Additional\RestClient();
181 $result = $client->getDeliveryPrice(
182 $this->additionalHandler->getServiceType(),
184 self::extractConfigValues($this->additionalHandler->getConfig()),
185 self::extractConfigValues($this->getConfig()),
189 catch(SystemException $e)
191 $result =
new CalculationResult();
196 $shipmentCollection = $shipment->getCollection();
198 $order = $shipmentCollection->getOrder();
199 $shipmentCurrency =
$order->getCurrency();
201 if (
$result->isSuccess() && $this->currency != $shipmentCurrency)
203 if(!Loader::includeModule(
'currency'))
204 throw new SystemException(
"Can't include module \"Currency\"");
207 \CCurrencyRates::convertCurrency(
222 public static function extractConfigValues(
array $config)
229 foreach(
$config as $sectionKey => $sectionConfig)
231 if(isset($sectionConfig[
"ITEMS"]) && is_array($sectionConfig[
"ITEMS"]) && !empty($sectionConfig[
"ITEMS"]))
256 public function isCalculatePriceImmediately()
258 return $this->additionalHandler->isCalculatePriceImmediately();
264 protected function getConfigStructure()
266 $client = new \Sale\Handlers\Delivery\Additional\RestClient();
268 $res = $client->getProfileConfig(
269 $this->additionalHandler->getServiceType(),
273 if(!
$res->isSuccess())
276 return $res->getData();
282 public function getParentService()
284 return $this->additionalHandler;
291 public function isCompatible(Shipment $shipment)
293 return array_key_exists(
295 $this->additionalHandler->getCompatibleProfiles($shipment)
302 public static function install()
304 AdditionalHandler::install();
310 public static function unInstall()
312 AdditionalHandler::unInstall();
318 public static function isInstalled()
320 AdditionalHandler::isInstalled();
326 public static function isProfile()
328 return self::$isProfile;
334 public static function whetherAdminExtraServicesShow()
336 return self::$whetherAdminExtraServicesShow;
342 public function getEmbeddedExtraServicesList()
349 $client =
new RestClient();
350 $res = $client->getProfileExtraServices(
351 $this->additionalHandler->getServiceType(),
353 self::extractConfigValues($this->getConfig())
356 if(
$res->isSuccess())
363 public function getTrackingClassTitle()
365 return !empty($this->config[
'MAIN'][
'TRACKING_TITLE']) ? $this->config[
'MAIN'][
'TRACKING_TITLE'] :
'';
368 public function getTrackingClassDescription()
370 return !empty($this->config[
'MAIN'][
'TRACKING_DESCRIPTION']) ? $this->config[
'MAIN'][
'TRACKING_DESCRIPTION'] :
'';
376 public function isTrackingInherited()
381 public function execAdminAction()
383 $result = new \Bitrix\Sale\Result();
385 if($this->isRusPost() && !empty($this->config[
'MAIN'][
'OTPRAVKA_RPO']))
387 $parentConfig = $this->getParentService()->getConfigValues();
389 if(empty($parentConfig[
'MAIN'][
'SHIPPING_POINT'][
'VALUE']))
394 $selectedShippingPoint = $parentConfig[
'MAIN'][
'SHIPPING_POINT'][
'VALUE'];
395 $shippingPoints = Helper::getEnabledShippingPointsList($this->
id);
397 if(isset($shippingPoints[$selectedShippingPoint]))
399 if(in_array($this->config[
'MAIN'][
'OTPRAVKA_RPO'], $shippingPoints[$selectedShippingPoint][
'available-mail-types']))
401 $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED'] =
'Y';
402 $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED_LABEL'] = Loc::getMessage(
'SALE_DLVRS_ADDP_Y');
406 $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED'] =
'N';
407 $this->config[
'MAIN'][
'IS_OTPRAVKA_SUPPORTED_LABEL'] = Loc::getMessage(
'SALE_DLVRS_ADDP_N');
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!function_exists(__NAMESPACE__.'\\___972068685'))
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']