Bitrix-D7  20.0.0
Класс Notify

Открытые статические члены

static getRegistryType ()
 
static sendOrderNew (Internals\Entity $entity)
 
static sendOrderCancel (Internals\Entity $entity)
 
static sendOrderPaid (Internals\Entity $entity)
 
static sendOrderStatusChange (Internals\Entity $entity)
 
static sendShipmentStatusChange (Internals\Entity $entity)
 
static sendOrderAllowPayStatusChange (Internals\Entity $entity)
 
static sendShipmentTrackingNumberChange (Internals\Entity $entity)
 
static sendShipmentAllowDelivery (Internals\Entity $entity)
 
static sendPrintableCheck (Internals\Entity $entity)
 
static sendCheckError (Internals\Entity $entity)
 
static getOrderLanguageId (Order $order)
 
static convertDateFieldsToOldFormat (array $fields)
 Convert an array of dates from the object to a string. Подробнее...
 
static callNotify (Internals\Entity $entity, $eventName)
 
static setNotifyDisable ($value)
 
static isNotifyDisabled ()
 

Поля данных

const EVENT_ORDER_STATUS_SEND_EMAIL = "OnOrderStatusSendEmail"
 
const EVENT_ORDER_STATUS_EMAIL = "OnSaleStatusEMail"
 
const EVENT_ON_ORDER_NEW_SEND_EMAIL = "OnOrderNewSendEmail"
 
const EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME = "SALE_NEW_ORDER"
 
const EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL = "OnOrderDeliverSendEmail"
 
const EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_DELIVERY"
 
const EVENT_ON_CHECK_PRINT_SEND_EMAIL = "SALE_CHECK_PRINT"
 
const EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL = "SALE_CHECK_PRINT_ERROR"
 
const EVENT_ON_ORDER_PAID_SEND_EMAIL = "OnOrderPaySendEmail"
 
const EVENT_ON_ORDER_CANCEL_SEND_EMAIL = "OnOrderCancelSendEmail"
 
const EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_PAID"
 
const EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_CANCEL"
 
const EVENT_ORDER_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_TRACKING_NUMBER"
 
const EVENT_ORDER_STATUS_CHANGED_SEND_EMAIL_EVENT_NAME = "SALE_STATUS_CHANGED"
 
const EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_TRACKING_NUMBER"
 
const EVENT_DEFAULT_STATUS_CHANGED_ID = "SALE_STATUS_CHANGED_"
 
const EVENT_SHIPMENT_STATUS_SEND_EMAIL = "OnSaleShipmentStatusSendEmail"
 
const EVENT_SHIPMENT_STATUS_EMAIL = "OnSaleShipmentStatusEMail"
 
const EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_ALLOW_PAY"
 
const EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL = "OnSaleOrderAllowPayStatusEMail"
 
const EVENT_MOBILE_PUSH_ORDER_CREATED = "ORDER_CREATED"
 
const EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE = "ORDER_STATUS_CHANGED"
 
const EVENT_MOBILE_PUSH_ORDER_CANCELED = "ORDER_CANCELED"
 
const EVENT_MOBILE_PUSH_ORDER_PAID = "ORDER_PAYED"
 
const EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR = "ORDER_CHECK_ERROR"
 
const EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY = "ORDER_DELIVERY_ALLOWED"
 

Защищенные члены

 __construct ()
 

Защищенные статические члены

static getSiteInfo (Order $order)
 
static getOrderPersonalDetailLink (Order $order)
 
static getUserEmail (Order $order)
 
static getUserName (Order $order)
 
static getAllFieldsFromOrder (Order $order)
 
static getOrderFields (Order $order)
 
static getBasketItemFields (BasketItem $basketItem)
 
static convertDateFieldToOldFormat ($value)
 Convert date object to a string. Подробнее...
 

Статические защищенные данные

static $cacheUserData = array()
 
static $sentEventList = array()
 
static $disableNotify = false
 

Подробное описание

См. определение в файле sale/lib/notify.php строка 22

Конструктор(ы)

◆ __construct()

__construct ( )
protected

См. определение в файле sale/lib/notify.php строка 68

68 {}

Методы

◆ callNotify()

static callNotify ( Internals\Entity  $entity,
  $eventName 
)
static
Аргументы
Internals\Entity$entity
$eventName

См. определение в файле sale/lib/notify.php строка 1568

1569  {
1570  if (($eventNotifyMap = EventActions::getEventNotifyMap()) && !empty($eventNotifyMap) && is_array($eventNotifyMap))
1571  {
1572  if (array_key_exists($eventName, $eventNotifyMap) && !empty($eventNotifyMap[$eventName]) && !empty($eventNotifyMap[$eventName]['METHOD']))
1573  {
1574  if ($entity instanceof $eventNotifyMap[$eventName]['ENTITY'])
1575  {
1576  call_user_func_array($eventNotifyMap[$eventName]['METHOD'], array($entity));
1577  }
1578  }
1579  }
1580  }

◆ convertDateFieldsToOldFormat()

static convertDateFieldsToOldFormat ( array  $fields)
static

Convert an array of dates from the object to a string.

Аргументы
array$fieldsThe array of dates
Возвращает
array

См. определение в файле sale/lib/notify.php строка 1496

1497  {
1498  $resultList = array();
1499  foreach ($fields as $k => $value)
1500  {
1501  $valueString = static::convertDateFieldToOldFormat($value);
1502  $resultList[$k] = $valueString;
1503  }
1504 
1505  return $resultList;
1506  }

◆ convertDateFieldToOldFormat()

static convertDateFieldToOldFormat (   $value)
staticprotected

Convert date object to a string.

Аргументы
string$valueField value
Возвращает
string

См. определение в файле sale/lib/notify.php строка 1514

1515  {
1516  $setValue = $value;
1517 
1518  if ($value instanceof Main\Type\Date)
1519  {
1520  $setValue = $value->toString();
1521  }
1522 
1523  return $setValue;
1524  }

◆ getAllFieldsFromOrder()

static getAllFieldsFromOrder ( Order  $order)
staticprotected
Аргументы
Order$order
Возвращает
Result

См. определение в файле sale/lib/notify.php строка 1285

