1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?
2namespace Sale\Handlers\Delivery\Additional\DeliveryRequests\RusPost;
3
4use Bitrix\Main\Application;
5use Bitrix\Main\Error;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Web\HttpClient;
8use Bitrix\Sale\Shipment;
9use Bitrix\Main\Type\Date;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Sale\Delivery\Requests;
12use Bitrix\Sale\Delivery\Services;
13use Sale\Handlers\Delivery\Additional\DeliveryRequests\RusPost\Requests\Base as RequestBase;
14
15Loc::loadMessages(__FILE__);
16
17class Handler extends Requests\HandlerBase
18{
20 protected $httpClient = null;
21
26 public function __construct(Services\Base $deliveryService)
27 {
28 parent::__construct($deliveryService);
29 self::registerLocalClasses();
30 }
31
35 protected function getHttpClient()
36 {
37 if($this->httpClient === null)
38 {
39 $this->httpClient = new HttpClient(array(
40 "version" => "1.1",
41 "socketTimeout" => 30,
42 "streamTimeout" => 30,
43 "redirect" => true,
44 "redirectMax" => 5,
45 ));
46 }
47
48 return $this->httpClient;
49 }
50
54 public function setHttpClient(HttpClient $httpClient): void
55 {
56 $this->httpClient = $httpClient;
57 }
58
63 protected static function registerLocalClasses()
64 {
65 static $registered = false;
66
67 if($registered)
68 return;
69
70 $path = 'handlers/delivery/additional/deliveryrequests/ruspost/requests/';
71 $namespace = __NAMESPACE__.'\Requests\\';
72 $requestClasses = array(
73 'Base', 'BaseFile', 'OrderCreate', 'OrderDelete', 'CleanAddress', 'NormalizeFio', 'BatchCreate',
74 'OrderDocF7P', 'OrderDocForms', 'BatchOrderAdd', 'BatchesList', 'BatchOrders', 'BatchDocF103',
75 'BatchDocPrepare', 'BatchDateUpdate', 'BatchDocAll', 'Batch', 'BatchOrder', 'OPS', 'OrderDocF112EK',
76 'UserSettings', 'UnreliableRecipient'
77 );
78 $classes = array(
79 __NAMESPACE__.'\Reference' => 'handlers/delivery/additional/deliveryrequests/ruspost/reference.php'
80 );
81
82 foreach($requestClasses as $className)
83 $classes[$namespace.$className] = $path.mb_strtolower($className).'.php';
84
85 Loader::registerAutoLoadClasses('sale', $classes);
86 $registered = true;
87 }
88
93 public function getActions($requestId)
94 {
95 return array(
96 'BATCH_DOC_PREPARE' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_BATCH_DOC_PREPARE'),
97 'BATCH_DOC_ALL' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_BATCH_DOC_ALL'),
98 'BATCH_DOC_F103' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_BATCH_DOC_F103'),
99 'BATCH_DATE_UPDATE' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_BATCH_DATE_UPDATE')
100 );
101 }
102
109 public function executeAction($requestId, $actionType, array $additional)
110 {
111 return $this->getRequestObject($actionType)->process(array($requestId), $additional);
112 }
113
118 public function getShipmentActions(Shipment $shipment)
119 {
120 if(Requests\Manager::isShipmentSent($shipment->getId()))
121 {
122 $result = array(
123 'ORDER_DOC_CREATE' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_ORDER_DOC_CREATE'),
124 'ORDER_DOC_F7P' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_ORDER_DOC_F7P'),
125 );
126
127 $delivery = Services\Manager::getObjectById($shipment->getDeliveryId());
128 $deliveryConfig = $delivery ? $delivery->getConfigValues() : [];
129
130 //cache on delivery
131 if($deliveryConfig['MAIN']['CATEGORY'] == 4)
132 $result['ORDER_DOC_F112EK'] = Loc::getMessage('SALE_DLVRS_ADD_DREQ_ORDER_DOC_F112EK');
133 }
134 else
135 {
136 $result = array();
137 }
138
139 return $result;
140 }
141
149 public function executeShipmentAction($requestId, $shipmentId, $actionType, array $additional)
150 {
151 return $this->getRequestObject($actionType)->process(array($shipmentId), $additional);
152 }
153
159 public function send($requestType, array $requestData)
160 {
161 $result = new Requests\Result();
162 $request = $this->getRequestObject($requestType);
163
164 if(!$request)
165 {
166 $result->addError(
167 new Error(
168 Loc::getMessage('SALE_DLVRS_ADD_DREQ_UNKNOWN_TYPE'),
169 array('#REQUEST_TYPE#' => $requestType)
170 ));
171 return $result;
172 }
173
174 return $request->send($requestData);
175 }
176
183 public function create(array $shipmentIds, array $additional = array())
184 {
185 return $this->getRequestObject('BATCH_CREATE')->process($shipmentIds, $additional);
186 }
187
194 public function addShipments($requestId, $shipmentIds, $additional = [])
195 {
196 $result = new Requests\Result();
197 $request = $this->getRequestObject('BATCH_ORDER_ADD');
198 $requestFields = Requests\RequestTable::getById($requestId)->fetch();
199
200 if(empty($requestFields['EXTERNAL_ID']))
201 {
202 $result->addError(
203 new Error(
204 Loc::getMessage('SALE_DLVRS_ADD_DREQ_UNKNOWN_TYPE'),
205 array('#REQUEST_ID#' => $requestId)
206 ));
207
208 return $result;
209 }
210
211 $result = $request->process(
212 $shipmentIds,
213 array_merge(
214 $additional,
215 array(
216 'BATCH_NAME' => $requestFields['EXTERNAL_ID'],
217 'REQUEST_ID' => $requestFields['ID']
218 )
219 )
220 );
221
222 return $result;
223 }
224
229 public function delete($requestId)
230 {
231 return $this->deleteShipments($requestId);
232 }
233
240 public function getFormFields($formFieldsType, array $entityIds, array $additional = array())
241 {
242 if ($formFieldsType == Requests\Manager::FORM_FIELDS_TYPE_CREATE)
243 {
244 $date = new Date();
245 $date->add('P1D');
246
247 $result = array(
248 "DATE" => array(
249 "TYPE" => "DATE",
250 "TIME" => "N",
251 "TITLE" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SEND_DAY'),
252 "VALUE" => $date->toString(),
253 "REQUIRED" => "Y",
254 )
255 );
256
257 $opsData = $this->getOpsData();
258 if (!is_null($opsData))
259 {
260 $result["OPS"] = $opsData;
261 }
262 }
263 elseif ($formFieldsType == Requests\Manager::FORM_FIELDS_TYPE_ADD)
264 {
265 $result = array();
266
267 $opsData = $this->getOpsData();
268 if (!is_null($opsData))
269 {
270 $result["OPS"] = $opsData;
271 }
272 }
273 elseif($formFieldsType == Requests\Manager::FORM_FIELDS_TYPE_ACTION)
274 {
275 $result = $this->getRequestObject($additional['ACTION_TYPE'])->getFormFields($entityIds);
276 }
277 else
278 {
279 $result = array();
280 }
281
282 return $result;
283 }
284
288 private function getOpsData(): ?array
289 {
290 $opsList = array();
291 $ops = $this->getDeliveryServiceOps();
292
293 if(!empty($ops['VALUE']) && isset($ops['NAME']))
294 {
295 $opsList[$ops['VALUE']] = $ops['NAME'];
296 }
297 else
298 {
299 //todo: cache
300 $opsRes = $this->getRequestObject('OPS')->send();
301
302 if($opsRes->isSuccess())
303 {
304 foreach($opsRes->getData() as $ops)
305 if($ops['enabled'] == true)
306 $opsList[$ops['operator-postcode']] = '('.$ops['operator-postcode'].') '.$ops['ops-address'];
307 }
308 }
309
310 if(!empty($opsList))
311 {
312 return array(
313 "TYPE" => "ENUM",
314 "TITLE" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_OPS'),
315 "REQUIRED" => "Y",
316 "OPTIONS" => $opsList
317 );
318 }
319
320 return null;
321 }
322 protected function getDeliveryServiceOps()
323 {
324 return \Sale\Handlers\Delivery\Additional\RusPost\Helper::getSelectedShippingPoint($this->deliveryService);
325 }
326
331 public function getRequestObject($type)
332 {
333 $result = null;
334 $requests = array(
335 'NORMALIZE_FIO' => 'NormalizeFio',
336 'CLEAN_ADDRESS' => 'CleanAddress',
337 'ORDER_CREATE' => 'OrderCreate',
338 'ORDER_DELETE' => 'OrderDelete',
339 'BATCH_CREATE' => 'BatchCreate',
340 'ORDER_DOC_F7P' => 'OrderDocF7P',
341 'ORDER_DOC_CREATE' => 'OrderDocForms',
342 'BATCH_ORDER_ADD' => 'BatchOrderAdd',
343 'BATCHES_LIST' => 'BatchesList',
344 'BATCH_ORDERS' => 'BatchOrders',
345 'BATCH_DOC_F103' => 'BatchDocF103',
346 'BATCH_DOC_PREPARE' => 'BatchDocPrepare',
347 'BATCH_DATE_UPDATE' => 'BatchDateUpdate',
348 'BATCH_DOC_ALL' => 'BatchDocAll',
349 'BATCH' => 'Batch',
350 'BATCHORDER' => 'BatchOrder',
351 'OPS' => 'OPS',
352 'USER_SETTINGS' => 'UserSettings',
353 'ORDER_DOC_F112EK' => 'OrderDocF112EK',
354 'UNRELIABLE_RECIPIENT' => 'UnreliableRecipient'
355 );
356
357 if(isset($requests[$type]))
358 {
359 $className = __NAMESPACE__.'\Requests\\'.$requests[$type];
360 $result = new $className($this->deliveryService, $this->getHttpClient());
361 }
362
363 return $result;
364 }
365
370 protected function getContentFieldName($field)
371 {
372 $fields = array(
373 "batch-name" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_BN'),
374 "batch-status" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_BS'),
375 "batch-status-date" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_BSD'),
376 "delivery-notice-payment-method" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_DNPM'),
377 "list-number" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_LN'),
378 "list-number-date" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_LND'),
379 "mail-category" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MC'),
380 "mail-category-text" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MCT'),
381 "mail-type" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MT'),
382 "mail-type-text" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MTT'),
383 "payment-method" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MTT'),
384 "postoffice-code" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_PC'),
385 "postoffice-name" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_PN'),
386 "shipment-count" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SC'),
387 "shipment-insure-rate-sum" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SIRS'),
388 "shipment-insure-rate-vat-sum" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SIRVS'),
389 "shipment-mass" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SM'),
390 "shipment-mass-rate-sum" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SMRS'),
391 "shipment-mass-rate-vat-sum" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SMRVS'),
392 "shipping-notice-type" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_SNT'),
393 "transport-type" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_TT'),
394 "postmarks" => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_PM'),
395 );
396
397 return isset($fields[$field]) ? $fields[$field] : $field;
398 }
399
405 protected function getContentFieldValue($field, $value)
406 {
407 $result = $value;
408
409 if($field == 'batch-status')
410 $result = Reference::getBatchStatus($value);
411 elseif($field == 'delivery-notice-payment-method')
412 $result = Reference::getPaymentMethod($value);
413 elseif($field == 'payment-method')
414 $result = Reference::getPaymentMethod($value);
415 elseif($field == 'shipping-notice-type')
416 $result = Reference::getShipmentNoticeType($value);
417 elseif($field == 'transport-type')
418 $result = Reference::getTransportType($value);
419 elseif($field == 'postmarks')
420 {
421 $result = implode(', ',
422 array_map(
423 array('\Sale\Handlers\Delivery\Additional\DeliveryRequests\RusPost\Reference', 'getPostmarkType'),
424 $value
425 )
426 );
427 }
428
429 if(is_array($result))
430 $result = implode(', ', $result);
431
432 return $result;
433 }
434
439 public function getContent($requestId)
440 {
441 $result = $this->getRequestObject('BATCH')->process(array($requestId));
442 $fields = array();
443
444 if($result->isSuccess())
445 {
446 foreach($result->getData() as $field => $value)
447 {
448 $fields[$field] = array(
449 "TITLE" => self::getContentFieldName($field),
450 "VALUE" => self::getContentFieldValue($field, $value)
451 );
452 }
453 }
454
455 $result->setData($fields);
456 return $result;
457 }
458
465 public function deleteShipments($requestId, array $shipmentIds = array())
466 {
467 $ids = array();
468 $filter = array('=REQUEST_ID' => $requestId);
469
470 if(!empty($shipmentIds))
471 $filter['=SHIPMENT_ID'] = $shipmentIds;
472
473 $res = Requests\ShipmentTable::getList(array(
474 'filter' => $filter
475 ));
476
477 while($row = $res->fetch())
478 if(intval($row['SHIPMENT_ID']) > 0)
479 $ids[] = $row['SHIPMENT_ID'];
480
481 if(!empty($ids))
482 $result = $this->getRequestObject('ORDER_DELETE')->process($ids);
483 else
484 $result = new Requests\Result();
485
486 return $result;
487 }
488
495 public function updateShipments($requestId, array $shipmentIds = array())
496 {
497 $result = $this->addShipments($requestId, $shipmentIds);
498
499 if(!$result->isSuccess())
500 return $result;
501
502 $idsToDel = array();
503 $queries = array();
504 $con = Application::getConnection();
505 $sqlHelper = $con->getSqlHelper();
506
508 foreach($result->getRequestResults() as $reqRes)
509 {
510 if($reqRes->isSuccess())
511 {
513 foreach($reqRes->getShipmentResults() as $shpRes)
514 {
515 if($shpRes->isSuccess())
516 {
517 $shpInternalId = intval($shpRes->getInternalId());
518 $idsToDel[] = $shpInternalId;
519 $externalId = $sqlHelper->forSql($shpRes->getExternalId());
520 $queries[$shpInternalId] = "UPDATE b_sale_delivery_req_shp SET EXTERNAL_ID='".$externalId."' WHERE REQUEST_ID=".intval($requestId)." AND SHIPMENT_ID=".$shpInternalId;
521 }
522 }
523 }
524 }
525
526 $failedShipments = array();
527
528 if(!empty($idsToDel))
529 {
530 $res = $this->deleteShipments($requestId, array_values($idsToDel));
531
532 if(!$res->isSuccess())
533 {
534 $result->addErrors($res->getErrors());
535 return $result;
536 }
537
538 foreach($res->getShipmentResults() as $shpRes)
539 if(!$shpRes->isSuccess())
540 $failedShipments[$shpRes->getInternalId()] = $shpRes;
541 }
542
543 if(!empty($failedShipments))
544 {
545 $results = $result->getRequestResults();
546
547 foreach($results as $resId => $reqRes)
548 {
549 if($reqRes->isSuccess())
550 {
551 $shpResults = $reqRes->getShipmentResults();
553 foreach($shpResults as $resShpId => $shpRes)
554 if(isset($failedShipments[$resShpId]))
555 $shpResults[$resShpId]->addErrors($failedShipments[$resShpId]->getErrors());
556
557 $results[$resId]->setResults($shpResults);
558 }
559 }
560
561 $result->setResults($results);
562 }
563
564 if(!empty($queries))
565 foreach($queries as $shpId => $query)
566 if(!isset($failedShipments[$shpId]))
567 $con->queryExecute($query);
568
569 return $result;
570 }
571
576 protected function getShipmentContentFieldName($field)
577 {
578 $fields = array(
579 'address-type-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ATT'),
580 'area-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_AT'),
581 'avia-rate' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_AR'),
582 'avia-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ARWV'),
583 'avia-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ARWOV'),
584 'barcode' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_B'),
585 'batch-category' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_BC'),
586 'batch-name' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_BN'),
587 'batch-status' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_BS'),
588 'brand-name' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_BRN'),
589 'building-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_BT'),
590 'comment' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_C'),
591 'corpus-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_CT'),
592 'delivery-time' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_DT'),
593 'dimension' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_D'),
594 'envelope-type' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ET'),
595 'fragile-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_FRWV'),
596 'fragile-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_FRWOV'),
597 'given-name' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_GN'),
598 'ground-rate' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_GR'),
599 'ground-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_GRWV'),
600 'ground-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_GRWOV'),
601 'hotel-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_HT'),
602 'house-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_HT2'),
603 'human-operation-name' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_HON'),
604 'id' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ID'),
605 'index-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_IT'),
606 'insr-rate' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_IR'),
607 'insr-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_IRWV'),
608 'insr-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_IRWOV'),
609 'insr-value' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_IV'),
610 'is-deleted' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ID'),
611 'last-oper-attr' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_LOA'),
612 'last-oper-type' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_LOT'),
613 'letter-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_LT'),
614 'location-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_LOCT'),
615 'mail-category' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MC'),
616 'mail-direct' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_MD'),
617 'mail-rank' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_MR'),
618 'mail-type' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_MT'),
619 'mass' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_M'),
620 'mass-rate' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_MRA'),
621 'mass-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_MRAWV'),
622 'mass-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_MRAWOV'),
623 'middle-name' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_MN'),
624 'notice-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_NRWV'),
625 'notice-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_NRWOV'),
626 'num-address-type-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_NATT'),
627 'order-num' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ON'),
628 'oversize-rate-with-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ORWV'),
629 'oversize-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ORWOV'),
630 'payment' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_P'),
631 'payment-method' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_PM'),
632 'place-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_PT'),
633 'postmarks' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_POMA'),
634 'postoffice-code' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_F_PC'),
635 'recipient-name' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_RN'),
636 'region-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_RT'),
637 'room-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ROTO'),
638 'slash-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_ST'),
639 'street-to' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_STT'),
640 'surname' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_S'),
641 'tel-address' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_TA'),
642 'total-rate-wo-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_TRWV'),
643 'total-vat' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_TV'),
644 'transport-type' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_TT'),
645 'version' => Loc::getMessage('SALE_DLVRS_ADD_DREQ_SF_V')
646 );
647
648 return isset($fields[$field]) ? $fields[$field] : $field;
649 }
650
656 protected function getShipmentContentFieldValue($field, $value)
657 {
658 $result = $value;
659
660 if($field == 'address-type-to')
661 $result = Reference::getAddressType($value);
662 elseif($field == 'batch-category')
663 $result = Reference::getRpoCategory($value);
664 elseif($field == 'batch-status')
665 $result = Reference::getBatchStatus($value);
666 elseif($field == 'delivery-time')
667 $result = $value['max-days'].' - '.$value['min-days'];
668 elseif($field == 'dimension')
669 $result = $value['length'].' X '.$value['width'].' X '.$value['height'];
670 elseif($field == 'envelope-type')
671 $result = Reference::getEnvelopeType($value);
672 elseif($field == 'last-oper-attr')
673 $result = Reference::getTrackingAttr($value);
674 elseif($field == 'last-oper-type')
675 $result = Reference::getTrackingAttr($value);
676 elseif($field == 'mail-category')
677 $result = Reference::getRpoCategory($value);
678 elseif($field == 'mail-rank')
679 $result = Reference::getMailRank($value);
680 elseif($field == 'mail-type')
681 $result = Reference::getRpoKind($value);
682 elseif($field == 'payment-method')
683 $result = Reference::getPaymentMethod($value);
684 elseif($field == 'transport-type')
685 $result = Reference::getTransportType($value);
686 elseif($field == 'postmarks')
687 {
688 $result = implode(', ',
689 array_map(
690 array(__NAMESPACE__.'\\Reference', 'getPostmarkType'),
691 $value
692 )
693 );
694 }
695
696 if(is_array($result))
697 $result = implode(', ', $result);
698
699 return $result;
700 }
701
708 public function getShipmentContent($requestId, $shipmentId)
709 {
710 $result = new Requests\Result();
711
712 if(intval($shipmentId) <= 0)
713 {
714 $result->addError(new Error(Loc::getMessage('SALE_DLVRS_ADD_DREQ_ERR_SID_NULL')));
715 return $result;
716 }
717
718 $res = Requests\ShipmentTable::getList(array(
719 'filter' => array(
720 '=SHIPMENT_ID' => $shipmentId
721 ),
722 ));
723
724 $row = $res->fetch();
725
726 if(!$row || (string)$row['EXTERNAL_ID'] === '')
727 {
728 $result->addError(
729 new Error(
730 Loc::getMessage(
731 'SALE_DLVRS_ADD_DREQ_ERR_SHIPMENT_NOT_INCLUDED',
732 array('#SHIPMENT_ID#' => $shipmentId)
733 )));
734
735 return $result;
736 }
737
738 $res = $this->getRequestObject('BATCHORDER')->process(array($shipmentId));
739
740 $fields = array();
741
742 if($res->isSuccess())
743 {
744 $data = $res->getData();
745
746 if(!empty($data))
747 {
748 foreach($data as $field => $value)
749 {
750 $fields[$field] = array(
751 "TITLE" => $this->getShipmentContentFieldName($field),
752 "VALUE" => $this->getShipmentContentFieldValue($field, $value),
753 );
754 }
755
756 if(!empty($fields))
757 $result->setData($fields);
758 }
759 }
760 else
761 {
762 $result->addErrors($res->getErrors());
763 }
764
765 return $result;
766 }
767}
$path
Определения access_edit.php:21
$con
Определения admin_tab.php:7
$type
Определения options.php:106
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
updateShipments($requestId, array $shipmentIds=[])
Определения handlerbase.php:155
$data['IS_AVAILABLE']
Определения .description.php:13
hidden PROPERTY[<?=$propertyIndex?>][CODE]<?=htmlspecialcharsEx( $propertyCode)?> height
Определения file_new.php:759
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
Определения file_new.php:677
</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
$query
Определения get_search.php:11
$filter
Определения iblock_catalog_list.php:54
$value
Определения Param.php:39
getErrors()
Определения errorableimplementation.php:34
trait Error
Определения error.php:11
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$fields
Определения yandex_run.php:501