Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
tracking.php
1
<?php
2
3
4
namespace
Bitrix\Sale\Controller
;
5
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\Localization\Loc
;
8
use
Bitrix\Main\Request
;
9
use
Bitrix\Sale\Delivery\Tracking\Manager
;
10
11
12
class
Tracking
extends
\Bitrix\Main\Engine\Controller
13
{
14
private
$manager;
15
16
const
PERMISSION_READ
=
'D'
;
17
const
PERMISSION_WRITE
=
'W'
;
18
19
public
function
__construct
(
Request
$request =
null
)
20
{
21
$this->manager =
Manager::getInstance
();
22
parent::__construct(
$request
);
23
}
24
25
public
function
getStatusByShipmentIdAction
(
int
$shipmentId,
string
$trackingNumber =
''
)
26
{
27
if
($shipmentId <= 0)
28
{
29
$this->
addError
(
new
Error
(
Loc::getMessage
(
'SALE_CONTROLLER_TRACKING_ERROR_SHIPMENT_ZERO'
)));
30
return
null
;
31
}
32
33
if
($trackingNumber ==
''
)
34
{
35
$this->
addError
(
new
Error
(
Loc::getMessage
(
'SALE_CONTROLLER_TRACKING_ERROR_DELETE_STATUS'
)));
36
return
null
;
37
}
38
39
if
(!$this->
checkPermission
(self::PERMISSION_READ))
40
{
41
return
null
;
42
}
43
44
$result =
null
;
45
$res = $this->manager->getStatusByShipmentId($shipmentId, $trackingNumber);
46
47
if
($res->isSuccess())
48
{
49
$lastChange =
''
;
50
51
if
($res->lastChangeTimestamp > 0)
52
{
53
$lastChange = \Bitrix\Main\Type\DateTime::createFromTimestamp(
54
$res->lastChangeTimestamp
55
)->toString();
56
}
57
58
$result = [
59
'status'
=> $res->status,
60
'statusName'
=>
Manager::getStatusName
($res->status),
61
'description'
=> $res->description,
62
'lastChange'
=> $lastChange
63
];
64
65
if
($this->
checkPermission
(self::PERMISSION_WRITE))
66
{
67
$res = $this->manager->updateShipment($shipmentId, $res);
68
69
if
(!$res->isSuccess())
70
{
71
$this->
addErrors
($res->getErrors());
72
}
73
}
74
}
75
else
76
{
77
$this->
addErrors
($res->getErrors());
78
}
79
80
return
$result;
81
}
82
83
protected
function
checkPermission
($permissionType)
84
{
85
$result = self::getApplication()->GetGroupRight(
"sale"
) >= $permissionType;
86
87
if
(!$result)
88
{
89
$this->
addError
(
new
Error
(
'Access denied'
));
90
}
91
92
return
$result;
93
}
94
95
protected
static
function
getApplication
()
96
{
98
global $APPLICATION;
99
100
return
$APPLICATION;
101
}
102
}
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Definition
controller.php:1051
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Engine\Controller\$request
$request
Definition
controller.php:48
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Request
Definition
request.php:10
Bitrix\Sale\Cashbox\Manager
Definition
manager.php:22
Bitrix\Sale\Controller\Tracking
Definition
tracking.php:13
Bitrix\Sale\Controller\Tracking\getApplication
static getApplication()
Definition
tracking.php:95
Bitrix\Sale\Controller\Tracking\__construct
__construct(Request $request=null)
Definition
tracking.php:19
Bitrix\Sale\Controller\Tracking\PERMISSION_WRITE
const PERMISSION_WRITE
Definition
tracking.php:17
Bitrix\Sale\Controller\Tracking\PERMISSION_READ
const PERMISSION_READ
Definition
tracking.php:16
Bitrix\Sale\Controller\Tracking\getStatusByShipmentIdAction
getStatusByShipmentIdAction(int $shipmentId, string $trackingNumber='')
Definition
tracking.php:25
Bitrix\Sale\Controller\Tracking\checkPermission
checkPermission($permissionType)
Definition
tracking.php:83
Bitrix\Sale\Delivery\Tracking\Manager\getStatusName
static getStatusName($status)
Definition
manager.php:118
Bitrix\Sale\Delivery\Tracking\Manager\getInstance
static getInstance()
Definition
manager.php:106
Bitrix\Sale\Controller
modules
sale
lib
controller
tracking.php
Создано системой
1.10.0