1286  {
1287  $result = new Result();
1288 
1289  $paymentSystemId = false;
1290  $deliveryId = false;
1291 
1292  /** @var PaymentCollection $paymentCollection */
1293  if ($paymentCollection = $order->getPaymentCollection())
1294  {
1295  /** @var Payment $payment */
1296  if ($payment = $paymentCollection->rewind())
1297  {
1298  $paymentSystemId = $payment->getPaymentSystemId();
1299  }
1300  }
1301 
1302  /** @var ShipmentCollection $shipe */
1303  if ($shipmentCollection = $order->getShipmentCollection())
1304  {
1305  /** @var Shipment $shipment */
1306  foreach ($shipmentCollection as $shipment)
1307  {
1308  if ($shipment->getDeliveryId() > 0)
1309  {
1310  $deliveryId = $shipment->getDeliveryId();
1311  break;
1312  }
1313  }
1314  }
1315 
1316  $fields = array(
1317  "SITE_ID" => $order->getSiteId(),
1318  "LID" => $order->getSiteId(),
1319  "PERSON_TYPE_ID" => $order->getPersonTypeId(),
1320  "PRICE" => $order->getPrice(),
1321  "CURRENCY" => $order->getCurrency(),
1322  "USER_ID" => $order->getUserId(),
1323  "PAY_SYSTEM_ID" => $paymentSystemId,
1324  "PRICE_DELIVERY" => $order->getDeliveryPrice(),
1325  "DELIVERY_ID" => $deliveryId,
1326  "DISCOUNT_VALUE" => $order->getDiscountPrice(),
1327  "TAX_VALUE" => $order->getTaxValue(),
1328  "TRACKING_NUMBER" => $order->getField('TRACKING_NUMBER'),
1329  "PAYED" => $order->getField('PAYED'),
1330  "CANCELED" => $order->getField('CANCELED'),
1331  "STATUS_ID" => $order->getField('STATUS_ID'),
1332  "RESERVED" => $order->getField('RESERVED'),
1333  );
1334 
1335  $orderFields = static::getOrderFields($order);
1336  if (is_array($orderFields))
1337  {
1338  $orderFields = $fields + $orderFields;
1339  $orderFields = static::convertDateFieldsToOldFormat($orderFields);
1340  }
1341 
1342  $result->setData(array(
1343  'FIELDS' => $fields,
1344  'ORDER_FIELDS' => $orderFields,
1345  ));
1346 
1347  return $result;
1348  }

◆ getBasketItemFields()

static getBasketItemFields ( BasketItem  $basketItem)
staticprotected
Аргументы
BasketItem$basketItem
Возвращает
array
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1441

1442  {
1443  $fields = $basketItem->getFieldValues();
1444 
1445  /** @var Basket $basket */
1446  if (!$basket = $basketItem->getCollection())
1447  {
1448  throw new Main\ObjectNotFoundException('Entity "Basket" not found');
1449  }
1450 
1451  if (empty($fields['LID']))
1452  {
1453  $fields['LID'] = $basket->getSiteId();
1454  }
1455 
1456  if (empty($fields['LID']))
1457  {
1458  if ($order = $basket->getOrder())
1459  {
1460  $fields['LID'] = $order->getField('LID');
1461  }
1462  }
1463 
1464  if (empty($fields['FUSER_ID']))
1465  {
1466  $fields['FUSER_ID'] = $basket->getFUserId(true);
1467  }
1468 
1469 
1470  /** @var BasketPropertiesCollection $propertyCollection */
1471  if ($propertyCollection = $basketItem->getPropertyCollection())
1472  {
1473  $fields['PROPS'] = $propertyCollection->getPropertyValues();
1474  }
1475 
1476  return $fields;
1477  }

◆ getOrderFields()

static getOrderFields ( Order  $order)
staticprotected
Аргументы
Order$order
Возвращает
array
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1356

1357  {
1358  $fields = $order->getFieldValues();
1359  $fields = array_merge($fields,
1360  array(
1361  'ORDER_ID' => $order->getId(),
1362  'ORDER_WEIGHT' => 0,
1363  'BASKET_ITEMS' => array(),
1364  'ORDER_PROP' => array(),
1365  'DISCOUNT_LIST' => array(),
1366  'TAX_LIST' => array(),
1367  'VAT_RATE' => $order->getVatRate(),
1368  'VAT_SUM' => $order->getVatSum(),
1369  ));
1370 
1371  /** @var Basket $basket */
1372  if ($basket = $order->getBasket())
1373  {
1374  /** @var BasketItem $basketItem */
1375  foreach ($basket as $basketItem)
1376  {
1377  $fields['BASKET_ITEMS'][] = static::getBasketItemFields($basketItem);
1378  }
1379 
1380  $fields['ORDER_WEIGHT'] = $basket->getWeight();
1381  }
1382 
1383  /** @var PropertyValueCollection $basket */
1384  if ($propertyCollection = $order->getPropertyCollection())
1385  {
1386  /** @var PropertyValue $property */
1387  foreach ($propertyCollection as $property)
1388  {
1389  $fields['ORDER_PROP'][$property->getPropertyId()] = $property->getValue();
1390  }
1391  }
1392 
1393 
1394  if ($propProfileName = $propertyCollection->getProfileName())
1395  {
1396  $fields['PROFILE_NAME'] = $propProfileName->getValue();
1397  }
1398 
1399  if ($propPayerName = $propertyCollection->getPayerName())
1400  {
1401  $fields['PAYER_NAME'] = $propPayerName->getValue();
1402  }
1403 
1404  if ($propUserEmail = $propertyCollection->getUserEmail())
1405  {
1406  $fields['USER_EMAIL'] = $propUserEmail->getValue();
1407  }
1408 
1409  if ($propDeliveryLocationZip = $propertyCollection->getDeliveryLocationZip())
1410  {
1411  $fields['DELIVERY_LOCATION_ZIP'] = $propDeliveryLocationZip->getValue();
1412  }
1413 
1414  if ($propDeliveryLocation = $propertyCollection->getDeliveryLocation())
1415  {
1416  $fields['DELIVERY_LOCATION'] = $propDeliveryLocation->getValue();
1417  }
1418 
1419  if ($propTaxLocation = $propertyCollection->getTaxLocation())
1420  {
1421  $fields['TAX_LOCATION'] = $propTaxLocation->getValue();
1422  }
1423 
1424  $fields['DISCOUNT_LIST'] = Compatible\DiscountCompatibility::getOldDiscountResult();
1425 
1426  /** @var Tax $tax */
1427  if ($tax = $order->getTax())
1428  {
1429  $fields['TAX_LIST'] = $tax->getTaxList();
1430  }
1431 
1432  return $fields;
1433  }

