Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2
3
5
12
14{
15 protected $app;
16
17 public function __construct()
18 {
19 $this->app = new IntegrationB24();
20 }
21
22 public function isOn()
23 {
24 return Token::getExistsByGuid($this->app->getCode());
25 }
26
27 public function delete()
28 {
29 $registry = new IntegrationB24Registry($this->app);
30 $neworder = new IntegrationB24NewOrder($this->app);
31
32 $result['PLACEMENTS'][] = [
33 'PLACEMENT'=>$registry->getPlacement(),
34 'HANDLER'=>$registry->getPlacmentHandler()
35 ];
36
37 $result['PLACEMENTS'][] = [
38 'PLACEMENT'=>$neworder->getPlacement(),
39 'HANDLER'=>$neworder->getPlacmentHandler()
40 ];
41
42 $result['OPTIONS'] = ['url'=>$this->app->getAppUrl()];
43
44 (new Scenarios\Connector())->delete($result);
45
46 Token::delete($this->app->getCode());
47
48 \CAgent::RemoveAgent('\\Bitrix\\Sale\\Exchange\\Integration\\Agent\\Statistic::modify();', 'sale');
49
50 static::unRegisterEvents();
51 }
52
53 public function add()
54 {
55 $registry = new IntegrationB24Registry($this->app);
56 $neworder = new IntegrationB24NewOrder($this->app);
57
58 $result['PLACEMENTS'][] = [
59 'PLACEMENT'=>$registry->getPlacement(),
60 'HANDLER'=>$registry->getPlacmentHandler(),
61 'GROUP_NAME'=>$registry->getGroupName(),
62 'TITLE'=>$registry->getTitle(),
63 ];
64
65 $result['PLACEMENTS'][] = [
66 'PLACEMENT'=>$neworder->getPlacement(),
67 'HANDLER'=>$neworder->getPlacmentHandler(),
68 'GROUP_NAME'=>$neworder->getGroupName(),
69 'TITLE'=>$neworder->getTitle(),
70 ];
71
72 $result['OPTIONS'] = ['url'=>$this->app->getAppUrl()];
73
74 $result['PROVIDER'] = [
75 'xmlId'=>$this->app->getCode(),
76 'name'=> (string)\Bitrix\Main\Config\Option::get('main', 'site_name'),
77 'externalServerHost'=> (string)\Bitrix\Main\Config\Option::get('main', 'server_name',
78 \Bitrix\Main\Application::getInstance()->getContext()->getRequest()->getHttpHost())
79 ];
80
81 (new Scenarios\Connector())->add($result);
82
83 \CAgent::AddAgent('\\Bitrix\\Sale\\Exchange\\Integration\\Agent\\Statistic::modify();', 'sale', 'N', 3600);
84
85 static::registerEvents();
86 }
87
88 protected static function registerEvents()
89 {
90 $eventManager = EventManager::getInstance();
91
92 //region Order handlerCallback
93 $eventManager->registerEventHandler(
94 "sale",
95 "OnSaleOrderSaved",
96 "sale",
97 '\Bitrix\Sale\Exchange\Integration\Handler',
98 'handlerCallbackOnSaleOrderSaved');
99 $eventManager->registerEventHandler(
100 "sale",
101 "OnSaleStatusOrderChange",
102 "sale",
103 '\Bitrix\Sale\Exchange\Integration\Timeline\Order',
104 'statusNotify');
105 $eventManager->registerEventHandler(
106 "sale",
107 "OnSaleOrderCanceled",
108 "sale",
109 '\Bitrix\Sale\Exchange\Integration\Timeline\Order',
110 'canceledNotify');
111 //endregion
112 //region Payment handlerCallback
113 $eventManager->registerEventHandler(
114 "sale",
115 "OnPaymentPaid",
116 "sale",
117 '\Bitrix\Sale\Exchange\Integration\Timeline\Payment',
118 'paidNotify');
119 //endregion
120 //region Shipment handlerCallback
121 $eventManager->registerEventHandler(
122 "sale",
123 "OnSaleStatusShipmentChange",
124 "sale",
125 '\Bitrix\Sale\Exchange\Integration\Timeline\Shipment',
126 'statusNotify');
127 $eventManager->registerEventHandler(
128 "sale",
129 "OnShipmentAllowDelivery",
130 "sale",
131 '\Bitrix\Sale\Exchange\Integration\Timeline\Shipment',
132 'allowDeliveryNotify');
133 $eventManager->registerEventHandler(
134 "sale",
135 "OnShipmentDeducted",
136 "sale",
137 '\Bitrix\Sale\Exchange\Integration\Timeline\Shipment',
138 'deductedNotify');
139 //endregion
140 }
141
142 protected static function unRegisterEvents()
143 {
144 //region Order handlerCallback
145 UnRegisterModuleDependences(
146 "sale",
147 "OnSaleOrderSaved",
148 "sale",
149 '\Bitrix\Sale\Exchange\Integration\Handler',
150 'handlerCallbackOnSaleOrderSaved');
151 UnRegisterModuleDependences(
152 "sale",
153 "OnSaleStatusOrderChange",
154 "sale",
155 '\Bitrix\Sale\Exchange\Integration\Timeline\Order',
156 'statusNotify');
157 UnRegisterModuleDependences(
158 "sale",
159 "OnSaleOrderCanceled",
160 "sale",
161 '\Bitrix\Sale\Exchange\Integration\Timeline\Order',
162 'canceledNotify');
163 //endregion
164 //region Payment handlerCallback
165 UnRegisterModuleDependences(
166 "sale",
167 "OnPaymentPaid",
168 "sale",
169 '\Bitrix\Sale\Exchange\Integration\Timeline\Payment',
170 'paidNotify');
171 //endregion
172 //region Shipment handlerCallback
173 UnRegisterModuleDependences(
174 "sale",
175 "OnSaleStatusShipmentChange",
176 "sale",
177 '\Bitrix\Sale\Exchange\Integration\Timeline\Shipment',
178 'statusNotify');
179 UnRegisterModuleDependences(
180 "sale",
181 "OnShipmentAllowDelivery",
182 "sale",
183 '\Bitrix\Sale\Exchange\Integration\Timeline\Shipment',
184 'allowDeliveryNotify');
185 UnRegisterModuleDependences(
186 "sale",
187 "OnShipmentDeducted",
188 "sale",
189 '\Bitrix\Sale\Exchange\Integration\Timeline\Shipment',
190 'deductedNotify');
191 //endregion
192 }
193}
194