30 Loader::includeModule(
'sale');
43 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
46 'OnSaleBeforeOrderDelete'=>[
48 'OnSaleBeforeOrderDelete',
54 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
58 'OnPropertyValueEntitySaved'=>[
60 'OnSalePropertyValueEntitySaved',
66 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
69 'OnPaymentEntitySaved'=>[
71 'OnSalePaymentEntitySaved',
77 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
80 'OnShipmentEntitySaved'=>[
82 'OnSaleShipmentEntitySaved',
88 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
91 'OnOrderEntitySaved'=>[
93 'OnSaleOrderEntitySaved',
99 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
102 'OnPropertyValueDeleted'=>[
104 'OnSalePropertyValueDeleted',
110 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
113 'OnPaymentDeleted'=>[
115 'OnSalePaymentDeleted',
121 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
124 'OnShipmentDeleted'=>[
126 'OnSaleShipmentDeleted',
132 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
137 'OnSaleOrderEntitySaved',
143 'category' => \Bitrix\Rest\Sqs::CATEGORY_CRM
151 public static function processEvent(array $params, array $handlerFields)
154 $eventName = $handlerFields[
'EVENT_NAME'];
155 $eventHandler = $handlerFields[
'EVENT_HANDLER'];
159 LoggerDiag::addMessage(
'processEvent', var_export([
160 'processEvent [process-01]'=> [
161 'eventName'=>$eventName,
162 'action'=>$instance->getAction()
166 switch(mb_strtolower($eventName))
168 case 'onsaleordersaved':
171 $entity = $event->getParameters()[
'ENTITY'];
182 elseif($instance->isExecutedHandler($eventHandler))
189 if($entity->getId() <= 0)
191 throw new RestException(
"Could not find entity ID in fields of event \"{$eventName}\"");
195 $parameters = [
'FIELDS' => [
'ID' => $entity->getId(),
'XML_ID' => $entity->getField(
'XML_ID'),
'ACTION' =>
Synchronizer::MODE_SAVE]];
197 LoggerDiag::addMessage(mb_strtolower($eventName), var_export([
198 'processEvent [process-02]' => [
199 'parameters' => $parameters
204 $instance->pushHandlerExecuted($eventHandler);
208 case 'onsalebeforeorderdelete':
211 $entity = $event->getParameters()[
'ENTITY'];
218 throw new RestException(
"Event stopped");
225 $parameters = [
'FIELDS' => [
'ID' => $entity->getId(),
'XML_ID' => $entity->getField(
'XML_ID'),
'ACTION' =>
Synchronizer::MODE_DELETE]];
227 LoggerDiag::addMessage(mb_strtolower($eventName), var_export([
228 'processEvent [process-03]' => [
229 'parameters' => $parameters
236 case 'onpropertyvalueentitysaved':
237 case 'onpaymententitysaved':
238 case 'onshipmententitysaved':
239 case 'onorderentitysaved':
240 case 'onpropertyvaluedeleted':
241 case 'onpaymentdeleted':
242 case 'onshipmentdeleted':
243 case 'onorderdeleted':
246 $entity = $event->getParameters()[
'ENTITY'];
250 $entityId = $entity->getId();
252 elseif(isset($event->getParameters()[
'VALUES']))
254 $entityId = $event->getParameters()[
'VALUES'][
'ID'];
257 $parameters = [
'FIELDS' => [
'ID' => $entityId]];
259 LoggerDiag::addMessage(mb_strtolower($eventName), var_export([
260 'processEvent [process-04]' => [
261 'parameters' => $parameters
268 throw new RestException(
"The Event \"{$eventName}\" is not supported in current context");