◆ getOrderLanguageId()

static getOrderLanguageId ( Order  $order)
static
Аргументы
Order$order
Возвращает
mixed

См. определение в файле sale/lib/notify.php строка 1484

1485  {
1486  $siteData = Main\SiteTable::GetById($order->getSiteId())->fetch();
1487  return $siteData['LANGUAGE_ID'];
1488  }

◆ getOrderPersonalDetailLink()

static getOrderPersonalDetailLink ( Order  $order)
staticprotected
Аргументы
Order$order
Возвращает
string
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1035

1036  {
1037  $context = Main\Context::getCurrent();
1038  $server = $context->getServer();
1039 
1040  $accountNumberEncode = urlencode(urlencode($order->getField("ACCOUNT_NUMBER")));
1041  $result = 'http://'.$server->getServerName().'/personal/order/detail/'.$accountNumberEncode.'/';
1042 
1043  $collection = $order->getTradeBindingCollection();
1044  /** @var TradeBindingEntity $tradeBinding */
1045  foreach ($collection as $tradeBinding)
1046  {
1047  $platform = $tradeBinding->getTradePlatform();
1048  if ($platform === null)
1049  {
1050  continue;
1051  }
1052 
1053  $link = $platform->getExternalLink(Platform::LINK_TYPE_PUBLIC_DETAIL_ORDER, $order);
1054  if ($link)
1055  {
1056  $result = $link;
1057  }
1058 
1059  break;
1060  }
1061 
1062  return $result;
1063  }

◆ getRegistryType()

static getRegistryType ( )
static
Возвращает
string

См. определение в файле sale/lib/notify.php строка 73

74  {
76  }

◆ getSiteInfo()

static getSiteInfo ( Order  $order)
staticprotected
Аргументы
Order$order
Возвращает
array
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1010

1011  {
1012  $collection = $order->getTradeBindingCollection();
1013  /** @var TradeBindingEntity $tradeBinding */
1014  foreach ($collection as $tradeBinding)
1015  {
1016  $platform = $tradeBinding->getTradePlatform();
1017  if ($platform !== null)
1018  {
1019  return $platform->getInfo();
1020  }
1021  }
1022 
1023  return [];
1024  }

◆ getUserEmail()

static getUserEmail ( Order  $order)
staticprotected
Аргументы
Order$order
Возвращает
null|string
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1187

1188  {
1189  $userEmail = "";
1190 
1191  if (!empty(static::$cacheUserData[$order->getId()]))
1192  {
1193  $userData = static::$cacheUserData[$order->getId()];
1194  if (!empty($userData['EMAIL']))
1195  {
1196  $userEmail = $userData['EMAIL'];
1197  }
1198  }
1199 
1200 
1201  if (empty($userEmail))
1202  {
1203  /** @var PropertyValueCollection $propertyCollection */
1204  if ($propertyCollection = $order->getPropertyCollection())
1205  {
1206  if ($propUserEmail = $propertyCollection->getUserEmail())
1207  {
1208  $userEmail = $propUserEmail->getValue();
1209  static::$cacheUserData[$order->getId()]['EMAIL'] = $userEmail;
1210  }
1211  }
1212  }
1213 
1214  if (empty($userEmail))
1215  {
1216  $userRes = Main\UserTable::getList(array(
1217  'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
1218  'filter' => array('=ID' => $order->getUserId()),
1219  ));
1220  if ($userData = $userRes->fetch())
1221  {
1222  static::$cacheUserData[$order->getId()] = $userData;
1223  $userEmail = $userData['EMAIL'];
1224  }
1225  }
1226 
1227  return $userEmail;
1228  }

◆ getUserName()

static getUserName ( Order  $order)
staticprotected
Аргументы
Order$order
Возвращает
mixed|null|string
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1236

1237  {
1238  $userName = "";
1239 
1240  if (!empty(static::$cacheUserData[$order->getUserId()]))
1241  {
1242  $userData = static::$cacheUserData[$order->getUserId()];
1243  if (!empty($userData['USER_NAME']))
1244  {
1245  $userName = $userData['USER_NAME'];
1246  }
1247  }
1248 
1249 
1250  if (empty($userName))
1251  {
1252  /** @var PropertyValueCollection $propertyCollection */
1253  if ($propertyCollection = $order->getPropertyCollection())
1254  {
1255  if ($propPayerName = $propertyCollection->getPayerName())
1256  {
1257  $userName = $propPayerName->getValue();
1258  static::$cacheUserData[$order->getUserId()]['PAYER_NAME'] = $userName;
1259  }
1260  }
1261  }
1262 
1263  if (empty($userName))
1264  {
1265  $userRes = Main\UserTable::getList(array(
1266  'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
1267  'filter' => array('=ID' => $order->getUserId()),
1268  ));
1269  if ($userData = $userRes->fetch())
1270  {
1271  $userData['PAYER_NAME'] = \CUser::FormatName(\CSite::GetNameFormat(null, $order->getSiteId()), $userData, true);
1272  static::$cacheUserData[$order->getUserId()]['PAYER_NAME'] = $userData['PAYER_NAME'];
1273  $userName = $userData['PAYER_NAME'];
1274  }
1275  }
1276 
1277  return $userName;
1278  }

◆ isNotifyDisabled()

static isNotifyDisabled ( )
static
Возвращает
bool

См. определение в файле sale/lib/notify.php строка 1594

1595  {
1596  return static::$disableNotify;
1597  }

◆ sendCheckError()

static sendCheckError ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 1075

