1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
profile.php
См. документацию.
1<?
2namespace Sale\Handlers\Delivery;
3
4use Bitrix\Main\Error;
5use Bitrix\Main\Loader;
6use Bitrix\Main\SystemException;
7use Bitrix\Sale\Delivery\Requests\Result;
8use Bitrix\Sale\Order;
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;
17
18Loc::loadMessages(__FILE__);
19
20class AdditionalProfile extends \Bitrix\Sale\Delivery\Services\Base
21{
23 protected $additionalHandler = null;
25 protected $profileType = "";
26 protected $trackingTitle = "";
27 protected $trackingDescription = "";
28
29 protected static $whetherAdminExtraServicesShow = true;
31 protected static $isProfile = true;
32
38 public function __construct(array $initParams)
39 {
40 if(empty($initParams["PARENT_ID"]))
41 throw new ArgumentNullException('initParams[PARENT_ID]');
42
43 parent::__construct($initParams);
44 $this->additionalHandler = Manager::getObjectById($this->parentId);
45
46 if(!($this->additionalHandler instanceof AdditionalHandler))
47 throw new ArgumentNullException('this->additionalHandler is not instance of AdditionalHandler');
48
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'];
53
54 if($this->profileType <> '')
55 {
56 $profileParams = $this->getProfileParams();
57
58 if(!empty($profileParams) && $this->id <= 0)
59 {
60 $this->name = $profileParams['NAME'];
61 $this->description = $profileParams['DESCRIPTION'];
62
63 if(!empty($profileParams['LOGOTIP']))
64 $this->logotip = $profileParams['LOGOTIP'];
65 }
66
67 if($this->isRusPost())
68 {
69 if(empty($this->config['MAIN']['IS_OTPRAVKA_SUPPORTED']))
70 {
71 if(isset($profileParams['IS_OTPRAVKA_SUPPORTED']) && $profileParams['IS_OTPRAVKA_SUPPORTED'] == 'Y')
72 {
73 $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED'] = 'Y';
74 }
75 else
76 {
77 $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED'] = 'N';
78 }
79 }
80 }
81 }
82
83 $this->inheritParams();
84 }
85
89 protected function getProfileType(): string
90 {
91 return (string)$this->profileType;
92 }
93
94 protected function isRusPost()
95 {
96 $parentConfig = $this->additionalHandler->getConfigValues();
97 return $parentConfig['MAIN']['SERVICE_TYPE'] == "RUSPOST";
98 }
99
103 protected function getProfileParams()
104 {
105 $result = array();
106 $list = $this->additionalHandler->getProfilesListFull();
107
108 if(!empty($list[$this->profileType]))
109 $result = $list[$this->profileType];
110
111 return $result;
112 }
113
117 public static function getClassTitle()
118 {
119 return Loc::getMessage("SALE_DLVRS_ADDP_NAME");
120 }
121
125 public static function getClassDescription()
126 {
127 return Loc::getMessage("SALE_DLVRS_ADDP_DESCRIPTION");
128 }
129
135 protected function inheritParams()
136 {
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();
140
141 $this->trackingParams = $this->additionalHandler->getTrackingParams();
142 $this->trackingClass = $this->additionalHandler->getTrackingClass();
143 $this->trackingTitle = $this->additionalHandler->getTrackingClassTitle();
144 $this->trackingDescription = $this->additionalHandler->getTrackingClassDescription();
145
146 if(!$this->isRusPost() || $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED'] == 'Y')
147 {
148 $this->deliveryRequestHandler = $this->additionalHandler->getDeliveryRequestHandler();
149 }
150
151 $parentES = \Bitrix\Sale\Delivery\ExtraServices\Manager::getExtraServicesList($this->parentId);
152
153 if(!empty($parentES))
154 {
155 foreach($parentES as $esFields)
156 {
157 if(
158 ($esFields['CODE'] <> '' && !$this->extraServices->getItemByCode($esFields['CODE']))
159 || $esFields['CODE'] == ''
160 )
161 {
162 $this->extraServices->addItem($esFields, $this->currency);
163 }
164 }
165 }
166 }
167
175 protected function calculateConcrete(Shipment $shipment)
176 {
177 $client = new \Sale\Handlers\Delivery\Additional\RestClient();
178
179 try
180 {
181 $result = $client->getDeliveryPrice(
182 $this->additionalHandler->getServiceType(),
183 $this->profileType,
184 self::extractConfigValues($this->additionalHandler->getConfig()),
185 self::extractConfigValues($this->getConfig()),
186 $shipment
187 );
188 }
189 catch(SystemException $e)
190 {
191 $result = new CalculationResult();
192 $result->addError(new Error($e->getMessage()));
193 }
194
196 $shipmentCollection = $shipment->getCollection();
198 $order = $shipmentCollection->getOrder();
199 $shipmentCurrency = $order->getCurrency();
200
201 if ($result->isSuccess() && $this->currency != $shipmentCurrency)
202 {
203 if(!Loader::includeModule('currency'))
204 throw new SystemException("Can't include module \"Currency\"");
205
206 $result->setDeliveryPrice(
207 \CCurrencyRates::convertCurrency(
208 $result->getPrice(),
209 $this->currency,
210 $shipmentCurrency
211 ));
212 }
213
214 return $result;
215 }
216
217
222 public static function extractConfigValues(array $config)
223 {
224 if(!is_array($config) || empty($config))
225 return array();
226
227 $result = array();
228
229 foreach($config as $sectionKey => $sectionConfig)
230 {
231 if(isset($sectionConfig["ITEMS"]) && is_array($sectionConfig["ITEMS"]) && !empty($sectionConfig["ITEMS"]))
232 {
233 $result[$sectionKey] = array();
234
235 foreach($sectionConfig["ITEMS"] as $name => $params)
236 {
237 $value = "";
238
239 if(isset($params['VALUE']))
240 $value = $params['VALUE'];
241 elseif(isset($params['DEFAULT']))
242 $value = $params['DEFAULT'];
243
244 $result[$sectionKey][$name] = $value;
245 }
246 }
247 }
248
249 return $result;
250 }
251
252
256 public function isCalculatePriceImmediately()
257 {
258 return $this->additionalHandler->isCalculatePriceImmediately();
259 }
260
264 protected function getConfigStructure()
265 {
266 $client = new \Sale\Handlers\Delivery\Additional\RestClient();
267
268 $res = $client->getProfileConfig(
269 $this->additionalHandler->getServiceType(),
270 $this->profileType
271 );
272
273 if(!$res->isSuccess())
274 array();
275
276 return $res->getData();
277 }
278
282 public function getParentService()
283 {
284 return $this->additionalHandler;
285 }
286
291 public function isCompatible(Shipment $shipment)
292 {
293 return array_key_exists(
294 $this->profileType,
295 $this->additionalHandler->getCompatibleProfiles($shipment)
296 );
297 }
298
302 public static function install()
303 {
304 AdditionalHandler::install();
305 }
306
310 public static function unInstall()
311 {
312 AdditionalHandler::unInstall();
313 }
314
318 public static function isInstalled()
319 {
320 AdditionalHandler::isInstalled();
321 }
322
326 public static function isProfile()
327 {
328 return self::$isProfile;
329 }
330
334 public static function whetherAdminExtraServicesShow()
335 {
336 return self::$whetherAdminExtraServicesShow;
337 }
338
342 public function getEmbeddedExtraServicesList()
343 {
344 static $result = null;
345
346 if($result === null)
347 {
348 $result = array();
349 $client = new RestClient();
350 $res = $client->getProfileExtraServices(
351 $this->additionalHandler->getServiceType(),
352 $this->profileType,
353 self::extractConfigValues($this->getConfig())
354 );
355
356 if($res->isSuccess())
357 $result = $res->getData();
358 }
359
360 return $result;
361 }
362
363 public function getTrackingClassTitle()
364 {
365 return !empty($this->config['MAIN']['TRACKING_TITLE']) ? $this->config['MAIN']['TRACKING_TITLE'] : '';
366 }
367
368 public function getTrackingClassDescription()
369 {
370 return !empty($this->config['MAIN']['TRACKING_DESCRIPTION']) ? $this->config['MAIN']['TRACKING_DESCRIPTION'] : '';
371 }
372
376 public function isTrackingInherited()
377 {
378 return true;
379 }
380
381 public function execAdminAction()
382 {
383 $result = new \Bitrix\Sale\Result();
384
385 if($this->isRusPost() && !empty($this->config['MAIN']['OTPRAVKA_RPO']))
386 {
387 $parentConfig = $this->getParentService()->getConfigValues();
388
389 if(empty($parentConfig['MAIN']['SHIPPING_POINT']['VALUE']))
390 {
391 return $result;
392 }
393
394 $selectedShippingPoint = $parentConfig['MAIN']['SHIPPING_POINT']['VALUE'];
395 $shippingPoints = Helper::getEnabledShippingPointsList($this->id);
396
397 if(isset($shippingPoints[$selectedShippingPoint]))
398 {
399 if(in_array($this->config['MAIN']['OTPRAVKA_RPO'], $shippingPoints[$selectedShippingPoint]['available-mail-types']))
400 {
401 $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED'] = 'Y';
402 $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED_LABEL'] = Loc::getMessage('SALE_DLVRS_ADDP_Y');
403 }
404 else
405 {
406 $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED'] = 'N';
407 $this->config['MAIN']['IS_OTPRAVKA_SUPPORTED_LABEL'] = Loc::getMessage('SALE_DLVRS_ADDP_N');
408 }
409 }
410 }
411
412 return $result;
413 }
414}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$name
Определения menu_edit.php:35
$value
Определения Param.php:39
if(!function_exists(__NAMESPACE__.'\\___972068685'))
Определения license.php:1
trait Error
Определения error.php:11
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$config
Определения quickway.php:69
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799