Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notify.php
1<?php
9namespace Bitrix\Sale;
10
11use Bitrix\Main;
19
20Main\Localization\Loc::loadMessages(__FILE__);
21
22class Notify
23{
24
25 const EVENT_ORDER_STATUS_SEND_EMAIL = "OnOrderStatusSendEmail";
26 const EVENT_ORDER_STATUS_EMAIL = "OnSaleStatusEMail";
27
28 const EVENT_ON_ORDER_NEW_SEND_EMAIL = "OnOrderNewSendEmail";
29 const EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME = "SALE_NEW_ORDER";
30
31 const EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL = "OnOrderDeliverSendEmail";
32 const EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_DELIVERY";
33
34 const EVENT_ON_CHECK_PRINT_SEND_EMAIL = "SALE_CHECK_PRINT";
35 const EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL = "SALE_CHECK_PRINT_ERROR";
36 const EVENT_ON_CHECK_VALIDATION_ERROR_SEND_EMAIL = "SALE_CHECK_VALIDATION_ERROR";
37
38 const EVENT_ON_ORDER_PAID_SEND_EMAIL = "OnOrderPaySendEmail";
39
40 const EVENT_ON_ORDER_CANCEL_SEND_EMAIL = "OnOrderCancelSendEmail";
41
42 const EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_PAID";
43 const EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_CANCEL";
44 const EVENT_ORDER_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_TRACKING_NUMBER";
46 const EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_TRACKING_NUMBER";
47
48
49 const EVENT_DEFAULT_STATUS_CHANGED_ID = "SALE_STATUS_CHANGED_";
50 const EVENT_SHIPMENT_STATUS_SEND_EMAIL = "OnSaleShipmentStatusSendEmail";
51 const EVENT_SHIPMENT_STATUS_EMAIL = "OnSaleShipmentStatusEMail";
52
53 const EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_ALLOW_PAY";
54 const EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL = "OnSaleOrderAllowPayStatusEMail";
55
56 const EVENT_MOBILE_PUSH_ORDER_CREATED = "ORDER_CREATED";
57 const EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE = "ORDER_STATUS_CHANGED";
58 const EVENT_MOBILE_PUSH_ORDER_CANCELED = "ORDER_CANCELED";
59 const EVENT_MOBILE_PUSH_ORDER_PAID = "ORDER_PAYED";
60 const EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR = "ORDER_CHECK_ERROR";
61 const EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY = "ORDER_DELIVERY_ALLOWED";
62
63 protected static $cacheUserData = array();
64
65 protected static $sentEventList = array();
66
67 protected static $disableNotify = false;
68
69 protected function __construct() {}
70
74 public static function getRegistryType()
75 {
76 return Registry::REGISTRY_TYPE_ORDER;
77 }
78
86 public static function sendOrderNew(Internals\Entity $entity)
87 {
88 $result = new Result();
89
90 if (static::isNotifyDisabled())
91 {
92 return $result;
93 }
94
95 if (!$entity instanceof Order)
96 {
97 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
98 }
99
100 if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME))
101 {
102 return $result;
103 }
104
105 if (!$entity->isNew())
106 {
107 return $result;
108 }
109
110 $separator = "<br/>";
111
112 $eventName = static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME;
113
114 $filter = array(
115 "EVENT_NAME" => $eventName,
116 "EVENT_NAME_EXACT_MATCH" => 'Y',
117 'ACTIVE' => 'Y',
118 );
119
120 if ($entity instanceof OrderBase)
121 {
122 $filter['SITE_ID'] = $entity->getSiteId();
123 }
124 elseif (defined('SITE_ID') && SITE_ID != '')
125 {
126 $filter['SITE_ID'] = SITE_ID;
127 }
128
129 $res = \CEventMessage::GetList('', '', $filter);
130 if ($eventMessage = $res->Fetch())
131 {
132 if ($eventMessage['BODY_TYPE'] == 'text')
133 {
134 $separator = "\n";
135 }
136 }
137
138 $basketList = '';
140 $basket = $entity->getBasket();
141 if ($basket)
142 {
143 $basketTextList = $basket->getListOfFormatText();
144 if (!empty($basketTextList))
145 {
146 foreach ($basketTextList as $basketItemCode => $basketItemData)
147 {
148 $basketList .= $basketItemData.$separator;
149 }
150 }
151 }
152
153 $fields = Array(
154 "ORDER_ID" => $entity->getField("ACCOUNT_NUMBER"),
155 "ORDER_REAL_ID" => $entity->getField("ID"),
156 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($entity->getField("ACCOUNT_NUMBER"))),
157 "ORDER_DATE" => $entity->getDateInsert()->toString(),
158 "ORDER_USER" => static::getUserName($entity),
159 "PRICE" => SaleFormatCurrency($entity->getPrice(), $entity->getCurrency()),
160 "BCC" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
161 "EMAIL" => static::getUserEmail($entity),
162 "ORDER_LIST" => $basketList,
163 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
164 "DELIVERY_PRICE" => $entity->getDeliveryPrice(),
165 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($entity) ? Helpers\Order::getPublicLink($entity) : ""
166 );
167
168 $send = true;
169
170 foreach(GetModuleEvents("sale", static::EVENT_ON_ORDER_NEW_SEND_EMAIL, true) as $oldEvent)
171 {
172 if (ExecuteModuleEventEx($oldEvent, array($entity->getId(), &$eventName, &$fields)) === false)
173 {
174 $send = false;
175 }
176 }
177
178 if($send)
179 {
180 $event = new \CEvent;
181 $event->Send($eventName, $entity->getField('LID'), $fields, "Y", "", array(),static::getOrderLanguageId($entity));
182 }
183
184 static::addSentEvent($entity->getId(), static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME);
185
186 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_CREATED, array("ORDER" => static::getOrderFields($entity)));
187
188 return $result;
189 }
190
198 public static function sendOrderCancel(Internals\Entity $entity)
199 {
200 $result = new Result();
201
202 if (static::isNotifyDisabled())
203 {
204 return $result;
205 }
206
207
208 if (!$entity instanceof Order)
209 {
210 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
211 }
212
213 if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME))
214 {
215 return $result;
216 }
217
218 if (!$entity->isCanceled())
219 {
220 return $result;
221 }
222
223 $fields = Array(
224 "ORDER_ID" => $entity->getField("ACCOUNT_NUMBER"),
225 "ORDER_REAL_ID" => $entity->getField("ID"),
226 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($entity->getField("ACCOUNT_NUMBER"))),
227 "ORDER_DATE" => '',
228 "EMAIL" => static::getUserEmail($entity),
229 "ORDER_CANCEL_DESCRIPTION" => $entity->getField('REASON_CANCELED'),
230 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
231 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($entity) ? Helpers\Order::getPublicLink($entity) : ""
232 );
233
234 $dateInsert = $entity->getDateInsert();
235 if (isset($dateInsert) && $dateInsert instanceof Main\Type\Date)
236 {
237 $fields['ORDER_DATE'] = $dateInsert->toString();
238 }
239
240
241 $eventName = static::EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME;
242 $send = true;
243
244 foreach(GetModuleEvents("sale", static::EVENT_ON_ORDER_CANCEL_SEND_EMAIL, true) as $oldEvent)
245 {
246 if (ExecuteModuleEventEx($oldEvent, array($entity->getId(), &$eventName, &$fields)) === false)
247 {
248 $send = false;
249 }
250 }
251
252 if($send)
253 {
254 $event = new \CEvent;
255 $event->Send($eventName, $entity->getField('LID'), $fields, "Y", "", array(), static::getOrderLanguageId($entity));
256 }
257
258 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_CANCELED, array("ORDER" => static::getOrderFields($entity)));
259
260 static::addSentEvent($entity->getId(), static::EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME);
261
262 return $result;
263 }
264
272 public static function sendOrderPaid(Internals\Entity $entity)
273 {
274 $result = new Result();
275
276 if (static::isNotifyDisabled())
277 {
278 return $result;
279 }
280
281 if (!$entity instanceof Order)
282 {
283 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
284 }
285
286 if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME))
287 {
288 return $result;
289 }
290
291 if (!$entity->isPaid())
292 {
293 return $result;
294 }
295
296
297
298 $fields = Array(
299 "ORDER_ID" => $entity->getField("ACCOUNT_NUMBER"),
300 "ORDER_REAL_ID" => $entity->getField("ID"),
301 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($entity->getField("ACCOUNT_NUMBER"))),
302 "ORDER_DATE" => '',
303 "EMAIL" => static::getUserEmail($entity),
304 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
305 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($entity) ? Helpers\Order::getPublicLink($entity) : ""
306 );
307 $dateInsert = $entity->getDateInsert();
308 if (isset($dateInsert) && $dateInsert instanceof Main\Type\Date)
309 {
310 $fields['ORDER_DATE'] = $dateInsert->toString();
311 }
312
313 $eventName = static::EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME;
314 $send = true;
315
316 foreach(GetModuleEvents("sale", static::EVENT_ON_ORDER_PAID_SEND_EMAIL, true) as $oldEvent)
317 {
318 if (ExecuteModuleEventEx($oldEvent, array($entity->getId(), &$eventName, &$fields)) === false)
319 {
320 $send = false;
321 }
322 }
323
324 if($send)
325 {
326 $event = new \CEvent;
327 $event->Send($eventName, $entity->getField('LID'), $fields, "Y", "", array(), static::getOrderLanguageId($entity));
328 }
329
330 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_PAID, array("ORDER" => static::getOrderFields($entity)));
331
332 static::addSentEvent($entity->getId(), static::EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME);
333
334 return $result;
335 }
336
344 public static function sendOrderStatusChange(Internals\Entity $entity)
345 {
346 $result = new Result();
347
348 if (static::isNotifyDisabled())
349 {
350 return $result;
351 }
352
353 if (!$entity instanceof Order)
354 {
355 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
356 }
357
358 $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
359
360 if (static::hasSentEvent($entity->getId(), $statusEventName))
361 {
362 return $result;
363 }
364
366 $fields = $entity->getFields();
367 $originalValues = $fields->getOriginalValues();
368
369 if (array_key_exists('STATUS_ID', $originalValues) && $originalValues['STATUS_ID'] == $entity->getField("STATUS_ID"))
370 {
371 return $result;
372 }
373
374 static $cacheSiteData = array();
375
376 if (!isset($cacheSiteData[$entity->getSiteId()]))
377 {
378 $siteRes = \CSite::GetByID($entity->getSiteId());
379 $siteData = $siteRes->Fetch();
380 }
381 else
382 {
383 $siteData = $cacheSiteData[$entity->getSiteId()];
384 }
385
386 if (($statusData = \CSaleStatus::GetByID($entity->getField("STATUS_ID"), $siteData['LANGUAGE_ID'])) && $statusData['NOTIFY'] == "Y")
387 {
388 $fields = Array(
389 "ORDER_ID" => $entity->getField("ACCOUNT_NUMBER"),
390 "ORDER_REAL_ID" => $entity->getField("ID"),
391 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($entity->getField("ACCOUNT_NUMBER"))),
392 "ORDER_STATUS" => $statusData["NAME"],
393 "EMAIL" => static::getUserEmail($entity),
394 "ORDER_DESCRIPTION" => $statusData["DESCRIPTION"],
395 "TEXT" => "",
396 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
397 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($entity) ? Helpers\Order::getPublicLink($entity) : ""
398 );
399
400 if ($entity->getField("DATE_INSERT") instanceof Main\Type\Date)
401 {
402 $fields['ORDER_DATE'] = $entity->getField("DATE_INSERT")->toString();
403 }
404
405 foreach(GetModuleEvents("sale", static::EVENT_ORDER_STATUS_EMAIL, true) as $oldEvent)
406 {
407 $fields["TEXT"] = ExecuteModuleEventEx($oldEvent, array($entity->getId(), $statusData["ID"]));
408 }
409
410 $eventName = $statusEventName;
411
412 $isSend = true;
413 foreach(GetModuleEvents("sale", static::EVENT_ORDER_STATUS_SEND_EMAIL, true) as $oldEvent)
414 {
415 if (ExecuteModuleEventEx($oldEvent, Array($entity->getId(), &$eventName, &$fields, $entity->getField("STATUS_ID")))===false)
416 {
417 $isSend = false;
418 }
419 }
420
421 if($isSend)
422 {
423 $eventMessage = new \CEventMessage;
424 $eventMessageRes = $eventMessage->GetList(
425 '',
426 '',
427 array(
428 "EVENT_NAME" => $eventName,
429 "EVENT_NAME_EXACT_MATCH" => 'Y',
430 "SITE_ID" => $entity->getSiteId(),
431 'ACTIVE' => 'Y'
432 )
433 );
434 if (!($eventMessageData = $eventMessageRes->Fetch()))
435 {
436 $eventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
437 }
438
439 unset($o, $b);
440 $event = new \CEvent;
441 $event->Send($eventName, $entity->getSiteId(), $fields, "Y", "", array(), $siteData['LANGUAGE_ID']);
442 }
443 }
444
445 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE, array("ORDER" => static::getOrderFields($entity)));
446
447 static::addSentEvent($entity->getId(), $statusEventName);
448
449 return $result;
450 }
451
459 public static function sendShipmentStatusChange(Internals\Entity $entity)
460 {
461 $result = new Result();
462
463 if (static::isNotifyDisabled())
464 {
465 return $result;
466 }
467
468 if (!$entity instanceof Shipment)
469 {
470 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Shipment');
471 }
472
473 $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
474
475 if (static::hasSentEvent('s'.$entity->getId(), $statusEventName))
476 {
477 return $result;
478 }
479
481 $fields = $entity->getFields();
482 $originalValues = $fields->getOriginalValues();
483
484 if (array_key_exists('STATUS_ID', $originalValues) && $originalValues['STATUS_ID'] == $entity->getField("STATUS_ID"))
485 {
486 return $result;
487 }
488
489 static $cacheSiteData = array();
490
492 if (!$shipmentCollection = $entity->getCollection())
493 {
494 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
495 return $result;
496 }
497
499 if (!$order = $shipmentCollection->getOrder())
500 {
501 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
502 return $result;
503 }
504
505
506 if (!isset($cacheSiteData[$order->getSiteId()]))
507 {
508 $siteRes = \CSite::GetByID($order->getSiteId());
509 $siteData = $siteRes->Fetch();
510 }
511 else
512 {
513 $siteData = $cacheSiteData[$order->getSiteId()];
514 }
515
516 $statusData = Internals\StatusTable::getList([
517 'select' => [
518 'ID',
519 'NOTIFY',
520 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME',
521 ],
522 'filter' => [
523 '=ID' => $entity->getField("STATUS_ID"),
524 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => $siteData['LANGUAGE_ID'],
525 '=TYPE' => DeliveryStatus::TYPE,
526 ],
527 'limit' => 1,
528 ])->fetch();
529
530 if (!empty($statusData) && $statusData['NOTIFY'] == "Y")
531 {
532 $isSend = true;
533
534 $fields = array(
535 "ORDER_ID" => $order->getField("ACCOUNT_NUMBER"),
536 "ORDER_REAL_ID" => $order->getField("ID"),
537 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
538 "ORDER_DATE" => $order->getDateInsert()->toString(),
539 "SHIPMENT_ID" => $entity->getId(),
540 "SHIPMENT_DATE" => $entity->getField("DATE_INSERT")->toString(),
541 "SHIPMENT_STATUS" => $statusData["NAME"],
542 "EMAIL" => static::getUserEmail($order),
543 "TEXT" => "",
544 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
545 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : ""
546 );
547
548 $eventManager = Main\EventManager::getInstance();
549 if ($eventsList = $eventManager->findEventHandlers('sale', static::EVENT_SHIPMENT_STATUS_EMAIL))
550 {
551 $event = new Main\Event('sale', static::EVENT_SHIPMENT_STATUS_EMAIL, array(
552 'EVENT_NAME' => $statusEventName,
553 'VALUES' => $fields
554 ));
555 $event->send();
556
557 if ($event->getResults())
558 {
560 foreach($event->getResults() as $eventResult)
561 {
562 if($eventResult->getType() === Main\EventResult::ERROR)
563 {
564 $isSend = false;
565 }
566 elseif($eventResult->getType() == Main\EventResult::SUCCESS)
567 {
568 if ($eventResultParams = $eventResult->getParameters())
569 {
571 if (!empty($eventResultParams) && is_array($eventResultParams))
572 {
573 if (!empty($eventResultParams['EVENT_NAME']))
574 {
575 $statusEventName = $eventResultParams['EVENT_NAME'];
576 }
577
578 if (!empty($eventResultParams['VALUES']) && is_array($eventResultParams['VALUES']))
579 {
580 $fields = $eventResultParams['VALUES'];
581 }
582 }
583 }
584 }
585 }
586 }
587 }
588
589 if($isSend)
590 {
591 $eventMessage = new \CEventMessage;
592 $eventMessageRes = $eventMessage->GetList(
593 '',
594 '',
595 array(
596 "EVENT_NAME" => $statusEventName,
597 "EVENT_NAME_EXACT_MATCH" => 'Y',
598 "SITE_ID" => $order->getSiteId(),
599 'ACTIVE' => 'Y'
600 )
601 );
602 if (!($eventMessageData = $eventMessageRes->Fetch()))
603 {
604 $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
605 }
606
607 unset($o, $b);
608 $event = new \CEvent;
609 $event->Send($statusEventName, $order->getSiteId(), $fields, "Y", "", array(), $siteData['LANGUAGE_ID']);
610 }
611 }
612
613 static::addSentEvent('s'.$entity->getId(), $statusEventName);
614
615 return $result;
616 }
617
625 public static function sendOrderAllowPayStatusChange(Internals\Entity $entity)
626 {
627 $result = new Result();
628
629 if (static::isNotifyDisabled())
630 {
631 return $result;
632 }
633
634 if (!$entity instanceof Order)
635 {
636 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
637 }
638
639 $statusEventName = static::EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME;
640
641 if (static::hasSentEvent($entity->getId(), $statusEventName))
642 {
643 return $result;
644 }
645
647 $fields = $entity->getFields();
648 $originalValues = $fields->getOriginalValues();
649
650 if (array_key_exists('STATUS_ID', $originalValues) && $originalValues['STATUS_ID'] == $entity->getField("STATUS_ID"))
651 {
652 return $result;
653 }
654
655 static $cacheSiteData = array();
656
657 if (!isset($cacheSiteData[$entity->getSiteId()]))
658 {
659 $siteRes = \CSite::GetByID($entity->getSiteId());
660 $siteData = $siteRes->Fetch();
661 }
662 else
663 {
664 $siteData = $cacheSiteData[$entity->getSiteId()];
665 }
666
667 $statusData = Internals\StatusTable::getList([
668 'select' => [
669 'ID',
670 'NOTIFY',
671 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME',
672 ],
673 'filter' => [
674 '=ID' => $entity->getField("STATUS_ID"),
675 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => $siteData['LANGUAGE_ID'],
676 '=TYPE' => OrderStatus::TYPE,
677 ],
678 'limit' => 1,
679 ])->fetch();
680
681 if (!empty($statusData) && $statusData['NOTIFY'] == "Y")
682 {
683 $isSend = true;
684
685 $fields = array(
686 "ORDER_ID" => $entity->getField("ACCOUNT_NUMBER"),
687 "ORDER_REAL_ID" => $entity->getField("ID"),
688 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($entity->getField("ACCOUNT_NUMBER"))),
689 "ORDER_DATE" => $entity->getDateInsert()->toString(),
690 "ORDER_STATUS" => $statusData["NAME"],
691 "EMAIL" => static::getUserEmail($entity),
692 "TEXT" => "",
693 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
694 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($entity) ? Helpers\Order::getPublicLink($entity) : ""
695 );
696
697 $eventManager = Main\EventManager::getInstance();
698 if ($eventsList = $eventManager->findEventHandlers('sale', static::EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL))
699 {
700 $event = new Main\Event('sale', static::EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL, array(
701 'EVENT_NAME' => $statusEventName,
702 'VALUES' => $fields
703 ));
704 $event->send();
705
706 if ($event->getResults())
707 {
709 foreach($event->getResults() as $eventResult)
710 {
711 if($eventResult->getType() === Main\EventResult::ERROR)
712 {
713 $isSend = false;
714 }
715 elseif($eventResult->getType() == Main\EventResult::SUCCESS)
716 {
717 if ($eventResultParams = $eventResult->getParameters())
718 {
720 if (!empty($eventResultParams) && is_array($eventResultParams))
721 {
722 if (!empty($eventResultParams['EVENT_NAME']))
723 {
724 $statusEventName = $eventResultParams['EVENT_NAME'];
725 }
726
727 if (!empty($eventResultParams['VALUES']) && is_array($eventResultParams['VALUES']))
728 {
729 $fields = $eventResultParams['VALUES'];
730 }
731 }
732 }
733 }
734 }
735 }
736 }
737
738 if($isSend)
739 {
740 $eventMessage = new \CEventMessage;
741 $eventMessageRes = $eventMessage->GetList(
742 '',
743 '',
744 array(
745 "EVENT_NAME" => $statusEventName,
746 "EVENT_NAME_EXACT_MATCH" => 'Y',
747 "SITE_ID" => $entity->getSiteId(),
748 'ACTIVE' => 'Y'
749 )
750 );
751 if (!($eventMessageData = $eventMessageRes->Fetch()))
752 {
753 $statusEventName = static::EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME;
754 }
755
756 unset($o, $b);
757 $event = new \CEvent;
758 $event->Send($statusEventName, $entity->getSiteId(), $fields, "Y", "", array(), $siteData['LANGUAGE_ID']);
759 }
760 }
761
762 static::addSentEvent($entity->getId(), $statusEventName);
763
764 return $result;
765 }
766
774 public static function sendShipmentTrackingNumberChange(Internals\Entity $entity)
775 {
776 $result = new Result();
777
778 if (static::isNotifyDisabled())
779 {
780 return $result;
781 }
782
783 if (!$entity instanceof Shipment)
784 {
785 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Shipment');
786 }
787
788 if (static::hasSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME))
789 {
790 return $result;
791 }
792
794 if (!$shipmentCollection = $entity->getCollection())
795 {
796 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
797 return $result;
798 }
799
801 if (!$order = $shipmentCollection->getOrder())
802 {
803 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
804 return $result;
805 }
806
808 $fields = $order->getFields();
809 $originalValues = $fields->getOriginalValues();
810
811 if (array_key_exists('ACCOUNT_NUMBER', $originalValues) && $originalValues['ACCOUNT_NUMBER'] == $order->getField("ACCOUNT_NUMBER"))
812 {
813 return $result;
814 }
815
816 $accountNumber = $order->getField("ACCOUNT_NUMBER");
817
818 $emailFields = Array(
819 "ORDER_ID" => $accountNumber,
820 "ORDER_REAL_ID" => $order->getField("ID"),
821 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
822 "ORDER_DATE" => $order->getDateInsert()->toString(),
823 "ORDER_USER" => static::getUserName($order),
824 "ORDER_TRACKING_NUMBER" => $entity->getField('TRACKING_NUMBER'),
825 "BCC" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER['SERVER_NAME']),
826 "EMAIL" => static::getUserEmail($order),
827 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER['SERVER_NAME']),
828 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : ""
829 );
830
831 $event = new \CEvent;
832 $event->send(static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME, $order->getField("LID"), $emailFields, "Y", "", array(), static::getOrderLanguageId($order));
833
834 static::addSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME);
835
836 return $result;
837 }
838
846 public static function sendShipmentAllowDelivery(Internals\Entity $entity)
847 {
848 $result = new Result();
849
850 if (static::isNotifyDisabled())
851 {
852 return $result;
853 }
854
855 if (!$entity instanceof Shipment)
856 {
857 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Shipment');
858 }
859
860 if (static::hasSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME))
861 {
862 return $result;
863 }
864
866 if (!$shipmentCollection = $entity->getCollection())
867 {
868 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
869 return $result;
870 }
871
873 if (!$order = $shipmentCollection->getOrder())
874 {
875 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
876 return $result;
877 }
878
879 if (!$order->isAllowDelivery())
880 {
881 return $result;
882 }
883
884
885 $fields = Array(
886 "ORDER_ID" => $order->getField("ACCOUNT_NUMBER"),
887 "ORDER_REAL_ID" => $order->getField("ID"),
888 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
889 "ORDER_DATE" => $order->getDateInsert()->toString(),
890 "SHIPMENT_ID" => $entity->getId(),
891 "SHIPMENT_DATE" => $entity->getField("DATE_INSERT")->toString(),
892 "EMAIL" => static::getUserEmail($order),
893 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
894 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : ""
895 );
896
897 $eventName = static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME;
898 $send = true;
899
900 foreach(GetModuleEvents("sale", static::EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL, true) as $oldEvent)
901 {
902 if (ExecuteModuleEventEx($oldEvent, array($order->getId(), &$eventName, &$fields)) === false)
903 {
904 $send = false;
905 }
906 }
907
908 if($send)
909 {
910 $event = new \CEvent;
911 $event->Send($eventName, $order->getField('LID'), $fields, "Y", "", array(), static::getOrderLanguageId($order));
912 }
913
914 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY, array("ORDER" => static::getOrderFields($order)));
915
916 static::addSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME);
917
918 return $result;
919 }
920
929 public static function sendPrintableCheck(Internals\Entity $entity)
930 {
931 $result = new Result();
932
933 if (static::isNotifyDisabled())
934 {
935 return $result;
936 }
937
938 if (!($entity instanceof Payment)
939 && !($entity instanceof Shipment)
940 )
941 {
942 return $result;
943 }
944
946 if (!$collection = $entity->getCollection())
947 {
948 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ENTITY_COLLECTION_NOT_FOUND")));
949 return $result;
950 }
951
953 if (!$order = $collection->getOrder())
954 {
955 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
956 return $result;
957 }
958
959 $check = CheckManager::getLastPrintableCheckInfo($entity);
960 if (!empty($check['LINK']))
961 {
962 $fields = array(
963 "ORDER_ID" => $order->getField("ACCOUNT_NUMBER"),
964 "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
965 "ORDER_USER" => static::getUserName($order),
966 "ORDER_DATE" => $order->getDateInsert()->toString(),
967 "EMAIL" => static::getUserEmail($order),
968 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
969 "CHECK_LINK" => $check['LINK'],
970 "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : "",
971 "LINK_URL" => static::getOrderPersonalDetailLink($order)
972 );
973
974 $info = static::getSiteInfo($order);
975 if ($info)
976 {
977 $fields["SITE_NAME"] = $info['TITLE'];
978 $fields["SERVER_NAME"] = $info['PUBLIC_URL'];
979 }
980
981 $eventName = static::EVENT_ON_CHECK_PRINT_SEND_EMAIL;
982 $event = new \CEvent;
983 $event->Send($eventName, $order->getField('LID'), $fields, "N");
984
985 if ($entity instanceof Payment)
986 {
987 static::addSentEvent('p'.$entity->getId(), $eventName);
988 }
989 elseif ($entity instanceof Shipment)
990 {
991 static::addSentEvent('s'.$entity->getId(), $eventName);
992 }
993 }
994
995 return $result;
996 }
997
1007 protected static function getSiteInfo(Order $order)
1008 {
1009 $collection = $order->getTradeBindingCollection();
1011 foreach ($collection as $tradeBinding)
1012 {
1013 $platform = $tradeBinding->getTradePlatform();
1014 if ($platform !== null)
1015 {
1016 return $platform->getInfo();
1017 }
1018 }
1019
1020 return [];
1021 }
1022
1032 protected static function getOrderPersonalDetailLink(Order $order)
1033 {
1034 $context = Main\Context::getCurrent();
1035 $server = $context->getServer();
1036
1037 $accountNumberEncode = urlencode(urlencode($order->getField("ACCOUNT_NUMBER")));
1038 $result = 'http://'.$server->getServerName().'/personal/order/detail/'.$accountNumberEncode.'/';
1039
1040 $collection = $order->getTradeBindingCollection();
1042 foreach ($collection as $tradeBinding)
1043 {
1044 $platform = $tradeBinding->getTradePlatform();
1045 if ($platform === null)
1046 {
1047 continue;
1048 }
1049
1050 $link = $platform->getExternalLink(Platform::LINK_TYPE_PUBLIC_DETAIL_ORDER, $order);
1051 if ($link)
1052 {
1053 $result = $link;
1054 }
1055
1056 break;
1057 }
1058
1059 return $result;
1060 }
1061
1072 public static function sendCheckError(Internals\Entity $entity)
1073 {
1074 $result = new Result();
1075
1076 if (static::isNotifyDisabled())
1077 {
1078 return $result;
1079 }
1080
1081 if (!($entity instanceof Payment)
1082 && !($entity instanceof Shipment)
1083 )
1084 {
1085 throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Payment or \Bitrix\Sale\Shipment');
1086 }
1087
1089 if (!$collection = $entity->getCollection())
1090 {
1091 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ENTITY_COLLECTION_NOT_FOUND")));
1092 return $result;
1093 }
1094
1096 if (!$order = $collection->getOrder())
1097 {
1098 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
1099 return $result;
1100 }
1101
1102 $filter = array('STATUS' => 'E');
1103 if ($entity instanceof Payment)
1104 {
1105 $filter['PAYMENT_ID'] = $entity->getId();
1106 }
1107 elseif ($entity instanceof Shipment)
1108 {
1109 $filter['SHIPMENT_ID'] = $entity->getId();
1110 }
1111
1112 $dbRes = CashboxCheckTable::getList(
1113 array(
1114 'select' => array('*'),
1115 'filter' => $filter,
1116 'order' => array('DATE_PRINT_END' => 'DESC'),
1117 'limit' => 1
1118 )
1119 );
1120 $check = $dbRes->fetch();
1121 if (!$check)
1122 {
1123 $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_CHECK_NOT_FOUND")));
1124 return $result;
1125 }
1126
1127 $cashbox = Manager::getCashboxFromCache($check['CASHBOX_ID']);
1128 if ($cashbox['EMAIL'])
1129 {
1130 $cashbox = Manager::getCashboxFromCache($check['CASHBOX_ID']);
1131
1132 $fields = array(
1133 "ORDER_ACCOUNT_NUMBER" => $order->getField("ACCOUNT_NUMBER"),
1134 "CHECK_ID" => $check['ID'],
1135 "ORDER_ID" => $order->getId(),
1136 "ORDER_DATE" => $order->getDateInsert()->toString(),
1137 "EMAIL" => $cashbox['EMAIL'],
1138 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
1139 );
1140
1141 $context = Main\Context::getCurrent();
1142 $server = $context->getServer();
1143
1144 if (IsModuleInstalled('crm'))
1145 {
1146 $fields['LINK_URL'] = 'http://'.$server->getServerName().'/shop/orders/details/'.$order->getId().'/';
1147 }
1148 else
1149 {
1150 $fields['LINK_URL'] = 'http://'.$server->getServerName().'/bitrix/admin/sale_order_view.php?ID='.$order->getId();
1151 }
1152
1153 $eventName = static::EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL;
1154 $event = new \CEvent;
1155 $event->Send($eventName, $order->getField('LID'), $fields, "N");
1156
1157 if ($entity instanceof Payment)
1158 {
1159 static::addSentEvent('p'.$entity->getId(), $eventName);
1160 }
1161 elseif ($entity instanceof Shipment)
1162 {
1163 static::addSentEvent('s'.$entity->getId(), $eventName);
1164 }
1165 }
1166
1167 \CSaleMobileOrderPush::send(
1168 static::EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR,
1169 array(
1170 'ORDER' => static::getOrderFields($order),
1171 'CHECK' => $check
1172 )
1173 );
1174
1175 return $result;
1176 }
1177
1184 public static function sendCheckValidationError(Internals\Entity $order)
1185 {
1186 $result = new Result();
1187
1188 if (static::isNotifyDisabled())
1189 {
1190 return $result;
1191 }
1192
1193 $context = Main\Context::getCurrent();
1194 $server = $context->getServer();
1195
1196 $fields = array(
1197 "ORDER_ID" => $order->getId(),
1198 "ORDER_ACCOUNT_NUMBER" => $order->getField("ACCOUNT_NUMBER"),
1199 "ORDER_DATE" => $order->getDateInsert()->toString(),
1200 "EMAIL" => Main\Config\Option::get("main", "email_from"),
1201 "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$server->getServerName()),
1202 );
1203
1204 if (IsModuleInstalled('crm'))
1205 {
1206 $fields['LINK_URL'] = 'http://'.$server->getServerName().'/shop/orders/details/'.$order->getId().'/';
1207 }
1208 else
1209 {
1210 $fields['LINK_URL'] = 'http://'.$server->getServerName().'/bitrix/admin/sale_order_view.php?ID='.$order->getId();
1211 }
1212
1213 $eventName = static::EVENT_ON_CHECK_VALIDATION_ERROR_SEND_EMAIL;
1214 $event = new \CEvent;
1215 $event->Send($eventName, $order->getField('LID'), $fields, "N");
1216
1217 return $result;
1218 }
1219
1226 protected static function getUserEmail(Order $order)
1227 {
1228 $userEmail = "";
1229
1230 if (!empty(static::$cacheUserData[$order->getId()]))
1231 {
1232 $userData = static::$cacheUserData[$order->getId()];
1233 if (!empty($userData['EMAIL']))
1234 {
1235 $userEmail = $userData['EMAIL'];
1236 }
1237 }
1238
1239
1240 if (empty($userEmail))
1241 {
1243 if ($propertyCollection = $order->getPropertyCollection())
1244 {
1245 if ($propUserEmail = $propertyCollection->getUserEmail())
1246 {
1247 $userEmail = $propUserEmail->getValue();
1248 static::$cacheUserData[$order->getId()]['EMAIL'] = $userEmail;
1249 }
1250 }
1251 }
1252
1253 if (empty($userEmail))
1254 {
1255 $userRes = Main\UserTable::getList([
1256 'select' => [
1257 'ID',
1258 'LOGIN',
1259 'NAME',
1260 'LAST_NAME',
1261 'SECOND_NAME',
1262 'EMAIL',
1263 ],
1264 'filter' => [
1265 '=ID' => $order->getUserId(),
1266 ],
1267 ]);
1268 if ($userData = $userRes->fetch())
1269 {
1270 static::$cacheUserData[$order->getId()] = $userData;
1271 $userEmail = $userData['EMAIL'];
1272 }
1273 }
1274
1275 return $userEmail;
1276 }
1277
1284 protected static function getUserName(Order $order)
1285 {
1286 $userName = "";
1287
1288 if (!empty(static::$cacheUserData[$order->getUserId()]))
1289 {
1290 $userData = static::$cacheUserData[$order->getUserId()];
1291 if (!empty($userData['USER_NAME']))
1292 {
1293 $userName = $userData['USER_NAME'];
1294 }
1295 }
1296
1297
1298 if (empty($userName))
1299 {
1301 if ($propertyCollection = $order->getPropertyCollection())
1302 {
1303 if ($propPayerName = $propertyCollection->getPayerName())
1304 {
1305 $userName = $propPayerName->getValue();
1306 static::$cacheUserData[$order->getUserId()]['PAYER_NAME'] = $userName;
1307 }
1308 }
1309 }
1310
1311 if (empty($userName))
1312 {
1313 $userRes = Main\UserTable::getList([
1314 'select' => [
1315 'ID',
1316 'LOGIN',
1317 'NAME',
1318 'LAST_NAME',
1319 'SECOND_NAME',
1320 'EMAIL',
1321 ],
1322 'filter' => [
1323 '=ID' => $order->getUserId(),
1324 ],
1325 ]);
1326 if ($userData = $userRes->fetch())
1327 {
1328 $userData['PAYER_NAME'] = \CUser::FormatName(\CSite::GetNameFormat(null, $order->getSiteId()), $userData, true);
1329 static::$cacheUserData[$order->getUserId()]['PAYER_NAME'] = $userData['PAYER_NAME'];
1330 $userName = $userData['PAYER_NAME'];
1331 }
1332 }
1333
1334 return $userName;
1335 }
1336
1342 protected static function getAllFieldsFromOrder(Order $order)
1343 {
1344 $result = new Result();
1345
1346 $paymentSystemId = false;
1347 $deliveryId = false;
1348
1350 if ($paymentCollection = $order->getPaymentCollection())
1351 {
1353 if ($payment = $paymentCollection->rewind())
1354 {
1355 $paymentSystemId = $payment->getPaymentSystemId();
1356 }
1357 }
1358
1360 if ($shipmentCollection = $order->getShipmentCollection())
1361 {
1363 foreach ($shipmentCollection as $shipment)
1364 {
1365 if ($shipment->getDeliveryId() > 0)
1366 {
1367 $deliveryId = $shipment->getDeliveryId();
1368 break;
1369 }
1370 }
1371 }
1372
1373 $fields = array(
1374 "SITE_ID" => $order->getSiteId(),
1375 "LID" => $order->getSiteId(),
1376 "PERSON_TYPE_ID" => $order->getPersonTypeId(),
1377 "PRICE" => $order->getPrice(),
1378 "CURRENCY" => $order->getCurrency(),
1379 "USER_ID" => $order->getUserId(),
1380 "PAY_SYSTEM_ID" => $paymentSystemId,
1381 "PRICE_DELIVERY" => $order->getDeliveryPrice(),
1382 "DELIVERY_ID" => $deliveryId,
1383 "DISCOUNT_VALUE" => $order->getDiscountPrice(),
1384 "TAX_VALUE" => $order->getTaxValue(),
1385 "TRACKING_NUMBER" => $order->getField('TRACKING_NUMBER'),
1386 "PAYED" => $order->getField('PAYED'),
1387 "CANCELED" => $order->getField('CANCELED'),
1388 "STATUS_ID" => $order->getField('STATUS_ID'),
1389 "RESERVED" => $order->getField('RESERVED'),
1390 );
1391
1392 $orderFields = static::getOrderFields($order);
1393 if (is_array($orderFields))
1394 {
1395 $orderFields = $fields + $orderFields;
1396 $orderFields = static::convertDateFieldsToOldFormat($orderFields);
1397 }
1398
1399 $result->setData([
1400 'FIELDS' => $fields,
1401 'ORDER_FIELDS' => $orderFields,
1402 ]);
1403
1404 return $result;
1405 }
1406
1413 protected static function getOrderFields(Order $order)
1414 {
1415 $fields = $order->getFieldValues();
1416 $fields = array_merge(
1417 $fields,
1418 [
1419 'ORDER_ID' => $order->getId(),
1420 'ORDER_WEIGHT' => 0,
1421 'BASKET_ITEMS' => [],
1422 'ORDER_PROP' => [],
1423 'DISCOUNT_LIST' => [],
1424 'TAX_LIST' => [],
1425 'VAT_RATE' => $order->getVatRate(),
1426 'VAT_SUM' => $order->getVatSum(),
1427 ]);
1428
1430 if ($basket = $order->getBasket())
1431 {
1433 foreach ($basket as $basketItem)
1434 {
1435 $fields['BASKET_ITEMS'][] = static::getBasketItemFields($basketItem);
1436 }
1437
1438 $fields['ORDER_WEIGHT'] = $basket->getWeight();
1439 }
1440
1442 if ($propertyCollection = $order->getPropertyCollection())
1443 {
1445 foreach ($propertyCollection as $property)
1446 {
1447 $fields['ORDER_PROP'][$property->getPropertyId()] = $property->getValue();
1448 }
1449 }
1450
1451
1452 if ($propProfileName = $propertyCollection->getProfileName())
1453 {
1454 $fields['PROFILE_NAME'] = $propProfileName->getValue();
1455 }
1456
1457 if ($propPayerName = $propertyCollection->getPayerName())
1458 {
1459 $fields['PAYER_NAME'] = $propPayerName->getValue();
1460 }
1461
1462 if ($propUserEmail = $propertyCollection->getUserEmail())
1463 {
1464 $fields['USER_EMAIL'] = $propUserEmail->getValue();
1465 }
1466
1467 if ($propDeliveryLocationZip = $propertyCollection->getDeliveryLocationZip())
1468 {
1469 $fields['DELIVERY_LOCATION_ZIP'] = $propDeliveryLocationZip->getValue();
1470 }
1471
1472 if ($propDeliveryLocation = $propertyCollection->getDeliveryLocation())
1473 {
1474 $fields['DELIVERY_LOCATION'] = $propDeliveryLocation->getValue();
1475 }
1476
1477 if ($propTaxLocation = $propertyCollection->getTaxLocation())
1478 {
1479 $fields['TAX_LOCATION'] = $propTaxLocation->getValue();
1480 }
1481
1482 $fields['DISCOUNT_LIST'] = Compatible\DiscountCompatibility::getOldDiscountResult();
1483
1485 if ($tax = $order->getTax())
1486 {
1487 $fields['TAX_LIST'] = $tax->getTaxList();
1488 }
1489
1490 return $fields;
1491 }
1492
1499 protected static function getBasketItemFields(BasketItem $basketItem)
1500 {
1501 $fields = $basketItem->getFieldValues();
1502
1504 if (!$basket = $basketItem->getCollection())
1505 {
1506 throw new Main\ObjectNotFoundException('Entity "Basket" not found');
1507 }
1508
1509 if (empty($fields['LID']))
1510 {
1511 $fields['LID'] = $basket->getSiteId();
1512 }
1513
1514 if (empty($fields['LID']))
1515 {
1516 if ($order = $basket->getOrder())
1517 {
1518 $fields['LID'] = $order->getField('LID');
1519 }
1520 }
1521
1522 if (empty($fields['FUSER_ID']))
1523 {
1524 $fields['FUSER_ID'] = $basket->getFUserId(true);
1525 }
1526
1527
1529 if ($propertyCollection = $basketItem->getPropertyCollection())
1530 {
1531 $fields['PROPS'] = $propertyCollection->getPropertyValues();
1532 }
1533
1534 return $fields;
1535 }
1536
1542 public static function getOrderLanguageId(Order $order)
1543 {
1544 $siteData = Main\SiteTable::GetById($order->getSiteId())->fetch();
1545 return $siteData['LANGUAGE_ID'];
1546 }
1547
1554 public static function convertDateFieldsToOldFormat(array $fields)
1555 {
1556 $resultList = array();
1557 foreach ($fields as $k => $value)
1558 {
1559 $valueString = static::convertDateFieldToOldFormat($value);
1560 $resultList[$k] = $valueString;
1561 }
1562
1563 return $resultList;
1564 }
1565
1572 protected static function convertDateFieldToOldFormat($value)
1573 {
1574 $setValue = $value;
1575
1576 if ($value instanceof Main\Type\Date)
1577 {
1578 $setValue = $value->toString();
1579 }
1580
1581 return $setValue;
1582 }
1583
1590 private static function hasSentEvent($code, $event)
1591 {
1592 if (!array_key_exists($code, static::$sentEventList))
1593 {
1594 return false;
1595 }
1596
1597 if (in_array($event, static::$sentEventList[$code]))
1598 {
1599 return true;
1600 }
1601
1602 return false;
1603 }
1604
1611 private static function addSentEvent($code, $event)
1612 {
1613 if (!static::hasSentEvent($code, $event))
1614 {
1615 static::$sentEventList[$code][] = $event;
1616
1617 return true;
1618 }
1619
1620 return false;
1621 }
1622
1627 public static function callNotify(Internals\Entity $entity, $eventName)
1628 {
1629 $eventNotifyMap = EventActions::getEventNotifyMap();
1630
1631 if (isset($eventNotifyMap[$eventName]))
1632 {
1633 if ($entity instanceof $eventNotifyMap[$eventName]['ENTITY'])
1634 {
1635 call_user_func_array($eventNotifyMap[$eventName]['METHOD'], [$entity]);
1636 }
1637 }
1638 }
1639
1643 public static function setNotifyDisable($value)
1644 {
1645 static::$disableNotify = ($value === true);
1646 Compatible\EventCompatibility::setDisableMailSend($value);
1647 }
1648
1652 public static function isNotifyDisabled()
1653 {
1654 return static::$disableNotify;
1655 }
1656}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
const EVENT_ON_CHECK_VALIDATION_ERROR_SEND_EMAIL
Definition notify.php:36
static $sentEventList
Definition notify.php:65
const EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME
Definition notify.php:53
static getOrderLanguageId(Order $order)
Definition notify.php:1542
static sendCheckValidationError(Internals\Entity $order)
Definition notify.php:1184
const EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME
Definition notify.php:42
static sendOrderCancel(Internals\Entity $entity)
Definition notify.php:198
const EVENT_ORDER_STATUS_EMAIL
Definition notify.php:26
const EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL
Definition notify.php:31
const EVENT_DEFAULT_STATUS_CHANGED_ID
Definition notify.php:49
const EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME
Definition notify.php:43
static $disableNotify
Definition notify.php:67
static setNotifyDisable($value)
Definition notify.php:1643
static convertDateFieldsToOldFormat(array $fields)
Definition notify.php:1554
const EVENT_ORDER_STATUS_CHANGED_SEND_EMAIL_EVENT_NAME
Definition notify.php:45
static $cacheUserData
Definition notify.php:63
static sendOrderPaid(Internals\Entity $entity)
Definition notify.php:272
const EVENT_ORDER_STATUS_SEND_EMAIL
Definition notify.php:25
const EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL
Definition notify.php:54
const EVENT_MOBILE_PUSH_ORDER_CREATED
Definition notify.php:56
const EVENT_MOBILE_PUSH_ORDER_PAID
Definition notify.php:59
const EVENT_SHIPMENT_STATUS_SEND_EMAIL
Definition notify.php:50
const EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME
Definition notify.php:46
const EVENT_ON_ORDER_NEW_SEND_EMAIL
Definition notify.php:28
const EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME
Definition notify.php:29
const EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL
Definition notify.php:35
static callNotify(Internals\Entity $entity, $eventName)
Definition notify.php:1627
const EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR
Definition notify.php:60
const EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY
Definition notify.php:61
const EVENT_ON_ORDER_CANCEL_SEND_EMAIL
Definition notify.php:40
const EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME
Definition notify.php:32
const EVENT_ORDER_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME
Definition notify.php:44
const EVENT_ON_ORDER_PAID_SEND_EMAIL
Definition notify.php:38
const EVENT_ON_CHECK_PRINT_SEND_EMAIL
Definition notify.php:34
static convertDateFieldToOldFormat($value)
Definition notify.php:1572
static getRegistryType()
Definition notify.php:74
const EVENT_MOBILE_PUSH_ORDER_CANCELED
Definition notify.php:58
const EVENT_SHIPMENT_STATUS_EMAIL
Definition notify.php:51
static isNotifyDisabled()
Definition notify.php:1652
const EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE
Definition notify.php:57