1076  {
1077  $result = new Result();
1078 
1079  if (static::isNotifyDisabled())
1080  {
1081  return $result;
1082  }
1083 
1084  if (!($entity instanceof Payment)
1085  && !($entity instanceof Shipment)
1086  )
1087  {
1088  throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Payment or \Bitrix\Sale\Shipment');
1089  }
1090 
1091  /** @var PaymentCollection|ShipmentCollection $collection */
1092  if (!$collection = $entity->getCollection())
1093  {
1094  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ENTITY_COLLECTION_NOT_FOUND")));
1095  return $result;
1096  }
1097 
1098  /** @var Order $order */
1099  if (!$order = $collection->getOrder())
1100  {
1101  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
1102  return $result;
1103  }
1104 
1105  $filter = array('STATUS' => 'E');
1106  if ($entity instanceof Payment)
1107  {
1108  $filter['PAYMENT_ID'] = $entity->getId();
1109  }
1110  elseif ($entity instanceof Shipment)
1111  {
1112  $filter['SHIPMENT_ID'] = $entity->getId();
1113  }
1114 
1115  $dbRes = CashboxCheckTable::getList(
1116  array(
1117  'select' => array('*'),
1118  'filter' => $filter,
1119  'order' => array('DATE_PRINT_END' => 'DESC'),
1120  'limit' => 1
1121  )
1122  );
1123  $check = $dbRes->fetch();
1124  if (!$check)
1125  {
1126  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_CHECK_NOT_FOUND")));
1127  return $result;
1128  }
1129 
1130  $cashbox = Manager::getCashboxFromCache($check['CASHBOX_ID']);
1131  if ($cashbox['EMAIL'])
1132  {
1133  $cashbox = Manager::getCashboxFromCache($check['CASHBOX_ID']);
1134 
1135  $fields = array(
1136  "ORDER_ACCOUNT_NUMBER" => $order->getField("ACCOUNT_NUMBER"),
1137  "CHECK_ID" => $check['ID'],
1138  "ORDER_ID" => $order->getId(),
1139  "ORDER_DATE" => $order->getDateInsert()->toString(),
1140  "EMAIL" => $cashbox['EMAIL'],
1141  "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
1142  );
1143 
1144  $context = Main\Context::getCurrent();
1145  $server = $context->getServer();
1146 
1147  if (IsModuleInstalled('crm'))
1148  {
1149  $fields['LINK_URL'] = 'http://'.$server->getServerName().'/shop/orders/details/'.$order->getId().'/';
1150  }
1151  else
1152  {
1153  $fields['LINK_URL'] = 'http://'.$server->getServerName().'/bitrix/admin/sale_order_view.php?ID='.$order->getId();
1154  }
1155 
1156  $eventName = static::EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL;
1157  $event = new \CEvent;
1158  $event->Send($eventName, $order->getField('LID'), $fields, "N");
1159 
1160  if ($entity instanceof Payment)
1161  {
1162  static::addSentEvent('p'.$entity->getId(), $eventName);
1163  }
1164  elseif ($entity instanceof Shipment)
1165  {
1166  static::addSentEvent('s'.$entity->getId(), $eventName);
1167  }
1168  }
1169 
1170  \CSaleMobileOrderPush::send(
1171  static::EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR,
1172  array(
1173  'ORDER' => static::getOrderFields($order),
1174  'CHECK' => $check
1175  )
1176  );
1177 
1178  return $result;
1179  }

◆ sendOrderAllowPayStatusChange()

static sendOrderAllowPayStatusChange ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 627

628  {
629  $result = new Result();
630 
631  if (static::isNotifyDisabled())
632  {
633  return $result;
634  }
635 
636  if (!$entity instanceof Order)
637  {
638  throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
639  }
640 
641  $statusEventName = static::EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME;
642 
643  if (static::hasSentEvent($entity->getId(), $statusEventName))
644  {
645  return $result;
646  }
647 
648  /** @var Internals\Fields $fields */
649  $fields = $entity->getFields();
650  $originalValues = $fields->getOriginalValues();
651 
652  if (array_key_exists('STATUS_ID', $originalValues) && $originalValues['STATUS_ID'] == $entity->getField("STATUS_ID"))
653  {
654  return $result;
655  }
656 
657  static $cacheSiteData = array();
658 
659  if (!isset($cacheSiteData[$entity->getSiteId()]))
660  {
661  $siteRes = \CSite::GetByID($entity->getSiteId());
662  $siteData = $siteRes->Fetch();
663  }
664  else
665  {
666  $siteData = $cacheSiteData[$entity->getSiteId()];
667  }
668 
669  $statusData = Internals\StatusTable::getList(array(
670  'select' => array(
671  'ID',
672  'NOTIFY',
673  'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME',
674  ),
675  'filter' => array(
676  '=ID' => $entity->getField("STATUS_ID"),
677  '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => $siteData['LANGUAGE_ID'],
678  '=TYPE' => OrderStatus::TYPE
679  ),
680  'limit' => 1,
681  ))->fetch();
682 
683  if (!empty($statusData) && $statusData['NOTIFY'] == "Y")
684  {
685  $isSend = true;
686 
687  $fields = array(
688  "ORDER_ID" => $entity->getField("ACCOUNT_NUMBER"),
689  "ORDER_REAL_ID" => $entity->getField("ID"),
690  "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($entity->getField("ACCOUNT_NUMBER"))),
691  "ORDER_DATE" => $entity->getDateInsert()->toString(),
692  "ORDER_STATUS" => $statusData["NAME"],
693  "EMAIL" => static::getUserEmail($entity),
694  "TEXT" => "",
695  "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
696  "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($entity) ? Helpers\Order::getPublicLink($entity) : ""
697  );
698 
699  $eventManager = Main\EventManager::getInstance();
700  if ($eventsList = $eventManager->findEventHandlers('sale', static::EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL))
701  {
702  $event = new Main\Event('sale', static::EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL, array(
703  'EVENT_NAME' => $statusEventName,
704  'VALUES' => $fields
705  ));
706  $event->send();
707 
708  if ($event->getResults())
709  {
710  /** @var Main\EventResult $eventResult */
711  foreach($event->getResults() as $eventResult)
712  {
713  if($eventResult->getType() === Main\EventResult::ERROR)
714  {
715  $isSend = false;
716  }
717  elseif($eventResult->getType() == Main\EventResult::SUCCESS)
718  {
719  if ($eventResultParams = $eventResult->getParameters())
720  {
721  /** @var Result $eventResultData */
722  if (!empty($eventResultParams) && is_array($eventResultParams))
723  {
724  if (!empty($eventResultParams['EVENT_NAME']))
725  {
726  $statusEventName = $eventResultParams['EVENT_NAME'];
727  }
728 
729  if (!empty($eventResultParams['VALUES']) && is_array($eventResultParams['VALUES']))
730  {
731  $fields = $eventResultParams['VALUES'];
732  }
733  }
734  }
735  }
736  }
737  }
738  }
739 
740  if($isSend)
741  {
742  $b = '';
743  $o = '';
744  $eventMessage = new \CEventMessage;
745  $eventMessageRes = $eventMessage->GetList(
746  $b,
747  $o,
748  array(
749  "EVENT_NAME" => $statusEventName,
750  "SITE_ID" => $entity->getSiteId(),
751  'ACTIVE' => 'Y'
752  )
753  );
754  if (!($eventMessageData = $eventMessageRes->Fetch()))
755  {
756  $statusEventName = static::EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME;
757  }
758 
759  unset($o, $b);
760  $event = new \CEvent;
761  $event->Send($statusEventName, $entity->getSiteId(), $fields, "Y", "", array(), $siteData['LANGUAGE_ID']);
762  }
763  }
764 
765  static::addSentEvent($entity->getId(), $statusEventName);
766 
767  return $result;
768  }

