Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2
3
5
6
12
13Loc::loadMessages(__FILE__);
14
16{
17 protected $action;
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
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
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
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
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}
static includeModule($moduleName)
Definition loader.php:69
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=[])
static getList(array $parameters=array())