Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
manager.php
1
<?php
2
3
4
namespace
Bitrix\Sale\Rest\Synchronization
;
5
6
7
use
Bitrix\Main\Config\Option
;
8
use
Bitrix\Main\Error
;
9
use
Bitrix\Main\HttpRequest
;
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Sale\Result
;
12
13
Loc::loadMessages
(__FILE__);
14
15
class
Manager
16
{
17
protected
$action
;
18
protected
$handlerExecuted
;
19
20
protected
$client
;
21
protected
$clientOAuth
;
22
protected
$clientId
;
23
protected
$clientSecret
;
24
25
26
protected
$serviceUrl
;
27
protected
$oauthKey
;
28
protected
$accessToken
;
29
protected
$refreshToken
;
30
32
protected
$request
;
33
34
protected
static
$instance
=
null
;
35
36
const
B24_APP_GRANT_TYPE
=
'refresh_token'
;
37
38
const
ACTION_UNDEFINED
=
'undefined'
;
39
const
ACTION_DELETED
=
'deleted'
;
40
const
ACTION_IMPORT
=
'import'
;
41
42
const
END_POINT
=
'/bitrix/services/sale/synchronizer/push.php'
;
43
44
public
static
function
getInstance
()
45
{
46
if
(self::$instance ===
null
)
47
{
48
self::$instance =
new
static
();
49
}
50
return
self::$instance
;
51
}
52
53
public
function
isActive
()
54
{
55
return
Option::get(
"sale"
,
"config_external_is_active"
)==
'Y'
;
56
}
57
public
function
activate
()
58
{
59
Option::set(
"sale"
,
"config_external_is_active"
,
'Y'
);
60
}
61
public
function
deactivate
()
62
{
63
Option::set(
"sale"
,
"config_external_is_active"
,
'N'
);
64
}
65
66
public
function
pushHandlerExecuted
($name)
67
{
68
$this->handlerExecuted[$name];
69
}
70
71
public
function
isExecutedHandler
($name)
72
{
73
return
is_set($this->handlerExecuted, $name);
74
}
75
76
public
function
checkDefaultSettings
()
77
{
78
$result =
new
Result
();
79
80
$siteId=
''
;
81
$r = \CSite::GetList();
82
while
($row = $r->fetch())
83
if
($row[
'ID'
]==$this->
getDefaultSiteId
())
84
$siteId=$row[
'ID'
];
85
86
if
($siteId==
''
)
87
$result->addError(
new
Error
(
Loc::getMessage
(
'MAN_ERROR_EMPTY_FIELD_SITE'
)));
88
89
$deliverySystemId=0;
90
foreach
(\
Bitrix
\
Sale
\
Delivery
\Services\Manager::getActiveList() as $row)
91
if
($row[
'ID'
]==$this->
getDefaultDeliverySystemId
())
92
$deliverySystemId = $row[
'ID'
];
93
if
($deliverySystemId==0)
94
$result->addError(
new
Error
(
Loc::getMessage
(
'MAN_ERROR_EMPTY_FIELD_DELIVERY_SERVICES'
)));
95
96
if
(count(\
Bitrix
\
Sale
\PaySystem\Manager::getList([
'filter'
=>[
'ID'
=>$this->
getDefaultPaySystemId
()]]))<=0)
97
$result->addError(
new
Error
(
Loc::getMessage
(
'MAN_ERROR_EMPTY_FIELD_PAY_SYSTEM'
)));
98
if
(count(\
Bitrix
\
Sale
\
PersonType::getList
([
'filter'
=>[
'ID'
=>$this->
getDefaultPersonTypeId
()]]))<=0)
99
$result->addError(
new
Error
(
Loc::getMessage
(
'MAN_ERROR_EMPTY_FIELD_PERSON_TYPE'
)));
100
if
(count(\
Bitrix
\
Sale
\
OrderStatus::getList
([
'filter'
=>[
'ID'
=>$this->
getDefaultOrderStatusId
()]]))<=0)
101
$result->addError(
new
Error
(
'MAN_ERROR_EMPTY_FIELD_ORDER_STATUS'
));
102
if
(count(\
Bitrix
\
Sale
\
DeliveryStatus::getList
([
'filter'
=>[
'ID'
=>$this->
getDefaultDeliveryStatusId
()]]))<=0)
103
$result->addError(
new
Error
(
'MAN_ERROR_EMPTY_FIELD_DELIVERY_STATUS'
));
104
105
$catalogList=[];
106
if
(\
Bitrix
\Main\
Loader::includeModule
(
'catalog'
))
107
{
108
$catalogList = \Bitrix\Catalog\CatalogIblockTable::getList([
109
'select'
=> [
'IBLOCK_ID'
,
'IBLOCK.NAME'
],
110
'filter'
=> [
'=IBLOCK.ACTIVE'
=>
'Y'
]
111
])->fetchAll();
112
}
113
if
(!count($catalogList)>0)
114
$result->addError(
new
Error
(
Loc::getMessage
(
'MAN_ERROR_CATALOGS'
)));
115
116
return
$result;
117
}
118
119
public
function
getClient
()
120
{
121
if
(!$this->client)
122
{
123
$this->client =
new
Client
(
124
$this->
getClientId
(),
125
$this->
getClientSecret
(),
126
$this->
getSchemeServiceUrl
().
'://'
.$this->
getServiceUrl
()
127
);
128
}
129
return
$this->client
;
130
}
131
132
public
function
setSchemeServiceUrl
($code)
133
{
134
Option::set(
"sale"
,
"config_external_scheme_service_url"
, $code);
135
}
136
137
public
function
getSchemeServiceUrl
()
138
{
139
return
Option::get(
"sale"
,
"config_external_scheme_service_url"
,
false
);
140
}
141
142
public
function
setServiceUrl
($code)
143
{
144
Option::set(
"sale"
,
"config_external_service_url"
, $code);
145
}
146
147
public
function
getServiceUrl
()
148
{
149
return
Option::get(
"sale"
,
"config_external_service_url"
,
false
);
150
}
151
152
public
function
getClientId
()
153
{
154
return
'app.5c05614270fdc0.60242739'
;
155
}
156
157
public
function
getClientSecret
()
158
{
159
return
'cvdpAuyaHdC9ngJHctyRwu2xFtZamw85P3CWV8mIg7ESBfrVIa'
;
160
}
161
162
public
function
setAccessToken
(
$accessToken
)
163
{
164
Option::set(
"sale"
,
"config_external_access_token"
,
$accessToken
);
165
}
166
public
function
getAccessToken
()
167
{
168
return
Option::get(
"sale"
,
"config_external_access_token"
,
false
);
169
}
170
171
public
function
setRefreshToken
(
$refreshToken
)
172
{
173
Option::set(
"sale"
,
"config_external_refresh_token"
,
$refreshToken
);
174
}
175
public
function
getRefreshToken
()
176
{
177
return
Option::get(
"sale"
,
"config_external_refresh_token"
,
false
);
178
}
179
180
public
function
setOauthKey
($key)
181
{
182
Option::set(
"sale"
,
"config_external_oauth_key"
, $key);
183
}
184
public
function
getOauthKey
()
185
{
186
return
Option::get(
"sale"
,
"config_external_oauth_key"
,
""
);
187
}
188
189
public
function
setAction
(
$action
)
190
{
191
$this->action =
$action
;
192
}
193
public
function
getAction
()
194
{
195
return
$this->action
;
196
}
197
198
public
function
getDefaultDeliverySystemId
()
199
{
200
return
(
int
)Option::get(
"sale"
,
"config_external_default_delivery_system_id"
);
201
}
202
public
function
setDefaultDeliverySystemId
($code)
203
{
204
Option::set(
"sale"
,
"config_external_default_delivery_system_id"
, $code);
205
}
206
207
public
function
getDefaultPaySystemId
()
208
{
209
return
(
int
)Option::get(
"sale"
,
"config_external_default_pay_system_id"
);
210
}
211
public
function
setDefaultPaySystemId
($code)
212
{
213
Option::set(
"sale"
,
"config_external_default_pay_system_id"
, $code);
214
}
215
216
public
function
getDefaultSiteId
()
217
{
218
return
Option::get(
"sale"
,
"config_external_default_site_id"
);
219
}
220
public
function
setDefaultSiteId
($code)
221
{
222
Option::set(
"sale"
,
"config_external_default_site_id"
, $code);
223
}
224
225
public
function
getDefaultPersonTypeId
()
226
{
227
return
(
int
)Option::get(
"sale"
,
"config_external_default_person_type_id"
);
228
}
229
public
function
setDefaultPersonTypeId
($code)
230
{
231
Option::set(
"sale"
,
"config_external_default_person_type_id"
, $code);
232
}
233
234
public
function
getDefaultOrderStatusId
()
235
{
236
return
Option::get(
"sale"
,
"config_external_default_order_status_id"
);
237
}
238
public
function
setDefaultOrderStatusId
($code)
239
{
240
Option::set(
"sale"
,
"config_external_default_order_status_id"
, $code);
241
}
242
243
public
function
getDefaultDeliveryStatusId
()
244
{
245
return
Option::get(
"sale"
,
"config_external_default_delivery_status_id"
);
246
}
247
public
function
setDefaultDeliveryStatusId
($code)
248
{
249
Option::set(
"sale"
,
"config_external_default_delivery_status_id"
, $code);
250
}
251
252
public
function
getTradePlatformsXmlId
($siteId)
253
{
254
$r = unserialize(Option::get(
"sale"
,
"config_external_trade_platforms_xml_id"
), [
'allowed_classes'
=>
false
]);
255
return
$r[$siteId];
256
}
257
public
function
setTradePlatformsXmlId
($siteId, $code)
258
{
259
$r = unserialize(Option::get(
"sale"
,
"config_external_trade_platforms_xml_id"
), [
'allowed_classes'
=>
false
]);
260
261
$r[$siteId] = $code;
262
Option::set(
"sale"
,
"config_external_trade_platforms_xml_id"
, serialize($r));
263
}
264
265
public
function
isMarked
()
266
{
267
return
Option::get(
"sale"
,
"config_external_order_marked"
,
'N'
) ==
'Y'
;
268
}
269
public
function
marked
($code)
270
{
271
Option::set(
"sale"
,
"config_external_order_marked"
, $code);
272
}
273
274
}
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\HttpRequest
Definition
httprequest.php:20
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Definition
loader.php:69
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Sale\PersonType\getList
static getList(array $parameters=[])
Definition
persontype.php:100
Bitrix\Sale\Rest\Synchronization\Client
Definition
client.php:18
Bitrix\Sale\Rest\Synchronization\Manager
Definition
manager.php:16
Bitrix\Sale\Rest\Synchronization\Manager\setAction
setAction($action)
Definition
manager.php:189
Bitrix\Sale\Rest\Synchronization\Manager\setDefaultOrderStatusId
setDefaultOrderStatusId($code)
Definition
manager.php:238
Bitrix\Sale\Rest\Synchronization\Manager\setRefreshToken
setRefreshToken($refreshToken)
Definition
manager.php:171
Bitrix\Sale\Rest\Synchronization\Manager\$accessToken
$accessToken
Definition
manager.php:28
Bitrix\Sale\Rest\Synchronization\Manager\$refreshToken
$refreshToken
Definition
manager.php:29
Bitrix\Sale\Rest\Synchronization\Manager\getAction
getAction()
Definition
manager.php:193
Bitrix\Sale\Rest\Synchronization\Manager\getServiceUrl
getServiceUrl()
Definition
manager.php:147
Bitrix\Sale\Rest\Synchronization\Manager\getClientSecret
getClientSecret()
Definition
manager.php:157
Bitrix\Sale\Rest\Synchronization\Manager\checkDefaultSettings
checkDefaultSettings()
Definition
manager.php:76
Bitrix\Sale\Rest\Synchronization\Manager\ACTION_IMPORT
const ACTION_IMPORT
Definition
manager.php:40
Bitrix\Sale\Rest\Synchronization\Manager\getClient
getClient()
Definition
manager.php:119
Bitrix\Sale\Rest\Synchronization\Manager\setServiceUrl
setServiceUrl($code)
Definition
manager.php:142
Bitrix\Sale\Rest\Synchronization\Manager\$clientSecret
$clientSecret
Definition
manager.php:23
Bitrix\Sale\Rest\Synchronization\Manager\getSchemeServiceUrl
getSchemeServiceUrl()
Definition
manager.php:137
Bitrix\Sale\Rest\Synchronization\Manager\getTradePlatformsXmlId
getTradePlatformsXmlId($siteId)
Definition
manager.php:252
Bitrix\Sale\Rest\Synchronization\Manager\marked
marked($code)
Definition
manager.php:269
Bitrix\Sale\Rest\Synchronization\Manager\$handlerExecuted
$handlerExecuted
Definition
manager.php:18
Bitrix\Sale\Rest\Synchronization\Manager\getAccessToken
getAccessToken()
Definition
manager.php:166
Bitrix\Sale\Rest\Synchronization\Manager\getDefaultPaySystemId
getDefaultPaySystemId()
Definition
manager.php:207
Bitrix\Sale\Rest\Synchronization\Manager\setDefaultDeliveryStatusId
setDefaultDeliveryStatusId($code)
Definition
manager.php:247
Bitrix\Sale\Rest\Synchronization\Manager\getDefaultOrderStatusId
getDefaultOrderStatusId()
Definition
manager.php:234
Bitrix\Sale\Rest\Synchronization\Manager\setTradePlatformsXmlId
setTradePlatformsXmlId($siteId, $code)
Definition
manager.php:257
Bitrix\Sale\Rest\Synchronization\Manager\setDefaultSiteId
setDefaultSiteId($code)
Definition
manager.php:220
Bitrix\Sale\Rest\Synchronization\Manager\getOauthKey
getOauthKey()
Definition
manager.php:184
Bitrix\Sale\Rest\Synchronization\Manager\setDefaultPersonTypeId
setDefaultPersonTypeId($code)
Definition
manager.php:229
Bitrix\Sale\Rest\Synchronization\Manager\deactivate
deactivate()
Definition
manager.php:61
Bitrix\Sale\Rest\Synchronization\Manager\getRefreshToken
getRefreshToken()
Definition
manager.php:175
Bitrix\Sale\Rest\Synchronization\Manager\pushHandlerExecuted
pushHandlerExecuted($name)
Definition
manager.php:66
Bitrix\Sale\Rest\Synchronization\Manager\$clientId
$clientId
Definition
manager.php:22
Bitrix\Sale\Rest\Synchronization\Manager\ACTION_UNDEFINED
const ACTION_UNDEFINED
Definition
manager.php:38
Bitrix\Sale\Rest\Synchronization\Manager\$serviceUrl
$serviceUrl
Definition
manager.php:26
Bitrix\Sale\Rest\Synchronization\Manager\getDefaultDeliverySystemId
getDefaultDeliverySystemId()
Definition
manager.php:198
Bitrix\Sale\Rest\Synchronization\Manager\getDefaultPersonTypeId
getDefaultPersonTypeId()
Definition
manager.php:225
Bitrix\Sale\Rest\Synchronization\Manager\isActive
isActive()
Definition
manager.php:53
Bitrix\Sale\Rest\Synchronization\Manager\$action
$action
Definition
manager.php:17
Bitrix\Sale\Rest\Synchronization\Manager\isExecutedHandler
isExecutedHandler($name)
Definition
manager.php:71
Bitrix\Sale\Rest\Synchronization\Manager\setOauthKey
setOauthKey($key)
Definition
manager.php:180
Bitrix\Sale\Rest\Synchronization\Manager\getDefaultDeliveryStatusId
getDefaultDeliveryStatusId()
Definition
manager.php:243
Bitrix\Sale\Rest\Synchronization\Manager\getClientId
getClientId()
Definition
manager.php:152
Bitrix\Sale\Rest\Synchronization\Manager\B24_APP_GRANT_TYPE
const B24_APP_GRANT_TYPE
Definition
manager.php:36
Bitrix\Sale\Rest\Synchronization\Manager\$request
$request
Definition
manager.php:32
Bitrix\Sale\Rest\Synchronization\Manager\getInstance
static getInstance()
Definition
manager.php:44
Bitrix\Sale\Rest\Synchronization\Manager\$client
$client
Definition
manager.php:20
Bitrix\Sale\Rest\Synchronization\Manager\setDefaultPaySystemId
setDefaultPaySystemId($code)
Definition
manager.php:211
Bitrix\Sale\Rest\Synchronization\Manager\$instance
static $instance
Definition
manager.php:34
Bitrix\Sale\Rest\Synchronization\Manager\$clientOAuth
$clientOAuth
Definition
manager.php:21
Bitrix\Sale\Rest\Synchronization\Manager\ACTION_DELETED
const ACTION_DELETED
Definition
manager.php:39
Bitrix\Sale\Rest\Synchronization\Manager\$oauthKey
$oauthKey
Definition
manager.php:27
Bitrix\Sale\Rest\Synchronization\Manager\setAccessToken
setAccessToken($accessToken)
Definition
manager.php:162
Bitrix\Sale\Rest\Synchronization\Manager\END_POINT
const END_POINT
Definition
manager.php:42
Bitrix\Sale\Rest\Synchronization\Manager\getDefaultSiteId
getDefaultSiteId()
Definition
manager.php:216
Bitrix\Sale\Rest\Synchronization\Manager\setDefaultDeliverySystemId
setDefaultDeliverySystemId($code)
Definition
manager.php:202
Bitrix\Sale\Rest\Synchronization\Manager\setSchemeServiceUrl
setSchemeServiceUrl($code)
Definition
manager.php:132
Bitrix\Sale\Rest\Synchronization\Manager\isMarked
isMarked()
Definition
manager.php:265
Bitrix\Sale\Rest\Synchronization\Manager\activate
activate()
Definition
manager.php:57
Bitrix\Sale\Services\PaySystem\Restrictions\Delivery
Definition
delivery.php:23
Bitrix\Sale\StatusBase\getList
static getList(array $parameters=array())
Definition
statusbase.php:29
Bitrix\Sale\Rest\Synchronization
Definition
client.php:4
Bitrix
Sale
modules
sale
lib
rest
synchronization
manager.php
Создано системой
1.10.0