◆ sendOrderCancel()

static sendOrderCancel ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 198

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  }

◆ sendOrderNew()

static sendOrderNew ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 85

86  {
87  $result = new Result();
88 
89  if (static::isNotifyDisabled())
90  {
91  return $result;
92  }
93 
94  if (!$entity instanceof Order)
95  {
96  throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Order');
97  }
98 
99  if (static::hasSentEvent($entity->getId(), static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME))
100  {
101  return $result;
102  }
103 
104  if (!$entity->isNew())
105  {
106  return $result;
107  }
108 
109  $by = $sort = '';
110 
111  $separator = "<br/>";
112 
113  $eventName = static::EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME;
114 
115  $filter = array(
116  "EVENT_NAME" => $eventName,
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($by, $sort, $filter);
130  if ($eventMessage = $res->Fetch())
131  {
132  if ($eventMessage['BODY_TYPE'] == 'text')
133  {
134  $separator = "\n";
135  }
136  }
137 
138  $basketList = '';
139  /** @var Basket $basket */
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  }

◆ sendOrderPaid()

static sendOrderPaid ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 272

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  }

◆ sendOrderStatusChange()

static sendOrderStatusChange ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 344

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 
365  /** @var Internals\Fields $fields */
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  $b = '';
424  $o = '';
425  $eventMessage = new \CEventMessage;
426  $eventMessageRes = $eventMessage->GetList(
427  $b,
428  $o,
429  array(
430  "EVENT_NAME" => $eventName,
431  "SITE_ID" => $entity->getSiteId(),
432  'ACTIVE' => 'Y'
433  )
434  );
435  if (!($eventMessageData = $eventMessageRes->Fetch()))
436  {
437  $eventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
438  }
439 
440  unset($o, $b);
441  $event = new \CEvent;
442  $event->Send($eventName, $entity->getSiteId(), $fields, "Y", "", array(), $siteData['LANGUAGE_ID']);
443  }
444  }
445 
446  \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE, array("ORDER" => static::getOrderFields($entity)));
447 
448  static::addSentEvent($entity->getId(), $statusEventName);
449 
450  return $result;
451  }

◆ sendPrintableCheck()

static sendPrintableCheck ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 932

933  {
934  $result = new Result();
935 
936  if (static::isNotifyDisabled())
937  {
938  return $result;
939  }
940 
941  if (!($entity instanceof Payment)
942  && !($entity instanceof Shipment)
943  )
944  {
945  return $result;
946  }
947 
948  /** @var PaymentCollection|ShipmentCollection $collection */
949  if (!$collection = $entity->getCollection())
950  {
951  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ENTITY_COLLECTION_NOT_FOUND")));
952  return $result;
953  }
954 
955  /** @var Order $order */
956  if (!$order = $collection->getOrder())
957  {
958  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
959  return $result;
960  }
961 
962  $check = CheckManager::getLastPrintableCheckInfo($entity);
963  if (!empty($check['LINK']))
964  {
965  $fields = array(
966  "ORDER_ID" => $order->getField("ACCOUNT_NUMBER"),
967  "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
968  "ORDER_USER" => static::getUserName($order),
969  "ORDER_DATE" => $order->getDateInsert()->toString(),
970  "EMAIL" => static::getUserEmail($order),
971  "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
972  "CHECK_LINK" => $check['LINK'],
973  "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : "",
974  "LINK_URL" => static::getOrderPersonalDetailLink($order)
975  );
976 
977  $info = static::getSiteInfo($order);
978  if ($info)
979  {
980  $fields["SITE_NAME"] = $info['TITLE'];
981  $fields["SERVER_NAME"] = $info['PUBLIC_URL'];
982  }
983 
984  $eventName = static::EVENT_ON_CHECK_PRINT_SEND_EMAIL;
985  $event = new \CEvent;
986  $event->Send($eventName, $order->getField('LID'), $fields, "N");
987 
988  if ($entity instanceof Payment)
989  {
990  static::addSentEvent('p'.$entity->getId(), $eventName);
991  }
992  elseif ($entity instanceof Shipment)
993  {
994  static::addSentEvent('s'.$entity->getId(), $eventName);
995  }
996  }
997 
998  return $result;
999  }

◆ sendShipmentAllowDelivery()

static sendShipmentAllowDelivery ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 849

