1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
profile.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\Delivery;
4
5use Bitrix\Main;
6use Bitrix\Main\ArgumentNullException;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Sale;
9use Bitrix\Sale\Delivery\CalculationResult;
10use Bitrix\Sale\Delivery\Services\Base;
11use Bitrix\Sale\Delivery\Services\Manager;
12use Sale\Handlers\Delivery\Rest\DataProviders;
13use Sale\Handlers\Delivery\Rest\RequestHandler;
14
15Loc::loadMessages(__FILE__);
16
21class RestProfile extends Base
22{
23 private const HANDLER_CODE_PREFIX = 'BITRIX_REST_';
24
26 protected $restHandler;
27
29 protected $profileType = '';
30
32 protected static $whetherAdminExtraServicesShow = true;
33
35 protected static $isProfile = true;
36
42 public function __construct(array $initParams)
43 {
44 if (empty($initParams['PARENT_ID']))
45 {
46 throw new ArgumentNullException('initParams[PARENT_ID]');
47 }
48
49 parent::__construct($initParams);
50 $this->restHandler = Manager::getObjectById($this->parentId);
51
52 if (!($this->restHandler instanceof RestHandler))
53 {
54 throw new ArgumentNullException('this->restHandler is not instance of RestHandler');
55 }
56
57 if (!empty($initParams['PROFILE_ID']))
58 {
59 $this->profileType = $initParams['PROFILE_ID'];
60 }
61 elseif (!empty($this->config['MAIN']['PROFILE_TYPE']))
62 {
63 $this->profileType = $this->config['MAIN']['PROFILE_TYPE'];
64 }
65
66 if ($this->profileType)
67 {
68 $profileParams = $this->getProfileParams();
69 if (!empty($profileParams) && $this->id <= 0)
70 {
71 $this->name = $profileParams['NAME'];
72 $this->description = $profileParams['DESCRIPTION'];
73 }
74 }
75 }
76
80 public static function getClassTitle(): string
81 {
82 return Loc::getMessage('SALE_DELIVERY_REST_PROFILE_NAME');
83 }
84
88 public static function getClassDescription(): string
89 {
90 return Loc::getMessage('SALE_DELIVERY_REST_PROFILE_DESCRIPTION');
91 }
92
97 protected function calculateConcrete(Sale\Shipment $shipment): CalculationResult
98 {
99 $result = new CalculationResult;
100
101 $handlerParams = $this->getHandlerParams();
102 if (
103 !isset($handlerParams['SETTINGS']['CALCULATE_URL'])
104 || !is_string($handlerParams['SETTINGS']['CALCULATE_URL'])
105 || empty($handlerParams['SETTINGS']['CALCULATE_URL'])
106 )
107 {
108 return $result->addError(new Main\Error('Calculate URL is not specified'));
109 }
110
111 $sendRequestResult = Sale\Helpers\Rest\Http::sendRequest(
112 $handlerParams['SETTINGS']['CALCULATE_URL'],
113 [
114 'SHIPMENT' => DataProviders\Shipment::getData($shipment),
115 ],
116 [
117 'JSON_REQUEST' => true,
118 ]
119 );
120 if ($sendRequestResult->isSuccess())
121 {
122 $calculatedData = $sendRequestResult->getData();
123
124 if (!(isset($calculatedData['SUCCESS']) && $calculatedData['SUCCESS'] === 'Y'))
125 {
126 $errorText = (
127 isset($calculatedData['REASON']['TEXT'])
128 && is_string($calculatedData['REASON']['TEXT'])
129 && !empty($calculatedData['REASON']['TEXT'])
130 )
131 ? $calculatedData['REASON']['TEXT']
132 : Loc::getMessage('SALE_DELIVERY_REST_PROFILE_PRICE_CALCULATION_ERROR');
133
134 $result->addError(new Main\Error($errorText, 'DELIVERY_CALCULATION'));
135 }
136
137 if (!empty($calculatedData['PRICE']))
138 {
139 $result->setDeliveryPrice($calculatedData['PRICE']);
140 }
141
142 if (!empty($calculatedData['PERIOD_DESCRIPTION']))
143 {
144 $result->setPeriodDescription($calculatedData['PERIOD_DESCRIPTION']);
145 }
146
147 if (!empty($calculatedData['PERIOD_FROM']))
148 {
149 $result->setPeriodFrom($calculatedData['PERIOD_FROM']);
150 }
151
152 if (!empty($calculatedData['PERIOD_TO']))
153 {
154 $result->setPeriodTo($calculatedData['PERIOD_TO']);
155 }
156
157 if (!empty($calculatedData['PERIOD_TYPE']))
158 {
159 $result->setPeriodType($calculatedData['PERIOD_TYPE']);
160 }
161
162 if (!empty($calculatedData['DESCRIPTION']))
163 {
164 $result->setDescription($calculatedData['DESCRIPTION']);
165 }
166 }
167
168 return $result;
169 }
170
174 protected function getProfileType(): string
175 {
176 return (string)$this->profileType;
177 }
178
182 private function getProfileParams()
183 {
184 $handlerParams = $this->getHandlerParams();
185 $type = $this->getProfileType();
186
187 return $handlerParams['PROFILES'][$type];
188 }
189
193 private function getHandlerParams()
194 {
195 $handlerList = Manager::getRestHandlerList();
196 $code = str_replace(self::HANDLER_CODE_PREFIX, '', $this->restHandler->getHandlerCode());
197
198 return $handlerList[$code];
199 }
200
204 protected function getConfigStructure(): array
205 {
206 $result = [];
207
208 $configParams = $this->getProfileParams();
209
210 if (!empty($configParams['CONFIG']))
211 {
212 $result['MAIN'] = [
213 'TITLE' => $configParams['CONFIG']['TITLE'],
214 'DESCRIPTION' => $configParams['CONFIG']['DESCRIPTION'],
215 'ITEMS' => $configParams['CONFIG']['ITEMS'],
216 ];
217 }
218 else
219 {
220 $result['MAIN'] = [
221 'TITLE' => Loc::getMessage('SALE_DELIVERY_REST_PROFILE_SETTING_TITLE'),
222 'DESCRIPTION' => Loc::getMessage('SALE_DELIVERY_REST_PROFILE_SETTING_DESCRIPTION'),
223 ];
224 }
225
226 $result['MAIN']['ITEMS']['PROFILE_TYPE'] = [
227 'TYPE' => 'STRING',
228 'NAME' => 'PROFILE_TYPE',
229 'HIDDEN' => true,
230 'DEFAULT' => $this->getProfileType(),
231 ];
232
233 return $result;
234 }
235
236 public function getParentService()
237 {
238 return $this->restHandler;
239 }
240
244 public static function isProfile(): bool
245 {
246 return self::$isProfile;
247 }
248
252 public static function whetherAdminExtraServicesShow(): bool
253 {
254 return self::$whetherAdminExtraServicesShow;
255 }
256
260 public function getDeliveryRequestHandler()
261 {
262 $handlerParams = $this->getHandlerParams();
263
264 if (
265 !isset($handlerParams['SETTINGS']['CREATE_DELIVERY_REQUEST_URL'])
266 || !is_string($handlerParams['SETTINGS']['CREATE_DELIVERY_REQUEST_URL'])
267 || empty($handlerParams['SETTINGS']['CREATE_DELIVERY_REQUEST_URL'])
268 )
269 {
270 return null;
271 }
272
273 $handler = (new RequestHandler($this))
274 ->setCreateRequestUrl($handlerParams['SETTINGS']['CREATE_DELIVERY_REQUEST_URL']);
275
276 if (
277 isset($handlerParams['SETTINGS']['CANCEL_DELIVERY_REQUEST_URL'])
278 && is_string($handlerParams['SETTINGS']['CANCEL_DELIVERY_REQUEST_URL'])
279 && !empty($handlerParams['SETTINGS']['CANCEL_DELIVERY_REQUEST_URL'])
280 )
281 {
282 $handler->setCancelRequestUrl($handlerParams['SETTINGS']['CANCEL_DELIVERY_REQUEST_URL']);
283 }
284
285 if (
286 isset($handlerParams['SETTINGS']['CANCEL_ACTION_NAME'])
287 && is_string($handlerParams['SETTINGS']['CANCEL_ACTION_NAME'])
288 && !empty($handlerParams['SETTINGS']['CANCEL_ACTION_NAME'])
289 )
290 {
291 $handler->setCancelActionName($handlerParams['SETTINGS']['CANCEL_ACTION_NAME']);
292 }
293
294 if (
295 isset($handlerParams['SETTINGS']['DELETE_DELIVERY_REQUEST_URL'])
296 && is_string($handlerParams['SETTINGS']['DELETE_DELIVERY_REQUEST_URL'])
297 && !empty($handlerParams['SETTINGS']['DELETE_DELIVERY_REQUEST_URL'])
298 )
299 {
300 $handler->setDeleteRequestUrl($handlerParams['SETTINGS']['DELETE_DELIVERY_REQUEST_URL']);
301 }
302
303 if (
304 isset($handlerParams['SETTINGS']['HAS_CALLBACK_TRACKING_SUPPORT'])
305 && $handlerParams['SETTINGS']['HAS_CALLBACK_TRACKING_SUPPORT'] === 'Y'
306 )
307 {
308 $handler->setHasCallbackTrackingSupport(true);
309 }
310
311 return $handler;
312 }
313}
$type
Определения options.php:106
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
trait Error
Определения error.php:11
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393