76 return Registry::REGISTRY_TYPE_ORDER;
86 public static function sendOrderNew(Internals\
Entity $entity)
90 if (static::isNotifyDisabled())
95 if (!$entity instanceof Order)
100 if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME))
105 if (!$entity->isNew())
110 $separator =
"<br/>";
112 $eventName = static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME;
115 "EVENT_NAME" => $eventName,
116 "EVENT_NAME_EXACT_MATCH" =>
'Y',
120 if ($entity instanceof OrderBase)
122 $filter[
'SITE_ID'] = $entity->getSiteId();
124 elseif (defined(
'SITE_ID') && SITE_ID !=
'')
126 $filter[
'SITE_ID'] = SITE_ID;
129 $res = \CEventMessage::GetList(
'',
'', $filter);
130 if ($eventMessage = $res->Fetch())
132 if ($eventMessage[
'BODY_TYPE'] ==
'text')
140 $basket = $entity->getBasket();
143 $basketTextList = $basket->getListOfFormatText();
144 if (!empty($basketTextList))
146 foreach ($basketTextList as $basketItemCode => $basketItemData)
148 $basketList .= $basketItemData.$separator;
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) :
""
170 foreach(GetModuleEvents(
"sale", static::EVENT_ON_ORDER_NEW_SEND_EMAIL,
true) as $oldEvent)
172 if (ExecuteModuleEventEx($oldEvent, array($entity->getId(), &$eventName, &$fields)) ===
false)
180 $event = new \CEvent;
181 $event->Send($eventName, $entity->getField(
'LID'), $fields,
"Y",
"", array(),static::getOrderLanguageId($entity));
184 static::addSentEvent($entity->getId(), static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME);
186 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_CREATED, array(
"ORDER" => static::getOrderFields($entity)));
202 if (static::isNotifyDisabled())
208 if (!$entity instanceof
Order)
213 if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME))
218 if (!$entity->isCanceled())
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"))),
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) :
""
234 $dateInsert = $entity->getDateInsert();
237 $fields[
'ORDER_DATE'] = $dateInsert->toString();
241 $eventName = static::EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME;
244 foreach(GetModuleEvents(
"sale", static::EVENT_ON_ORDER_CANCEL_SEND_EMAIL,
true) as $oldEvent)
246 if (ExecuteModuleEventEx($oldEvent, array($entity->getId(), &$eventName, &$fields)) ===
false)
254 $event = new \CEvent;
255 $event->Send($eventName, $entity->getField(
'LID'), $fields,
"Y",
"", array(), static::getOrderLanguageId($entity));
258 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_CANCELED, array(
"ORDER" => static::getOrderFields($entity)));
260 static::addSentEvent($entity->getId(), static::EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME);
276 if (static::isNotifyDisabled())
281 if (!$entity instanceof
Order)
286 if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME))
291 if (!$entity->isPaid())
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"))),
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) :
""
307 $dateInsert = $entity->getDateInsert();
310 $fields[
'ORDER_DATE'] = $dateInsert->toString();
313 $eventName = static::EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME;
316 foreach(GetModuleEvents(
"sale", static::EVENT_ON_ORDER_PAID_SEND_EMAIL,
true) as $oldEvent)
318 if (ExecuteModuleEventEx($oldEvent, array($entity->getId(), &$eventName, &$fields)) ===
false)
326 $event = new \CEvent;
327 $event->Send($eventName, $entity->getField(
'LID'), $fields,
"Y",
"", array(), static::getOrderLanguageId($entity));
330 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_PAID, array(
"ORDER" => static::getOrderFields($entity)));
332 static::addSentEvent($entity->getId(), static::EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME);
344 public static function sendOrderStatusChange(Internals\
Entity $entity)
348 if (static::isNotifyDisabled())
353 if (!$entity instanceof Order)
358 $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField(
"STATUS_ID");
360 if (static::hasSentEvent($entity->getId(), $statusEventName))
366 $fields = $entity->getFields();
367 $originalValues = $fields->getOriginalValues();
369 if (array_key_exists(
'STATUS_ID', $originalValues) && $originalValues[
'STATUS_ID'] == $entity->getField(
"STATUS_ID"))
374 static $cacheSiteData = array();
376 if (!isset($cacheSiteData[$entity->getSiteId()]))
378 $siteRes = \CSite::GetByID($entity->getSiteId());
379 $siteData = $siteRes->Fetch();
383 $siteData = $cacheSiteData[$entity->getSiteId()];
386 if (($statusData = \CSaleStatus::GetByID($entity->getField(
"STATUS_ID"), $siteData[
'LANGUAGE_ID'])) && $statusData[
'NOTIFY'] ==
"Y")
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"],
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) :
""
400 if ($entity->getField(
"DATE_INSERT") instanceof Main\
Type\Date)
402 $fields[
'ORDER_DATE'] = $entity->getField(
"DATE_INSERT")->toString();
405 foreach(GetModuleEvents(
"sale", static::EVENT_ORDER_STATUS_EMAIL,
true) as $oldEvent)
407 $fields[
"TEXT"] = ExecuteModuleEventEx($oldEvent, array($entity->getId(), $statusData[
"ID"]));
410 $eventName = $statusEventName;
413 foreach(GetModuleEvents(
"sale", static::EVENT_ORDER_STATUS_SEND_EMAIL,
true) as $oldEvent)
415 if (ExecuteModuleEventEx($oldEvent, Array($entity->getId(), &$eventName, &$fields, $entity->getField(
"STATUS_ID")))===
false)
423 $eventMessage = new \CEventMessage;
424 $eventMessageRes = $eventMessage->GetList(
428 "EVENT_NAME" => $eventName,
429 "EVENT_NAME_EXACT_MATCH" =>
'Y',
430 "SITE_ID" => $entity->getSiteId(),
434 if (!($eventMessageData = $eventMessageRes->Fetch()))
436 $eventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField(
"STATUS_ID");
440 $event = new \CEvent;
441 $event->Send($eventName, $entity->getSiteId(), $fields,
"Y",
"", array(), $siteData[
'LANGUAGE_ID']);
445 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE, array(
"ORDER" => static::getOrderFields($entity)));
447 static::addSentEvent($entity->getId(), $statusEventName);
459 public static function sendShipmentStatusChange(Internals\Entity $entity)
461 $result =
new Result();
463 if (static::isNotifyDisabled())
468 if (!$entity instanceof Shipment)
470 throw new Main\ArgumentTypeException(
'entity',
'\Bitrix\Sale\Shipment');
473 $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField(
"STATUS_ID");
475 if (static::hasSentEvent(
's'.$entity->getId(), $statusEventName))
481 $fields = $entity->getFields();
482 $originalValues = $fields->getOriginalValues();
484 if (array_key_exists(
'STATUS_ID', $originalValues) && $originalValues[
'STATUS_ID'] == $entity->getField(
"STATUS_ID"))
489 static $cacheSiteData = array();
492 if (!$shipmentCollection = $entity->getCollection())
494 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
499 if (!$order = $shipmentCollection->getOrder())
501 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ORDER_NOT_FOUND")));
506 if (!isset($cacheSiteData[$order->getSiteId()]))
508 $siteRes = \CSite::GetByID($order->getSiteId());
509 $siteData = $siteRes->Fetch();
513 $siteData = $cacheSiteData[$order->getSiteId()];
516 $statusData = Internals\StatusTable::getList([
520 'NAME' =>
'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME',
523 '=ID' => $entity->getField(
"STATUS_ID"),
524 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => $siteData[
'LANGUAGE_ID'],
525 '=TYPE' => DeliveryStatus::TYPE,
530 if (!empty($statusData) && $statusData[
'NOTIFY'] ==
"Y")
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),
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) :
""
548 $eventManager = Main\EventManager::getInstance();
549 if ($eventsList = $eventManager->findEventHandlers(
'sale', static::EVENT_SHIPMENT_STATUS_EMAIL))
551 $event =
new Main\Event(
'sale', static::EVENT_SHIPMENT_STATUS_EMAIL, array(
552 'EVENT_NAME' => $statusEventName,
557 if ($event->getResults())
560 foreach($event->getResults() as $eventResult)
562 if($eventResult->getType() === Main\EventResult::ERROR)
566 elseif($eventResult->getType() == Main\EventResult::SUCCESS)
568 if ($eventResultParams = $eventResult->getParameters())
571 if (!empty($eventResultParams) && is_array($eventResultParams))
573 if (!empty($eventResultParams[
'EVENT_NAME']))
575 $statusEventName = $eventResultParams[
'EVENT_NAME'];
578 if (!empty($eventResultParams[
'VALUES']) && is_array($eventResultParams[
'VALUES']))
580 $fields = $eventResultParams[
'VALUES'];
591 $eventMessage = new \CEventMessage;
592 $eventMessageRes = $eventMessage->GetList(
596 "EVENT_NAME" => $statusEventName,
597 "EVENT_NAME_EXACT_MATCH" =>
'Y',
598 "SITE_ID" => $order->getSiteId(),
602 if (!($eventMessageData = $eventMessageRes->Fetch()))
604 $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField(
"STATUS_ID");
608 $event = new \CEvent;
609 $event->Send($statusEventName, $order->getSiteId(), $fields,
"Y",
"", array(), $siteData[
'LANGUAGE_ID']);
613 static::addSentEvent(
's'.$entity->getId(), $statusEventName);
625 public static function sendOrderAllowPayStatusChange(Internals\Entity $entity)
627 $result =
new Result();
629 if (static::isNotifyDisabled())
634 if (!$entity instanceof Order)
636 throw new Main\ArgumentTypeException(
'entity',
'\Bitrix\Sale\Order');
639 $statusEventName = static::EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME;
641 if (static::hasSentEvent($entity->getId(), $statusEventName))
647 $fields = $entity->getFields();
648 $originalValues = $fields->getOriginalValues();
650 if (array_key_exists(
'STATUS_ID', $originalValues) && $originalValues[
'STATUS_ID'] == $entity->getField(
"STATUS_ID"))
655 static $cacheSiteData = array();
657 if (!isset($cacheSiteData[$entity->getSiteId()]))
659 $siteRes = \CSite::GetByID($entity->getSiteId());
660 $siteData = $siteRes->Fetch();
664 $siteData = $cacheSiteData[$entity->getSiteId()];
667 $statusData = Internals\StatusTable::getList([
671 'NAME' =>
'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME',
674 '=ID' => $entity->getField(
"STATUS_ID"),
675 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => $siteData[
'LANGUAGE_ID'],
676 '=TYPE' => OrderStatus::TYPE,
681 if (!empty($statusData) && $statusData[
'NOTIFY'] ==
"Y")
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),
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) :
""
697 $eventManager = Main\EventManager::getInstance();
698 if ($eventsList = $eventManager->findEventHandlers(
'sale', static::EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL))
700 $event =
new Main\Event(
'sale', static::EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL, array(
701 'EVENT_NAME' => $statusEventName,
706 if ($event->getResults())
709 foreach($event->getResults() as $eventResult)
711 if($eventResult->getType() === Main\EventResult::ERROR)
715 elseif($eventResult->getType() == Main\EventResult::SUCCESS)
717 if ($eventResultParams = $eventResult->getParameters())
720 if (!empty($eventResultParams) && is_array($eventResultParams))
722 if (!empty($eventResultParams[
'EVENT_NAME']))
724 $statusEventName = $eventResultParams[
'EVENT_NAME'];
727 if (!empty($eventResultParams[
'VALUES']) && is_array($eventResultParams[
'VALUES']))
729 $fields = $eventResultParams[
'VALUES'];
740 $eventMessage = new \CEventMessage;
741 $eventMessageRes = $eventMessage->GetList(
745 "EVENT_NAME" => $statusEventName,
746 "EVENT_NAME_EXACT_MATCH" =>
'Y',
747 "SITE_ID" => $entity->getSiteId(),
751 if (!($eventMessageData = $eventMessageRes->Fetch()))
753 $statusEventName = static::EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME;
757 $event = new \CEvent;
758 $event->Send($statusEventName, $entity->getSiteId(), $fields,
"Y",
"", array(), $siteData[
'LANGUAGE_ID']);
762 static::addSentEvent($entity->getId(), $statusEventName);
774 public static function sendShipmentTrackingNumberChange(Internals\Entity $entity)
776 $result =
new Result();
778 if (static::isNotifyDisabled())
783 if (!$entity instanceof Shipment)
785 throw new Main\ArgumentTypeException(
'entity',
'\Bitrix\Sale\Shipment');
788 if (static::hasSentEvent(
's'.$entity->getId(), static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME))
794 if (!$shipmentCollection = $entity->getCollection())
796 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
801 if (!$order = $shipmentCollection->getOrder())
803 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ORDER_NOT_FOUND")));
808 $fields = $order->getFields();
809 $originalValues = $fields->getOriginalValues();
811 if (array_key_exists(
'ACCOUNT_NUMBER', $originalValues) && $originalValues[
'ACCOUNT_NUMBER'] == $order->getField(
"ACCOUNT_NUMBER"))
816 $accountNumber = $order->getField(
"ACCOUNT_NUMBER");
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) :
""
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));
834 static::addSentEvent(
's'.$entity->getId(), static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME);
846 public static function sendShipmentAllowDelivery(Internals\Entity $entity)
848 $result =
new Result();
850 if (static::isNotifyDisabled())
855 if (!$entity instanceof Shipment)
857 throw new Main\ArgumentTypeException(
'entity',
'\Bitrix\Sale\Shipment');
860 if (static::hasSentEvent(
's'.$entity->getId(), static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME))
866 if (!$shipmentCollection = $entity->getCollection())
868 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
873 if (!$order = $shipmentCollection->getOrder())
875 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ORDER_NOT_FOUND")));
879 if (!$order->isAllowDelivery())
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) :
""
897 $eventName = static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME;
900 foreach(GetModuleEvents(
"sale", static::EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL,
true) as $oldEvent)
902 if (ExecuteModuleEventEx($oldEvent, array($order->getId(), &$eventName, &$fields)) ===
false)
910 $event = new \CEvent;
911 $event->Send($eventName, $order->getField(
'LID'), $fields,
"Y",
"", array(), static::getOrderLanguageId($order));
914 \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY, array(
"ORDER" => static::getOrderFields($order)));
916 static::addSentEvent(
's'.$entity->getId(), static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME);
929 public static function sendPrintableCheck(Internals\Entity $entity)
931 $result =
new Result();
933 if (static::isNotifyDisabled())
938 if (!($entity instanceof Payment)
939 && !($entity instanceof Shipment)
946 if (!$collection = $entity->getCollection())
948 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ENTITY_COLLECTION_NOT_FOUND")));
953 if (!$order = $collection->getOrder())
955 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ORDER_NOT_FOUND")));
959 $check = CheckManager::getLastPrintableCheckInfo($entity);
960 if (!empty($check[
'LINK']))
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)
974 $info = static::getSiteInfo($order);
977 $fields[
"SITE_NAME"] = $info[
'TITLE'];
978 $fields[
"SERVER_NAME"] = $info[
'PUBLIC_URL'];
981 $eventName = static::EVENT_ON_CHECK_PRINT_SEND_EMAIL;
982 $event = new \CEvent;
983 $event->Send($eventName, $order->getField(
'LID'), $fields,
"N");
985 if ($entity instanceof Payment)
987 static::addSentEvent(
'p'.$entity->getId(), $eventName);
989 elseif ($entity instanceof Shipment)
991 static::addSentEvent(
's'.$entity->getId(), $eventName);
1007 protected static function getSiteInfo(Order $order)
1009 $collection = $order->getTradeBindingCollection();
1011 foreach ($collection as $tradeBinding)
1013 $platform = $tradeBinding->getTradePlatform();
1014 if ($platform !==
null)
1016 return $platform->getInfo();
1032 protected static function getOrderPersonalDetailLink(Order $order)
1034 $context = Main\Context::getCurrent();
1035 $server = $context->getServer();
1037 $accountNumberEncode = urlencode(urlencode($order->getField(
"ACCOUNT_NUMBER")));
1038 $result =
'http://'.$server->getServerName().
'/personal/order/detail/'.$accountNumberEncode.
'/';
1040 $collection = $order->getTradeBindingCollection();
1042 foreach ($collection as $tradeBinding)
1044 $platform = $tradeBinding->getTradePlatform();
1045 if ($platform ===
null)
1050 $link = $platform->getExternalLink(Platform::LINK_TYPE_PUBLIC_DETAIL_ORDER, $order);
1072 public static function sendCheckError(Internals\Entity $entity)
1074 $result =
new Result();
1076 if (static::isNotifyDisabled())
1081 if (!($entity instanceof Payment)
1082 && !($entity instanceof Shipment)
1085 throw new Main\ArgumentTypeException(
'entity',
'\Bitrix\Sale\Payment or \Bitrix\Sale\Shipment');
1089 if (!$collection = $entity->getCollection())
1091 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ENTITY_COLLECTION_NOT_FOUND")));
1096 if (!$order = $collection->getOrder())
1098 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ORDER_NOT_FOUND")));
1102 $filter = array(
'STATUS' =>
'E');
1103 if ($entity instanceof Payment)
1105 $filter[
'PAYMENT_ID'] = $entity->getId();
1107 elseif ($entity instanceof Shipment)
1109 $filter[
'SHIPMENT_ID'] = $entity->getId();
1112 $dbRes = CashboxCheckTable::getList(
1114 'select' => array(
'*'),
1115 'filter' => $filter,
1116 'order' => array(
'DATE_PRINT_END' =>
'DESC'),
1120 $check = $dbRes->fetch();
1123 $result->addError(
new ResultError(Main\Localization\
Loc::getMessage(
"SALE_NOTIFY_ORDER_CHECK_NOT_FOUND")));
1127 $cashbox = Manager::getCashboxFromCache($check[
'CASHBOX_ID']);
1128 if ($cashbox[
'EMAIL'])
1130 $cashbox = Manager::getCashboxFromCache($check[
'CASHBOX_ID']);
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"]),
1141 $context = Main\Context::getCurrent();
1142 $server = $context->getServer();
1144 if (IsModuleInstalled(
'crm'))
1146 $fields[
'LINK_URL'] =
'http://'.$server->getServerName().
'/shop/orders/details/'.$order->getId().
'/';
1150 $fields[
'LINK_URL'] =
'http://'.$server->getServerName().
'/bitrix/admin/sale_order_view.php?ID='.$order->getId();
1153 $eventName = static::EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL;
1154 $event = new \CEvent;
1155 $event->Send($eventName, $order->getField(
'LID'), $fields,
"N");
1157 if ($entity instanceof Payment)
1159 static::addSentEvent(
'p'.$entity->getId(), $eventName);
1161 elseif ($entity instanceof Shipment)
1163 static::addSentEvent(
's'.$entity->getId(), $eventName);
1167 \CSaleMobileOrderPush::send(
1168 static::EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR,
1170 'ORDER' => static::getOrderFields($order),
1188 if (static::isNotifyDisabled())
1193 $context = Main\Context::getCurrent();
1194 $server = $context->getServer();
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()),
1204 if (IsModuleInstalled(
'crm'))
1206 $fields[
'LINK_URL'] =
'http://'.$server->getServerName().
'/shop/orders/details/'.$order->getId().
'/';
1210 $fields[
'LINK_URL'] =
'http://'.$server->getServerName().
'/bitrix/admin/sale_order_view.php?ID='.$order->getId();
1213 $eventName = static::EVENT_ON_CHECK_VALIDATION_ERROR_SEND_EMAIL;
1214 $event = new \CEvent;
1215 $event->Send($eventName, $order->getField(
'LID'), $fields,
"N");
1226 protected static function getUserEmail(
Order $order)
1230 if (!empty(static::$cacheUserData[$order->getId()]))
1232 $userData = static::$cacheUserData[$order->getId()];
1233 if (!empty($userData[
'EMAIL']))
1235 $userEmail = $userData[
'EMAIL'];
1240 if (empty($userEmail))
1243 if ($propertyCollection = $order->getPropertyCollection())
1245 if ($propUserEmail = $propertyCollection->getUserEmail())
1247 $userEmail = $propUserEmail->getValue();
1248 static::$cacheUserData[$order->getId()][
'EMAIL'] = $userEmail;
1253 if (empty($userEmail))
1255 $userRes = Main\UserTable::getList([
1265 '=ID' => $order->getUserId(),
1268 if ($userData = $userRes->fetch())
1270 static::$cacheUserData[$order->getId()] = $userData;
1271 $userEmail = $userData[
'EMAIL'];
1284 protected static function getUserName(Order $order)
1288 if (!empty(static::$cacheUserData[$order->getUserId()]))
1290 $userData = static::$cacheUserData[$order->getUserId()];
1291 if (!empty($userData[
'USER_NAME']))
1293 $userName = $userData[
'USER_NAME'];
1298 if (empty($userName))
1301 if ($propertyCollection = $order->getPropertyCollection())
1303 if ($propPayerName = $propertyCollection->getPayerName())
1305 $userName = $propPayerName->getValue();
1306 static::$cacheUserData[$order->getUserId()][
'PAYER_NAME'] = $userName;
1311 if (empty($userName))
1313 $userRes = Main\UserTable::getList([
1323 '=ID' => $order->getUserId(),
1326 if ($userData = $userRes->fetch())
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'];
1342 protected static function getAllFieldsFromOrder(Order $order)
1344 $result =
new Result();
1346 $paymentSystemId =
false;
1347 $deliveryId =
false;
1350 if ($paymentCollection = $order->getPaymentCollection())
1353 if ($payment = $paymentCollection->rewind())
1355 $paymentSystemId = $payment->getPaymentSystemId();
1360 if ($shipmentCollection = $order->getShipmentCollection())
1363 foreach ($shipmentCollection as $shipment)
1365 if ($shipment->getDeliveryId() > 0)
1367 $deliveryId = $shipment->getDeliveryId();
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'),
1392 $orderFields = static::getOrderFields($order);
1393 if (is_array($orderFields))
1395 $orderFields = $fields + $orderFields;
1396 $orderFields = static::convertDateFieldsToOldFormat($orderFields);
1400 'FIELDS' => $fields,
1401 'ORDER_FIELDS' => $orderFields,
1413 protected static function getOrderFields(Order $order)
1415 $fields = $order->getFieldValues();
1416 $fields = array_merge(
1419 'ORDER_ID' => $order->getId(),
1420 'ORDER_WEIGHT' => 0,
1421 'BASKET_ITEMS' => [],
1423 'DISCOUNT_LIST' => [],
1425 'VAT_RATE' => $order->getVatRate(),
1426 'VAT_SUM' => $order->getVatSum(),
1430 if ($basket = $order->getBasket())
1433 foreach ($basket as $basketItem)
1435 $fields[
'BASKET_ITEMS'][] = static::getBasketItemFields($basketItem);
1438 $fields[
'ORDER_WEIGHT'] = $basket->getWeight();
1442 if ($propertyCollection = $order->getPropertyCollection())
1445 foreach ($propertyCollection as $property)
1447 $fields[
'ORDER_PROP'][$property->getPropertyId()] = $property->getValue();
1452 if ($propProfileName = $propertyCollection->getProfileName())
1454 $fields[
'PROFILE_NAME'] = $propProfileName->getValue();
1457 if ($propPayerName = $propertyCollection->getPayerName())
1459 $fields[
'PAYER_NAME'] = $propPayerName->getValue();
1462 if ($propUserEmail = $propertyCollection->getUserEmail())
1464 $fields[
'USER_EMAIL'] = $propUserEmail->getValue();
1467 if ($propDeliveryLocationZip = $propertyCollection->getDeliveryLocationZip())
1469 $fields[
'DELIVERY_LOCATION_ZIP'] = $propDeliveryLocationZip->getValue();
1472 if ($propDeliveryLocation = $propertyCollection->getDeliveryLocation())
1474 $fields[
'DELIVERY_LOCATION'] = $propDeliveryLocation->getValue();
1477 if ($propTaxLocation = $propertyCollection->getTaxLocation())
1479 $fields[
'TAX_LOCATION'] = $propTaxLocation->getValue();
1482 $fields[
'DISCOUNT_LIST'] = Compatible\DiscountCompatibility::getOldDiscountResult();
1485 if ($tax = $order->getTax())
1487 $fields[
'TAX_LIST'] = $tax->getTaxList();
1499 protected static function getBasketItemFields(BasketItem $basketItem)
1501 $fields = $basketItem->getFieldValues();
1504 if (!$basket = $basketItem->getCollection())
1506 throw new Main\ObjectNotFoundException(
'Entity "Basket" not found');
1509 if (empty($fields[
'LID']))
1511 $fields[
'LID'] = $basket->getSiteId();
1514 if (empty($fields[
'LID']))
1516 if ($order = $basket->getOrder())
1518 $fields[
'LID'] = $order->getField(
'LID');
1522 if (empty($fields[
'FUSER_ID']))
1524 $fields[
'FUSER_ID'] = $basket->getFUserId(
true);
1529 if ($propertyCollection = $basketItem->getPropertyCollection())
1531 $fields[
'PROPS'] = $propertyCollection->getPropertyValues();
1544 $siteData = Main\SiteTable::GetById($order->getSiteId())->fetch();
1545 return $siteData[
'LANGUAGE_ID'];
1556 $resultList = array();
1557 foreach ($fields as $k => $value)
1559 $valueString = static::convertDateFieldToOldFormat($value);
1560 $resultList[$k] = $valueString;
1576 if ($value instanceof Main\
Type\
Date)
1578 $setValue = $value->toString();
1590 private static function hasSentEvent($code, $event)
1592 if (!array_key_exists($code, static::$sentEventList))
1597 if (in_array($event, static::$sentEventList[$code]))
1611 private static function addSentEvent($code, $event)
1613 if (!static::hasSentEvent($code, $event))
1615 static::$sentEventList[$code][] = $event;
1629 $eventNotifyMap = EventActions::getEventNotifyMap();
1631 if (isset($eventNotifyMap[$eventName]))
1633 if ($entity instanceof $eventNotifyMap[$eventName][
'ENTITY'])
1635 call_user_func_array($eventNotifyMap[$eventName][
'METHOD'], [$entity]);
1645 static::$disableNotify = ($value ===
true);
1646 Compatible\EventCompatibility::setDisableMailSend($value);
1654 return static::$disableNotify;