850  {
851  $result = new Result();
852 
853  if (static::isNotifyDisabled())
854  {
855  return $result;
856  }
857 
858  if (!$entity instanceof Shipment)
859  {
860  throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Shipment');
861  }
862 
863  if (static::hasSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME))
864  {
865  return $result;
866  }
867 
868  /** @var ShipmentCollection $shipmentCollection */
869  if (!$shipmentCollection = $entity->getCollection())
870  {
871  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
872  return $result;
873  }
874 
875  /** @var Order $order */
876  if (!$order = $shipmentCollection->getOrder())
877  {
878  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
879  return $result;
880  }
881 
882  if (!$order->isAllowDelivery())
883  {
884  return $result;
885  }
886 
887 
888  $fields = Array(
889  "ORDER_ID" => $order->getField("ACCOUNT_NUMBER"),
890  "ORDER_REAL_ID" => $order->getField("ID"),
891  "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
892  "ORDER_DATE" => $order->getDateInsert()->toString(),
893  "SHIPMENT_ID" => $entity->getId(),
894  "SHIPMENT_DATE" => $entity->getField("DATE_INSERT")->toString(),
895  "EMAIL" => static::getUserEmail($order),
896  "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
897  "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : ""
898  );
899 
900  $eventName = static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME;
901  $send = true;
902 
903  foreach(GetModuleEvents("sale", static::EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL, true) as $oldEvent)
904  {
905  if (ExecuteModuleEventEx($oldEvent, array($order->getId(), &$eventName, &$fields)) === false)
906  {
907  $send = false;
908  }
909  }
910 
911  if($send)
912  {
913  $event = new \CEvent;
914  $event->Send($eventName, $order->getField('LID'), $fields, "Y", "", array(), static::getOrderLanguageId($order));
915  }
916 
917  \CSaleMobileOrderPush::send(static::EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY, array("ORDER" => static::getOrderFields($order)));
918 
919  static::addSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME);
920 
921  return $result;
922  }

◆ sendShipmentStatusChange()

static sendShipmentStatusChange ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 460

461  {
462  $result = new Result();
463 
464  if (static::isNotifyDisabled())
465  {
466  return $result;
467  }
468 
469  if (!$entity instanceof Shipment)
470  {
471  throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Shipment');
472  }
473 
474  $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
475 
476  if (static::hasSentEvent('s'.$entity->getId(), $statusEventName))
477  {
478  return $result;
479  }
480 
481  /** @var Internals\Fields $fields */
482  $fields = $entity->getFields();
483  $originalValues = $fields->getOriginalValues();
484 
485  if (array_key_exists('STATUS_ID', $originalValues) && $originalValues['STATUS_ID'] == $entity->getField("STATUS_ID"))
486  {
487  return $result;
488  }
489 
490  static $cacheSiteData = array();
491 
492  /** @var ShipmentCollection $shipmentCollection */
493  if (!$shipmentCollection = $entity->getCollection())
494  {
495  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
496  return $result;
497  }
498 
499  /** @var Order $order */
500  if (!$order = $shipmentCollection->getOrder())
501  {
502  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
503  return $result;
504  }
505 
506 
507  if (!isset($cacheSiteData[$order->getSiteId()]))
508  {
509  $siteRes = \CSite::GetByID($order->getSiteId());
510  $siteData = $siteRes->Fetch();
511  }
512  else
513  {
514  $siteData = $cacheSiteData[$order->getSiteId()];
515  }
516 
517  $statusData = Internals\StatusTable::getList(array(
518  'select' => array(
519  'ID',
520  'NOTIFY',
521  'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME',
522  ),
523  'filter' => array(
524  '=ID' => $entity->getField("STATUS_ID"),
525  '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => $siteData['LANGUAGE_ID'],
526  '=TYPE' => DeliveryStatus::TYPE
527  ),
528  'limit' => 1,
529  ))->fetch();
530 
531  if (!empty($statusData) && $statusData['NOTIFY'] == "Y")
532  {
533  $isSend = true;
534 
535  $fields = array(
536  "ORDER_ID" => $order->getField("ACCOUNT_NUMBER"),
537  "ORDER_REAL_ID" => $order->getField("ID"),
538  "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
539  "ORDER_DATE" => $order->getDateInsert()->toString(),
540  "SHIPMENT_ID" => $entity->getId(),
541  "SHIPMENT_DATE" => $entity->getField("DATE_INSERT")->toString(),
542  "SHIPMENT_STATUS" => $statusData["NAME"],
543  "EMAIL" => static::getUserEmail($order),
544  "TEXT" => "",
545  "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER["SERVER_NAME"]),
546  "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : ""
547  );
548 
549  $eventManager = Main\EventManager::getInstance();
550  if ($eventsList = $eventManager->findEventHandlers('sale', static::EVENT_SHIPMENT_STATUS_EMAIL))
551  {
552  $event = new Main\Event('sale', static::EVENT_SHIPMENT_STATUS_EMAIL, array(
553  'EVENT_NAME' => $statusEventName,
554  'VALUES' => $fields
555  ));
556  $event->send();
557 
558  if ($event->getResults())
559  {
560  /** @var Main\EventResult $eventResult */
561  foreach($event->getResults() as $eventResult)
562  {
563  if($eventResult->getType() === Main\EventResult::ERROR)
564  {
565  $isSend = false;
566  }
567  elseif($eventResult->getType() == Main\EventResult::SUCCESS)
568  {
569  if ($eventResultParams = $eventResult->getParameters())
570  {
571  /** @var Result $eventResultData */
572  if (!empty($eventResultParams) && is_array($eventResultParams))
573  {
574  if (!empty($eventResultParams['EVENT_NAME']))
575  {
576  $statusEventName = $eventResultParams['EVENT_NAME'];
577  }
578 
579  if (!empty($eventResultParams['VALUES']) && is_array($eventResultParams['VALUES']))
580  {
581  $fields = $eventResultParams['VALUES'];
582  }
583  }
584  }
585  }
586  }
587  }
588  }
589 
590  if($isSend)
591  {
592  $b = '';
593  $o = '';
594  $eventMessage = new \CEventMessage;
595  $eventMessageRes = $eventMessage->GetList(
596  $b,
597  $o,
598  array(
599  "EVENT_NAME" => $statusEventName,
600  "SITE_ID" => $order->getSiteId(),
601  'ACTIVE' => 'Y'
602  )
603  );
604  if (!($eventMessageData = $eventMessageRes->Fetch()))
605  {
606  $statusEventName = static::EVENT_DEFAULT_STATUS_CHANGED_ID.$entity->getField("STATUS_ID");
607  }
608 
609  unset($o, $b);
610  $event = new \CEvent;
611  $event->Send($statusEventName, $order->getSiteId(), $fields, "Y", "", array(), $siteData['LANGUAGE_ID']);
612  }
613  }
614 
615  static::addSentEvent('s'.$entity->getId(), $statusEventName);
616 
617  return $result;
618  }

