1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
notify.php
См. документацию.
1<?php
8
9namespace Bitrix\Sale;
10
11use Bitrix\Main;
12use Bitrix\Sale\Cashbox\CheckManager;
13use Bitrix\Sale\Cashbox\Internals\CashboxCheckTable;
14use Bitrix\Sale\Cashbox\Manager;
15use Bitrix\Sale\Compatible;
16use Bitrix\Sale\Internals;
17use Bitrix\Sale\Helpers;
18use Bitrix\Sale\TradingPlatform\Platform;
19
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 {
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
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->getUserId()]))
1231 {
1232 $userData = static::$cacheUserData[$order->getUserId()];
1233 if (!empty($userData['EMAIL']))
1234 {
1235 $userEmail = $userData['EMAIL'];
1236 }
1237 }
1238
1239 if (empty($userEmail))
1240 {
1242 if ($propertyCollection = $order->getPropertyCollection())
1243 {
1244 if ($propUserEmail = $propertyCollection->getUserEmail())
1245 {
1246 $userEmail = $propUserEmail->getValue();
1247 static::$cacheUserData[$order->getUserId()]['EMAIL'] = $userEmail;
1248 }
1249 }
1250 }
1251
1252 if (empty($userEmail))
1253 {
1254 $userData = self::getUserById($order->getUserId());
1255 if ($userData)
1256 {
1257 $userEmail = $userData['EMAIL'];
1258 static::$cacheUserData[$order->getUserId()]['EMAIL'] = $userData['EMAIL'];
1259 }
1260 }
1261
1262 return $userEmail;
1263 }
1264
1271 protected static function getUserName(Order $order)
1272 {
1273 $userName = "";
1274
1275 if (!empty(static::$cacheUserData[$order->getUserId()]))
1276 {
1277 $userData = static::$cacheUserData[$order->getUserId()];
1278 if (!empty($userData['PAYER_NAME']))
1279 {
1280 $userName = $userData['PAYER_NAME'];
1281 }
1282 }
1283
1284 if (empty($userName))
1285 {
1287 if ($propertyCollection = $order->getPropertyCollection())
1288 {
1289 if ($propPayerName = $propertyCollection->getPayerName())
1290 {
1291 $userName = $propPayerName->getValue();
1292 static::$cacheUserData[$order->getUserId()]['PAYER_NAME'] = $userName;
1293 }
1294 }
1295 }
1296
1297 if (empty($userName))
1298 {
1299 $userData = self::getUserById($order->getUserId());
1300 if ($userData)
1301 {
1302 $userName = \CUser::FormatName(\CSite::GetNameFormat(null, $order->getSiteId()), $userData, true);
1303 static::$cacheUserData[$order->getUserId()]['PAYER_NAME'] = $userName;
1304 }
1305 }
1306
1307 return $userName;
1308 }
1309
1310 private static function getUserById(int $userId)
1311 {
1312 static $userData = array();
1313
1314 if (isset($userData[$userId]))
1315 {
1316 return $userData[$userId];
1317 }
1318
1319 $row = Main\UserTable::getRow([
1320 'select' => [
1321 'ID',
1322 'LOGIN',
1323 'NAME',
1324 'LAST_NAME',
1325 'SECOND_NAME',
1326 'EMAIL',
1327 ],
1328 'filter' => [
1329 '=ID' => $userId,
1330 ],
1331 ]);
1332
1333 $userData[$userId] = $row ?: [];
1334
1335 return $userData[$userId];
1336 }
1337
1343 protected static function getAllFieldsFromOrder(Order $order)
1344 {
1345 $result = new Result();
1346
1347 $paymentSystemId = false;
1348 $deliveryId = false;
1349
1351 if ($paymentCollection = $order->getPaymentCollection())
1352 {
1354 if ($payment = $paymentCollection->rewind())
1355 {
1356 $paymentSystemId = $payment->getPaymentSystemId();
1357 }
1358 }
1359
1361 if ($shipmentCollection = $order->getShipmentCollection())
1362 {
1364 foreach ($shipmentCollection as $shipment)
1365 {
1366 if ($shipment->getDeliveryId() > 0)
1367 {
1368 $deliveryId = $shipment->getDeliveryId();
1369 break;
1370 }
1371 }
1372 }
1373
1374 $fields = array(
1375 "SITE_ID" => $order->getSiteId(),
1376 "LID" => $order->getSiteId(),
1377 "PERSON_TYPE_ID" => $order->getPersonTypeId(),
1378 "PRICE" => $order->getPrice(),
1379 "CURRENCY" => $order->getCurrency(),
1380 "USER_ID" => $order->getUserId(),
1381 "PAY_SYSTEM_ID" => $paymentSystemId,
1382 "PRICE_DELIVERY" => $order->getDeliveryPrice(),
1383 "DELIVERY_ID" => $deliveryId,
1384 "DISCOUNT_VALUE" => $order->getDiscountPrice(),
1385 "TAX_VALUE" => $order->getTaxValue(),
1386 "TRACKING_NUMBER" => $order->getField('TRACKING_NUMBER'),
1387 "PAYED" => $order->getField('PAYED'),
1388 "CANCELED" => $order->getField('CANCELED'),
1389 "STATUS_ID" => $order->getField('STATUS_ID'),
1390 "RESERVED" => $order->getField('RESERVED'),
1391 );
1392
1393 $orderFields = static::getOrderFields($order);
1394 if (is_array($orderFields))
1395 {
1396 $orderFields = $fields + $orderFields;
1397 $orderFields = static::convertDateFieldsToOldFormat($orderFields);
1398 }
1399
1400 $result->setData([
1401 'FIELDS' => $fields,
1402 'ORDER_FIELDS' => $orderFields,
1403 ]);
1404
1405 return $result;
1406 }
1407
1414 protected static function getOrderFields(Order $order)
1415 {
1416 $fields = $order->getFieldValues();
1417 $fields = array_merge(
1418 $fields,
1419 [
1420 'ORDER_ID' => $order->getId(),
1421 'ORDER_WEIGHT' => 0,
1422 'BASKET_ITEMS' => [],
1423 'ORDER_PROP' => [],
1424 'DISCOUNT_LIST' => [],
1425 'TAX_LIST' => [],
1426 'VAT_RATE' => $order->getVatRate(),
1427 'VAT_SUM' => $order->getVatSum(),
1428 ]);
1429
1431 if ($basket = $order->getBasket())
1432 {
1434 foreach ($basket as $basketItem)
1435 {
1436 $fields['BASKET_ITEMS'][] = static::getBasketItemFields($basketItem);
1437 }
1438
1439 $fields['ORDER_WEIGHT'] = $basket->getWeight();
1440 }
1441
1443 if ($propertyCollection = $order->getPropertyCollection())
1444 {
1446 foreach ($propertyCollection as $property)
1447 {
1448 $fields['ORDER_PROP'][$property->getPropertyId()] = $property->getValue();
1449 }
1450 }
1451
1452
1453 if ($propProfileName = $propertyCollection->getProfileName())
1454 {
1455 $fields['PROFILE_NAME'] = $propProfileName->getValue();
1456 }
1457
1458 if ($propPayerName = $propertyCollection->getPayerName())
1459 {
1460 $fields['PAYER_NAME'] = $propPayerName->getValue();
1461 }
1462
1463 if ($propUserEmail = $propertyCollection->getUserEmail())
1464 {
1465 $fields['USER_EMAIL'] = $propUserEmail->getValue();
1466 }
1467
1468 if ($propDeliveryLocationZip = $propertyCollection->getDeliveryLocationZip())
1469 {
1470 $fields['DELIVERY_LOCATION_ZIP'] = $propDeliveryLocationZip->getValue();
1471 }
1472
1473 if ($propDeliveryLocation = $propertyCollection->getDeliveryLocation())
1474 {
1475 $fields['DELIVERY_LOCATION'] = $propDeliveryLocation->getValue();
1476 }
1477
1478 if ($propTaxLocation = $propertyCollection->getTaxLocation())
1479 {
1480 $fields['TAX_LOCATION'] = $propTaxLocation->getValue();
1481 }
1482
1483 $fields['DISCOUNT_LIST'] = Compatible\DiscountCompatibility::getOldDiscountResult();
1484
1486 if ($tax = $order->getTax())
1487 {
1488 $fields['TAX_LIST'] = $tax->getTaxList();
1489 }
1490
1491 return $fields;
1492 }
1493
1500 protected static function getBasketItemFields(BasketItem $basketItem)
1501 {
1502 $fields = $basketItem->getFieldValues();
1503
1505 if (!$basket = $basketItem->getCollection())
1506 {
1507 throw new Main\ObjectNotFoundException('Entity "Basket" not found');
1508 }
1509
1510 if (empty($fields['LID']))
1511 {
1512 $fields['LID'] = $basket->getSiteId();
1513 }
1514
1515 if (empty($fields['LID']))
1516 {
1517 if ($order = $basket->getOrder())
1518 {
1519 $fields['LID'] = $order->getField('LID');
1520 }
1521 }
1522
1523 if (empty($fields['FUSER_ID']))
1524 {
1525 $fields['FUSER_ID'] = $basket->getFUserId(true);
1526 }
1527
1528
1530 if ($propertyCollection = $basketItem->getPropertyCollection())
1531 {
1532 $fields['PROPS'] = $propertyCollection->getPropertyValues();
1533 }
1534
1535 return $fields;
1536 }
1537
1543 public static function getOrderLanguageId(Order $order)
1544 {
1545 $siteData = Main\SiteTable::GetById($order->getSiteId())->fetch();
1546 return $siteData['LANGUAGE_ID'];
1547 }
1548
1556 {
1557 $resultList = array();
1558 foreach ($fields as $k => $value)
1559 {
1560 $valueString = static::convertDateFieldToOldFormat($value);
1561 $resultList[$k] = $valueString;
1562 }
1563
1564 return $resultList;
1565 }
1566
1573 protected static function convertDateFieldToOldFormat($value)
1574 {
1575 $setValue = $value;
1576
1577 if ($value instanceof Main\Type\Date)
1578 {
1579 $setValue = $value->toString();
1580 }
1581
1582 return $setValue;
1583 }
1584
1591 private static function hasSentEvent($code, $event)
1592 {
1593 if (!array_key_exists($code, static::$sentEventList))
1594 {
1595 return false;
1596 }
1597
1598 if (in_array($event, static::$sentEventList[$code]))
1599 {
1600 return true;
1601 }
1602
1603 return false;
1604 }
1605
1612 private static function addSentEvent($code, $event)
1613 {
1614 if (!static::hasSentEvent($code, $event))
1615 {
1616 static::$sentEventList[$code][] = $event;
1617
1618 return true;
1619 }
1620
1621 return false;
1622 }
1623
1628 public static function callNotify(Internals\Entity $entity, $eventName)
1629 {
1630 $eventNotifyMap = EventActions::getEventNotifyMap();
1631
1632 if (isset($eventNotifyMap[$eventName]))
1633 {
1634 if ($entity instanceof $eventNotifyMap[$eventName]['ENTITY'])
1635 {
1636 call_user_func_array($eventNotifyMap[$eventName]['METHOD'], [$entity]);
1637 }
1638 }
1639 }
1640
1644 public static function setNotifyDisable($value)
1645 {
1646 static::$disableNotify = ($value === true);
1648 }
1649
1653 public static function isNotifyDisabled()
1654 {
1655 return static::$disableNotify;
1656 }
1657}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static loadMessages($file)
Определения loc.php:65
Определения date.php:9
Определения notify.php:23
const EVENT_ON_CHECK_VALIDATION_ERROR_SEND_EMAIL
Определения notify.php:36
__construct()
Определения notify.php:69
static $sentEventList
Определения notify.php:65
const EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME
Определения notify.php:53
static getOrderLanguageId(Order $order)
Определения notify.php:1543
static sendCheckValidationError(Internals\Entity $order)
Определения notify.php:1184
const EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME
Определения notify.php:42
static sendOrderCancel(Internals\Entity $entity)
Определения notify.php:198
const EVENT_ORDER_STATUS_EMAIL
Определения notify.php:26
const EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL
Определения notify.php:31
const EVENT_DEFAULT_STATUS_CHANGED_ID
Определения notify.php:49
const EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME
Определения notify.php:43
static $disableNotify
Определения notify.php:67
static setNotifyDisable($value)
Определения notify.php:1644
static convertDateFieldsToOldFormat(array $fields)
Определения notify.php:1555
const EVENT_ORDER_STATUS_CHANGED_SEND_EMAIL_EVENT_NAME
Определения notify.php:45
static $cacheUserData
Определения notify.php:63
static sendOrderPaid(Internals\Entity $entity)
Определения notify.php:272
const EVENT_ORDER_STATUS_SEND_EMAIL
Определения notify.php:25
const EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL
Определения notify.php:54
const EVENT_MOBILE_PUSH_ORDER_CREATED
Определения notify.php:56
const EVENT_MOBILE_PUSH_ORDER_PAID
Определения notify.php:59
const EVENT_SHIPMENT_STATUS_SEND_EMAIL
Определения notify.php:50
const EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME
Определения notify.php:46
const EVENT_ON_ORDER_NEW_SEND_EMAIL
Определения notify.php:28
const EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME
Определения notify.php:29
const EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL
Определения notify.php:35
static callNotify(Internals\Entity $entity, $eventName)
Определения notify.php:1628
const EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR
Определения notify.php:60
const EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY
Определения notify.php:61
const EVENT_ON_ORDER_CANCEL_SEND_EMAIL
Определения notify.php:40
const EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME
Определения notify.php:32
const EVENT_ORDER_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME
Определения notify.php:44
const EVENT_ON_ORDER_PAID_SEND_EMAIL
Определения notify.php:38
const EVENT_ON_CHECK_PRINT_SEND_EMAIL
Определения notify.php:34
static convertDateFieldToOldFormat($value)
Определения notify.php:1573
static getRegistryType()
Определения notify.php:74
const EVENT_MOBILE_PUSH_ORDER_CANCELED
Определения notify.php:58
const EVENT_SHIPMENT_STATUS_EMAIL
Определения notify.php:51
static isNotifyDisabled()
Определения notify.php:1653
const EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE
Определения notify.php:57
const TYPE
Определения orderstatus.php:14
const REGISTRY_TYPE_ORDER
Определения registry.php:16
const LINK_TYPE_PUBLIC_DETAIL_ORDER
Определения platform.php:20
static send($eventId, $arParams)
Определения mobile_order.php:1088
static GetByID($statusId, $languageId=LANGUAGE_ID, $type=null)
Определения status.php:23
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$entity
$filter
Определения iblock_catalog_list.php:54
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
IsModuleInstalled($module_id)
Определения tools.php:5301
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
$platform
Определения settings.php:7
Определения tools.php:2
Order
Определения order.php:6
Определения ufield.php:9
Определения collection.php:2
$payment
Определения payment.php:14
$order
Определения payment.php:8
$paymentCollection
Определения payment.php:11
$dateInsert
Определения payment.php:19
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
else $userName
Определения order_form.php:75
SaleFormatCurrency($fSum, $strCurrency, $OnlyValue=false, $withoutFormat=false)
Определения include.php:142
$eventManager
Определения include.php:412
const SITE_ID
Определения sonet_set_content_view.php:12
$k
Определения template_pdf.php:567
$dbRes
Определения yandex_detail.php:168
$fields
Определения yandex_run.php:501