◆ sendShipmentTrackingNumberChange()

static sendShipmentTrackingNumberChange ( Internals\Entity  $entity)
static
Аргументы
Internals\Entity$entity
Возвращает
Result
Исключения
Main

См. определение в файле sale/lib/notify.php строка 777

778  {
779  $result = new Result();
780 
781  if (static::isNotifyDisabled())
782  {
783  return $result;
784  }
785 
786  if (!$entity instanceof Shipment)
787  {
788  throw new Main\ArgumentTypeException('entity', '\Bitrix\Sale\Shipment');
789  }
790 
791  if (static::hasSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME))
792  {
793  return $result;
794  }
795 
796  /** @var ShipmentCollection $shipmentCollection */
797  if (!$shipmentCollection = $entity->getCollection())
798  {
799  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_SHIPMENT_COLLECTION_NOT_FOUND")));
800  return $result;
801  }
802 
803  /** @var Order $order */
804  if (!$order = $shipmentCollection->getOrder())
805  {
806  $result->addError(new ResultError(Main\Localization\Loc::getMessage("SALE_NOTIFY_ORDER_NOT_FOUND")));
807  return $result;
808  }
809 
810  /** @var Internals\Fields $fields */
811  $fields = $order->getFields();
812  $originalValues = $fields->getOriginalValues();
813 
814  if (array_key_exists('ACCOUNT_NUMBER', $originalValues) && $originalValues['ACCOUNT_NUMBER'] == $order->getField("ACCOUNT_NUMBER"))
815  {
816  return $result;
817  }
818 
819  $accountNumber = $order->getField("ACCOUNT_NUMBER");
820 
821  $emailFields = Array(
822  "ORDER_ID" => $accountNumber,
823  "ORDER_REAL_ID" => $order->getField("ID"),
824  "ORDER_ACCOUNT_NUMBER_ENCODE" => urlencode(urlencode($order->getField("ACCOUNT_NUMBER"))),
825  "ORDER_DATE" => $order->getDateInsert()->toString(),
826  "ORDER_USER" => static::getUserName($order),
827  "ORDER_TRACKING_NUMBER" => $entity->getField('TRACKING_NUMBER'),
828  "BCC" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER['SERVER_NAME']),
829  "EMAIL" => static::getUserEmail($order),
830  "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@".$_SERVER['SERVER_NAME']),
831  "ORDER_PUBLIC_URL" => Helpers\Order::isAllowGuestView($order) ? Helpers\Order::getPublicLink($order) : ""
832  );
833 
834  $event = new \CEvent;
835  $event->send(static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME, $order->getField("LID"), $emailFields, "Y", "", array(), static::getOrderLanguageId($order));
836 
837  static::addSentEvent('s'.$entity->getId(), static::EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME);
838 
839  return $result;
840  }

◆ setNotifyDisable()

static setNotifyDisable (   $value)
static
Аргументы
$value

См. определение в файле sale/lib/notify.php строка 1585

1586  {
1587  static::$disableNotify = ($value === true);
1589  }

Поля

◆ $cacheUserData

$cacheUserData = array()
staticprotected

См. определение в файле sale/lib/notify.php строка 62

◆ $disableNotify

$disableNotify = false
staticprotected

См. определение в файле sale/lib/notify.php строка 66

◆ $sentEventList

$sentEventList = array()
staticprotected

См. определение в файле sale/lib/notify.php строка 64

◆ EVENT_DEFAULT_STATUS_CHANGED_ID

const EVENT_DEFAULT_STATUS_CHANGED_ID = "SALE_STATUS_CHANGED_"

См. определение в файле sale/lib/notify.php строка 48

◆ EVENT_MOBILE_PUSH_ORDER_CANCELED

const EVENT_MOBILE_PUSH_ORDER_CANCELED = "ORDER_CANCELED"

См. определение в файле sale/lib/notify.php строка 57

◆ EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR

const EVENT_MOBILE_PUSH_ORDER_CHECK_ERROR = "ORDER_CHECK_ERROR"

См. определение в файле sale/lib/notify.php строка 59

◆ EVENT_MOBILE_PUSH_ORDER_CREATED

const EVENT_MOBILE_PUSH_ORDER_CREATED = "ORDER_CREATED"

См. определение в файле sale/lib/notify.php строка 55

◆ EVENT_MOBILE_PUSH_ORDER_PAID

const EVENT_MOBILE_PUSH_ORDER_PAID = "ORDER_PAYED"

См. определение в файле sale/lib/notify.php строка 58

◆ EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE

const EVENT_MOBILE_PUSH_ORDER_STATUS_CHANGE = "ORDER_STATUS_CHANGED"

См. определение в файле sale/lib/notify.php строка 56

◆ EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY

const EVENT_MOBILE_PUSH_SHIPMENT_ALLOW_DELIVERY = "ORDER_DELIVERY_ALLOWED"

См. определение в файле sale/lib/notify.php строка 60

◆ EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL

const EVENT_ON_CHECK_PRINT_ERROR_SEND_EMAIL = "SALE_CHECK_PRINT_ERROR"

См. определение в файле sale/lib/notify.php строка 35

◆ EVENT_ON_CHECK_PRINT_SEND_EMAIL

const EVENT_ON_CHECK_PRINT_SEND_EMAIL = "SALE_CHECK_PRINT"

См. определение в файле sale/lib/notify.php строка 34

◆ EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL

const EVENT_ON_ORDER_ALLOW_PAY_STATUS_EMAIL = "OnSaleOrderAllowPayStatusEMail"

См. определение в файле sale/lib/notify.php строка 53

◆ EVENT_ON_ORDER_CANCEL_SEND_EMAIL

const EVENT_ON_ORDER_CANCEL_SEND_EMAIL = "OnOrderCancelSendEmail"

См. определение в файле sale/lib/notify.php строка 39

◆ EVENT_ON_ORDER_NEW_SEND_EMAIL

const EVENT_ON_ORDER_NEW_SEND_EMAIL = "OnOrderNewSendEmail"

См. определение в файле sale/lib/notify.php строка 28

◆ EVENT_ON_ORDER_PAID_SEND_EMAIL

const EVENT_ON_ORDER_PAID_SEND_EMAIL = "OnOrderPaySendEmail"

См. определение в файле sale/lib/notify.php строка 37

◆ EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL

const EVENT_ON_SHIPMENT_DELIVER_SEND_EMAIL = "OnOrderDeliverSendEmail"

См. определение в файле sale/lib/notify.php строка 31

◆ EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME

const EVENT_ORDER_ALLOW_PAY_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_ALLOW_PAY"

См. определение в файле sale/lib/notify.php строка 52

◆ EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME

const EVENT_ORDER_CANCEL_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_CANCEL"

См. определение в файле sale/lib/notify.php строка 42

◆ EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME

const EVENT_ORDER_NEW_SEND_EMAIL_EVENT_NAME = "SALE_NEW_ORDER"

См. определение в файле sale/lib/notify.php строка 29

◆ EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME

const EVENT_ORDER_PAID_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_PAID"

См. определение в файле sale/lib/notify.php строка 41

◆ EVENT_ORDER_STATUS_CHANGED_SEND_EMAIL_EVENT_NAME

const EVENT_ORDER_STATUS_CHANGED_SEND_EMAIL_EVENT_NAME = "SALE_STATUS_CHANGED"

См. определение в файле sale/lib/notify.php строка 44

◆ EVENT_ORDER_STATUS_EMAIL

const EVENT_ORDER_STATUS_EMAIL = "OnSaleStatusEMail"

См. определение в файле sale/lib/notify.php строка 26

◆ EVENT_ORDER_STATUS_SEND_EMAIL

const EVENT_ORDER_STATUS_SEND_EMAIL = "OnOrderStatusSendEmail"

См. определение в файле sale/lib/notify.php строка 25

◆ EVENT_ORDER_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME

const EVENT_ORDER_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_TRACKING_NUMBER"

См. определение в файле sale/lib/notify.php строка 43

◆ EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME

const EVENT_SHIPMENT_DELIVER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_DELIVERY"

См. определение в файле sale/lib/notify.php строка 32

◆ EVENT_SHIPMENT_STATUS_EMAIL

const EVENT_SHIPMENT_STATUS_EMAIL = "OnSaleShipmentStatusEMail"

См. определение в файле sale/lib/notify.php строка 50

◆ EVENT_SHIPMENT_STATUS_SEND_EMAIL

const EVENT_SHIPMENT_STATUS_SEND_EMAIL = "OnSaleShipmentStatusSendEmail"

См. определение в файле sale/lib/notify.php строка 49

◆ EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME

const EVENT_SHIPMENT_TRACKING_NUMBER_SEND_EMAIL_EVENT_NAME = "SALE_ORDER_TRACKING_NUMBER"

См. определение в файле sale/lib/notify.php строка 45


Объявления и описания членов класса находятся в файле:
Bitrix\Sale\EventActions\getEventNotifyMap
static getEventNotifyMap()
Definition: eventactions.php:69
Bitrix\Main\Config
Definition: main/lib/config/configuration.php:2
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
Bitrix\Sale\Helpers\Order\isAllowGuestView
static isAllowGuestView(Sale\Order $order)
Check ability to view order is not an authorized user.
Definition: sale/lib/helpers/order.php:19
Bitrix\Sale\Registry\REGISTRY_TYPE_ORDER
const REGISTRY_TYPE_ORDER
Definition: sale/lib/registry.php:16
Bitrix\Sale\Compatible\DiscountCompatibility\getOldDiscountResult
static getOldDiscountResult()
Return result discount list in old format.
Definition: discountcompatibility.php:773
Bitrix\Sale\OrderStatus\TYPE
const TYPE
Definition: orderstatus.php:14
Bitrix\Sale\Helpers\Order\getPublicLink
static getPublicLink(Sale\Order $order)
Return link to order for an unauthorized users.
Definition: sale/lib/helpers/order.php:35
Bitrix\Main\Config\Option\get
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.
Definition: main/lib/config/option.php:29
Bitrix\Main\Type
Definition: main/lib/type/collection.php:2
Bitrix\Main\EventManager\getInstance
static getInstance()
Definition: main/lib/eventmanager.php:34
Bitrix\Sale\Compatible\EventCompatibility\setDisableMailSend
static setDisableMailSend($value)
Definition: sale/lib/compatible/eventcompatibility.php:1354
Bitrix\Sale\TradingPlatform\Platform\LINK_TYPE_PUBLIC_DETAIL_ORDER
const LINK_TYPE_PUBLIC_DETAIL_ORDER
Definition: platform.php:21
Bitrix\Main\EventResult\ERROR
const ERROR
Definition: main/lib/eventresult.php:8
Bitrix\Main\EventResult\SUCCESS
const SUCCESS
Definition: main/lib/eventresult.php:7
Bitrix\Sale\DeliveryStatus\TYPE
const TYPE
Definition: deliverystatus.php:14
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Executes the query and returns selection by parameters of the query.
Definition: main/lib/orm/data/datamanager.php:438
Bitrix\Sale\Cashbox\Manager\getCashboxFromCache
static getCashboxFromCache($cashboxId)
Definition: sale/lib/cashbox/manager.php:157
Bitrix\Sale\Cashbox\CheckManager\getLastPrintableCheckInfo
static getLastPrintableCheckInfo(Sale\Internals\CollectableEntity $entity)
Definition: checkmanager.php:1114
Bitrix\Main\Context\getCurrent
static getCurrent()
Static method returns current instance of context.
Definition: main/lib/context.php:194