/** * @param Main\Event $event * * @return Main\EventResult */ public static function onSaleOrderCancelSendEmail(Main\Event $event) { $parameters = $event->getParameters(); /** @var Sale\Order $order */ $order = $parameters[0]; if (!$order instanceof Sale\Order) { return new Main\EventResult(Main\EventResult::ERROR, new Sale\ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_COMPATIBILITY_ORDER_CANCEL_SEND_EMAIL_WRONG_ORDER'), 'SALE_EVENT_COMPATIBILITY_ORDER_CANCEL_SEND_EMAIL_WRONG_ORDER'), 'sale'); } $id = $order->getId(); $value = $order->getField('CANCELED'); $description = $order->getField('REASON_CANCELED'); if ($value == "Y") { $userEmail = ""; /** @var Sale\PropertyValueCollection $propertyCollection */ if ($propertyCollection = $order->getPropertyCollection()) { if ($propUserEmail = $propertyCollection->getUserEmail()) { $userEmail = $propUserEmail->getValue(); } } if (strval($userEmail) == '') { $resUser = \CUser::GetByID($order->getUserId()); if ($userData = $resUser->Fetch()) { $userEmail = $userData["EMAIL"]; } } $fields = array("ORDER_ID" => $order->getField("ACCOUNT_NUMBER"), "ORDER_DATE" => $order->getDateInsert()->toString(), "EMAIL" => $userEmail, "ORDER_CANCEL_DESCRIPTION" => $description, "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@" . $_SERVER["SERVER_NAME"])); $eventName = "SALE_ORDER_CANCEL"; $send = true; foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ON_ORDER_CANCEL_SEND_EMAIL, true) as $oldEvent) { if (ExecuteModuleEventEx($oldEvent, array($id, &$eventName, &$fields)) === false) { $send = false; } } if ($send) { $event = new \CEvent(); $event->Send($eventName, $order->getField('LID'), $fields, "N"); } $orderFields = null; /** @var Sale\Result $r */ $r = OrderCompatibility::getOrderFields($order); if ($r->isSuccess()) { if ($resultOrderFieldsData = $r->getData()) { if (!empty($resultOrderFieldsData['ORDER_FIELDS']) && is_array($resultOrderFieldsData['ORDER_FIELDS'])) { $orderFields = $resultOrderFieldsData['ORDER_FIELDS']; } } } \CSaleMobileOrderPush::send("ORDER_CANCELED", array("ORDER" => $orderFields)); if (Main\Loader::includeModule("statistic")) { \CStatEvent::AddByEvents("eStore", "order_cancel", $id, "", $order->getField("STAT_GID")); } } return new Main\EventResult(Main\EventResult::SUCCESS, null, 'sale'); }
$strOrderList .= "\n"; } $arFields = array("ORDER_ID" => $ORDER_ID, "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", SITE_ID))), "ORDER_USER" => strlen($payerName) > 0 ? $payerName : $USER->GetFullName(), "PRICE" => SaleFormatCurrency($arBasketItems["PRICE"], $arBasketItems["CURRENCY"]), "BCC" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "EMAIL" => strlen($payerEMail) > 0 ? $payerEMail : $USER->GetEmail(), "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "DELIVERY_PRICE" => $arBasketItems["PRICE_DELIVERY"]); $eventName = "SALE_NEW_ORDER"; $bSend = true; foreach (GetModuleEvents("sale", "OnOrderNewSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ORDER_ID, &$eventName, &$arFields)) === false) { $bSend = false; } } if ($bSend) { $event = new CEvent(); $event->Send($eventName, SITE_ID, $arFields, "N"); } /*end mail*/ CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER_ID" => $arFields["ORDER_ID"])); if (Loader::includeModule("statistic")) { $event1 = "eStore"; $event2 = "order_confirm"; $event3 = $arResult["ORDER_ID"]; $e = $event1 . "/" . $event2 . "/" . $event3; if (!is_array($_SESSION["ORDER_EVENTS"]) || is_array($_SESSION["ORDER_EVENTS"]) && !in_array($e, $_SESSION["ORDER_EVENTS"])) { CStatistic::Set_Event($event1, $event2, $event3); $_SESSION["ORDER_EVENTS"][] = $e; } } $urlError = ""; if ($PAYSYSTEM_ID == "account") { if (!CSaleUserAccount::DoPayOrderFromAccount($currentUserId, $arBasketItems["CURRENCY"], $ORDER_ID, $arBasketItems["PRICE"], array(), $arErrors)) { $urlError = "&erraccount=y"; }
); $eventName = "SALE_NEW_ORDER"; $bSend = true; foreach(GetModuleEvents("sale", "OnOrderNewSendEmail", true) as $arEvent) if (ExecuteModuleEventEx($arEvent, array($ID, &$eventName, &$arFields))===false) $bSend = false; if($bSend) { $event = new CEvent; $event->Send($eventName, $LID, $arFields, "N"); } CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER" => $arOrderNew)); } } else { foreach($arErrors as $val) { if (is_array($val)) $errorMessage .= $val["TEXT"]."<br>"; else $errorMessage .= $val; } } } elseif (!empty($arErrors)) {
public function processOrder($orderEbay) { Ebay::log(Logger::LOG_LEVEL_DEBUG, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING", $orderEbay["ExtendedOrderID"], print_r($orderEbay, true), $this->siteId); /* * only in this case order is completely ready for shipping */ if ($orderEbay["OrderStatus"] != "Completed" || !isset($orderEbay["CheckoutStatus"]["eBayPaymentStatus"]) || $orderEbay["CheckoutStatus"]["eBayPaymentStatus"] != "NoPaymentFailure") { Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_SKIPPED", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SKIPPED", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId); return array(); } $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance(); $settings = $ebay->getSettings(); if (!isset($settings[$this->siteId]["ORDER_PROPS"]) || !is_array($settings[$this->siteId]["ORDER_PROPS"])) { throw new SystemException("Can't get order props map"); } $propsMap = $settings[$this->siteId]["ORDER_PROPS"]; /* if(strtolower(SITE_CHARSET) != 'utf-8') $orderEbay = \Bitrix\Main\Text\Encoding::convertEncodingArray($orderEbay, 'UTF-8', SITE_CHARSET); */ $dbRes = OrderTable::getList(array("filter" => array("TRADING_PLATFORM_ID" => $ebay->getId(), "EXTERNAL_ORDER_ID" => $orderEbay["ExtendedOrderID"]))); if ($orderCorrespondence = $dbRes->fetch()) { Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_ALREADY_EXIST", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SKIPPED_EXIST", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId); return array(); } /** @var \Bitrix\Sale\Order $order */ $order = \Bitrix\Sale\Order::create($this->siteId); $order->setPersonTypeId($settings[$this->siteId]["PERSON_TYPE"]); $propsCollection = $order->getPropertyCollection(); /** @var \Bitrix\Sale\PropertyValueCollection $propCollection */ if (intval($propsMap["FIO"]) > 0) { $prop = $propsCollection->getItemByOrderPropertyId($propsMap["FIO"]); $prop->setValue($orderEbay["ShippingAddress"]["Name"]); } if (intval($propsMap["CITY"]) > 0) { $prop = $propsCollection->getItemByOrderPropertyId($propsMap["CITY"]); $prop->setValue($orderEbay["ShippingAddress"]["CityName"]); } if (intval($propsMap["PHONE"]) > 0) { $prop = $propsCollection->getItemByOrderPropertyId($propsMap["PHONE"]); $prop->setValue($orderEbay["ShippingAddress"]["Phone"]); } if (intval($propsMap["ZIP"]) > 0) { $prop = $propsCollection->getItemByOrderPropertyId($propsMap["ZIP"]); $prop->setValue($orderEbay["ShippingAddress"]["PostalCode"]); } if (intval($propsMap["ADDRESS"]) > 0) { $prop = $propsCollection->getItemByOrderPropertyId($propsMap["ADDRESS"]); $prop->setValue($orderEbay["ShippingAddress"]["CountryName"] . " " . $orderEbay["ShippingAddress"]["CityName"] . " " . $orderEbay["ShippingAddress"]["Street1"] . " " . (!empty($orderEbay["ShippingAddress"]["Street2"]) ? $orderEbay["ShippingAddress"]["Street2"] . " " : "")); } $basket = null; $bitrixOrderId = 0; $userId = 0; $orderLineItemsIds = array(); $transactionsArray = $this->normalizeTransactionsArray($orderEbay["TransactionArray"]); foreach ($transactionsArray as $transaction) { //if we have more than one transaction let's create user from the first if ($userId <= 0) { if (intval($propsMap["EMAIL"]) > 0 && !empty($transaction["Buyer"]["Email"])) { $prop = $propsCollection->getItemByOrderPropertyId($propsMap["EMAIL"]); $prop->setValue($transaction["Buyer"]["Email"]); $userId = $this->createUser($transaction["Buyer"]["Email"], array("NAME" => $transaction["Buyer"]["UserFirstName"], "LAST_NAME" => $transaction["Buyer"]["UserLastName"])); } if ($userId <= 0) { $userId = \CSaleUser::GetAnonymousUserID(); } } if (intval($userId > 0)) { $order->setFieldNoDemand("USER_ID", $userId); } $fUserId = null; if ($order->getUserId() > 0) { $fUserId = Fuser::getIdByUserId($order->getUserId()); } /** @var \Bitrix\Sale\Basket $basket */ if (!$basket) { $basket = \Bitrix\Sale\Basket::create($this->siteId); $basket->setFUserId($fUserId); } $items = array(); $isVariation = false; if (!empty($transaction["Item"])) { $items = Xml2Array::normalize($transaction["Item"]); } elseif (!empty($transaction["Variation"])) { $items = Xml2Array::normalize($transaction["Variation"]); $isVariation = true; } if (empty($items)) { Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_NOT_FOUND", $transaction["OrderLineItemID"], print_r($transaction, true), $this->siteId); continue; } foreach ($items as $transactionItem) { $ebaySku = $isVariation ? $this->getSkuVariation($transactionItem["SKU"]) : $this->getSku($transactionItem["SKU"]); if (strlen($ebaySku) <= 0) { Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_SKU_NOT_FOUND", $transaction["OrderLineItemID"], print_r($transaction, true), $this->siteId); continue; } $item = $basket->createItem('catalog', $ebaySku); $item->setField("PRODUCT_PROVIDER_CLASS", "CCatalogProductProvider"); $itemData = array("CUSTOM_PRICE" => "Y", "PRICE" => floatval($transaction["TransactionPrice"]), "QUANTITY" => floatval($transaction["QuantityPurchased"]), "NAME" => !empty($transactionItem["VariationTitle"]) ? $transactionItem["VariationTitle"] : $transactionItem["Title"], "CURRENCY" => SiteCurrencyTable::getSiteCurrency($this->siteId)); $data = Provider::getProductData($basket); if (!empty($data[$item->getBasketCode()])) { $itemData = array_merge($data[$item->getBasketCode()], $itemData); } else { $item->delete(); $item = $basket->createItem('', $ebaySku); } $res = $item->setFields($itemData); if ($res->isSuccess()) { $orderLineItemsIds[] = $transaction["OrderLineItemID"]; } else { foreach ($res->getErrors() as $error) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_TRANSACTION_ITEM_CREATE_ERROR", $transaction["OrderLineItemID"], $error->getMessage(), $this->siteId); } } } } $res = $order->setBasket($basket); if (!$res->isSuccess()) { foreach ($res->getErrors() as $error) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_CREATE_ERROR_SET_BASKET", $orderEbay["ExtendedOrderID"], $error->getMessage(), $this->siteId); } } //payments if (intval($settings[$this->siteId]["MAPS"]["PAYMENT"]["PayPal"]) > 0) { $payments = $order->getPaymentCollection(); /** @var \Bitrix\Sale\Payment $payment */ if ($payments->count() > 0) { foreach ($payments as $payment) { if ($payment->isPaid()) { $payment->setPaid("N"); } $payment->delete(); } } $payment = $payments->createItem(); $payment->setField('PAY_SYSTEM_ID', $settings[$this->siteId]["MAPS"]["PAYMENT"]["PayPal"]); $payment->setField('PAY_SYSTEM_NAME', "PayPal via Ebay"); if ($orderEbay["CheckoutStatus"]["eBayPaymentStatus"] == "NoPaymentFailure" && $orderEbay["MonetaryDetails"]["Payments"]["Payment"]["PaymentStatus"] && $orderEbay["MonetaryDetails"]["Payments"]["Payment"]["PaymentAmount"] == $orderEbay["Total"]) { $payment->setField("SUM", $orderEbay["AmountPaid"]); $payment->setPaid("Y"); } } //shipment if (intval($settings[$this->siteId]["MAPS"]["SHIPMENT"][$orderEbay["ShippingServiceSelected"]["ShippingService"]]) > 0) { $shipments = $order->getShipmentCollection(); /** @var \Bitrix\Sale\Shipment $shipment */ if ($shipments->count() > 0) { foreach ($shipments as $shipment) { if (!$shipment->isSystem()) { $shipment->delete(); } } } $shipment = $shipments->createItem(); $shipment->setField('DELIVERY_ID', $settings[$this->siteId]["MAPS"]["SHIPMENT"][$orderEbay["ShippingServiceSelected"]["ShippingService"]]); $shipment->setField('CUSTOM_PRICE_DELIVERY', "Y"); $shipment->setField('BASE_PRICE_DELIVERY', $orderEbay["ShippingServiceSelected"]["ShippingServiceCost"]); $basket = $order->getBasket(); if ($basket) { $shipmentItemCollection = $shipment->getShipmentItemCollection(); $basketItems = $basket->getBasketItems(); foreach ($basketItems as $basketItem) { $shipmentItem = $shipmentItemCollection->createItem($basketItem); $shipmentItem->setQuantity($basketItem->getField('QUANTITY')); } } // todo: delivery price changed. Probably bug. $shipment->setField('BASE_PRICE_DELIVERY', $orderEbay["ShippingServiceSelected"]["ShippingServiceCost"]); } else { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_SHIPPING_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_NOT_MAPPED_SHIPPING", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"], "#EBAY_SHIPPING#" => $orderEbay["ShippingServiceSelected"]["ShippingService"])), $this->siteId); return 0; } // order status if (strlen($settings[$this->siteId]["STATUS_MAP"][$orderEbay["OrderStatus"]]) > 0) { switch ($settings[$this->siteId]["STATUS_MAP"][$orderEbay["OrderStatus"]]) { /* flags */ case "CANCELED": if (!$order->setField("CANCELED", "Y")) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_CANCELING_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_CANCEL_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId); } break; case "PAYED": $payments = $order->getPaymentCollection(); foreach ($payments as $payment) { $payment->setPaid("Y"); } break; case "ALLOW_DELIVERY": // we suggest that only one shipment exists $shipments = $order->getShipmentCollection(); foreach ($shipments as $shipment) { if (!$shipment->isSystem()) { if (!$shipment->allowDelivery()) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_ALLOW_DELIVERY_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_ALLOW_DELIVERY_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId); } } } break; case "DEDUCTED": $shipments = $order->getShipmentCollection(); foreach ($shipments as $shipment) { if (!$shipment->isSystem()) { if (!$shipment->setField('DEDUCTED', 'Y')) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_DEDUCTIOING_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_DEDUCT_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId); } } } break; /* statuses */ /* statuses */ default: $res = $order->setField("STATUS_ID", $settings[$this->siteId]["STATUS_MAP"][$orderEbay["OrderStatus"]]); /** @var \Bitrix\Sale\Result $res */ if (!$res->isSuccess()) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_CHANGE_STATUS_ERROR", $orderEbay["OrderLineItemID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SET_STATUS_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"], "#STATUS#" => $orderEbay["OrderStatus"])), $this->siteId); } } } $order->setField("PRICE", $orderEbay["Total"]); $order->setField("XML_ID", Ebay::TRADING_PLATFORM_CODE . "_" . $orderEbay["ExtendedOrderID"]); $res = $order->save(); if (!$res->isSuccess()) { foreach ($res->getErrors() as $error) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_SAVE_ERROR", $orderEbay["ExtendedOrderID"], print_r($error->getMessage(), true), $this->siteId); } } else { $bitrixOrderId = $order->getId(); Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_CREATED", $bitrixOrderId, Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SAVED", array("#ORDER_ID#" => $bitrixOrderId)), $this->siteId); \CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER_ID" => $bitrixOrderId)); $res = OrderTable::add(array("ORDER_ID" => $bitrixOrderId, "TRADING_PLATFORM_ID" => $ebay->getId(), "EXTERNAL_ORDER_ID" => $orderEbay["ExtendedOrderID"], "PARAMS" => array("ORDER_LINES" => $orderLineItemsIds, "ORDER_ID" => $orderEbay["OrderID"]))); if (!$res->isSuccess()) { foreach ($res->getErrors() as $error) { Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_DELIVERY_SAVE_ERROR", $orderEbay["ExtendedOrderID"], $error->getMessage(), $this->siteId); } } } // send confirmation if ($bitrixOrderId > 0 && !empty($orderLineItemsIds)) { $ebayFeed = \Bitrix\Sale\TradingPlatform\Ebay\Feed\Manager::createFeed("ORDER_ACK", $this->siteId); $sourceData = array(); foreach ($orderLineItemsIds as $id) { $sourceData[] = array("ORDER_ID" => $orderEbay["OrderID"], "ORDER_LINE_ITEM_ID" => $id); } $ebayFeed->setSourceData(array($sourceData)); $ebayFeed->processData(); } return $bitrixOrderId; }
public static function SetMark($ID, $comment = "", $userID = 0) { global $DB; $ID = IntVal($ID); if ($ID < 0) { return false; } $userID = IntVal($userID); $arFields = array("MARKED" => "Y", "REASON_MARKED" => $comment, "EMP_MARKED_ID" => $userID, "=DATE_MARKED" => $DB->GetNowFunction()); CSaleMobileOrderPush::send("ORDER_MARKED", array("ORDER_ID" => $ID)); return CSaleOrder::Update($ID, $arFields); }
protected function sendEmailNewOrder($newOrderId, $buyer) { global $DB; $strOrderList = ""; $baseLangCurrency = CSaleLang::GetLangCurrency($this->siteId); $orderNew = CSaleOrder::GetByID($newOrderId); $orderNew["BASKET_ITEMS"] = array(); $userEmail = $buyer["email"]; $fio = $buyer["last-name"] . (isset($buyer["first-name"]) ? $buyer["first-name"] : ""); $dbBasketTmp = CSaleBasket::GetList(array("SET_PARENT_ID" => "DESC", "TYPE" => "DESC", "NAME" => "ASC"), array("ORDER_ID" => $newOrderId), false, false, array("ID", "PRICE", "QUANTITY", "NAME")); while ($arBasketTmp = $dbBasketTmp->GetNext()) { $orderNew["BASKET_ITEMS"][] = $arBasketTmp; } $orderNew["BASKET_ITEMS"] = getMeasures($orderNew["BASKET_ITEMS"]); foreach ($orderNew["BASKET_ITEMS"] as $val) { if (CSaleBasketHelper::isSetItem($val)) { continue; } $measure = isset($val["MEASURE_TEXT"]) ? $val["MEASURE_TEXT"] : GetMessage("SALE_YMH_SHT"); $strOrderList .= $val["NAME"] . " - " . $val["QUANTITY"] . " " . $measure . ": " . SaleFormatCurrency($val["PRICE"], $baseLangCurrency); $strOrderList .= "\n"; } //send mail $arFields = array("ORDER_ID" => $orderNew["ACCOUNT_NUMBER"], "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", $this->siteId))), "ORDER_USER" => $fio, "PRICE" => SaleFormatCurrency($orderNew["PRICE"], $baseLangCurrency), "BCC" => COption::GetOptionString("sale", "order_email", "order@" . $_SERVER['SERVER_NAME']), "EMAIL" => array("PAYER_NAME" => $fio, "USER_EMAIL" => $userEmail), "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@" . $_SERVER['SERVER_NAME']), "DELIVERY_PRICE" => $orderNew["DELIVERY_PRICE"]); $eventName = "SALE_NEW_ORDER"; $bSend = true; foreach (GetModuleEvents("sale", "OnOrderNewSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($newOrderId, &$eventName, &$arFields)) === false) { $bSend = false; } } if ($bSend) { $event = new CEvent(); $event->Send($eventName, $this->siteId, $arFields, "N"); } CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER" => $orderNew)); }
$strOrderList .= "\n"; } } $arFields = array("ORDER_ID" => $arOrder["ACCOUNT_NUMBER"], "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", SITE_ID))), "ORDER_USER" => strlen($arUserResult["PAYER_NAME"]) > 0 ? $arUserResult["PAYER_NAME"] : $USER->GetFormattedName(false), "PRICE" => SaleFormatCurrency($orderTotalSum, $arResult["BASE_LANG_CURRENCY"]), "BCC" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "EMAIL" => strlen($arUserResult["USER_EMAIL"]) > 0 ? $arUserResult["USER_EMAIL"] : $USER->GetEmail(), "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "DELIVERY_PRICE" => $arResult["DELIVERY_PRICE"]); $eventName = "SALE_NEW_ORDER"; $bSend = true; foreach (GetModuleEvents("sale", "OnOrderNewSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($arResult["ORDER_ID"], &$eventName, &$arFields)) === false) { $bSend = false; } } if ($bSend) { $event = new CEvent(); $event->Send($eventName, SITE_ID, $arFields, "N"); } CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER_ID" => $arResult["ORDER_ID"])); } if (empty($arResult["ERROR"])) { if (Loader::includeModule("statistic")) { $event1 = "eStore"; $event2 = "order_confirm"; $event3 = $arResult["ORDER_ID"]; $e = $event1 . "/" . $event2 . "/" . $event3; if (!is_array($_SESSION["ORDER_EVENTS"]) || is_array($_SESSION["ORDER_EVENTS"]) && !in_array($e, $_SESSION["ORDER_EVENTS"])) { CStatistic::Set_Event($event1, $event2, $event3); $_SESSION["ORDER_EVENTS"][] = $e; } } foreach (GetModuleEvents("sale", "OnSaleComponentOrderOneStepComplete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($arResult["ORDER_ID"], $arOrder, $arParams)); }
/** * @param Main\Event $event * * @return Main\EventResult * @throws Main\ObjectNotFoundException */ public static function onSaleOrderStatusChangeSendEmail(Main\Event $event) { $parameters = $event->getParameters(); /** @var Sale\Order $basketItem */ $order = $parameters['ENTITY']; $value = $parameters['VALUE']; $oldValue = $parameters['OLD_VALUE']; if (!$order instanceof Sale\Order) { return new Main\EventResult(Main\EventResult::ERROR, new Sale\ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_COMPATIBILITY_ORDER_STATUS_CHANGE_WRONG_ORDER'), 'SALE_EVENT_COMPATIBILITY_ORDER_STATUS_CHANGE_WRONG_ORDER'), 'sale'); } $orderFields = array(); /** @var Sale\Result $resultOrderFields */ $resultOrderFields = OrderCompatibility::getOrderFields($order); if ($resultOrderFields->isSuccess()) { if ($orderFieldsResultData = $resultOrderFields->getData()) { if (!empty($orderFieldsResultData['ORDER_FIELDS']) && is_array($orderFieldsResultData['ORDER_FIELDS'])) { $orderFields = $orderFieldsResultData['ORDER_FIELDS']; } } } \CSaleMobileOrderPush::send(static::EVENT_COMPATIBILITY_MOBILE_PUSH_ORDER_STATUS_CHANGE, array("ORDER" => $orderFields)); $propertyCollection = $order->getPropertyCollection(); $userEmail = ""; /** @var Sale\PropertyValue $userEmailProperty */ if ($userEmailProperty = $propertyCollection->getUserEmail()) { $userEmail = $userEmailProperty->getValue(); } if (strval(trim($userEmail)) == '') { $userRes = \CUser::GetByID($order->getUserId()); if ($userData = $userRes->fetch()) { $userEmail = $userData["EMAIL"]; } } static $cacheSiteData = array(); if (!isset($cacheSiteData[$order->getSiteId()])) { $siteRes = \CSite::GetByID($order->getSiteId()); $siteData = $siteRes->Fetch(); } else { $siteData = $cacheSiteData[$order->getSiteId()]; } if (($statusData = \CSaleStatus::GetByID($order->getField("STATUS_ID"), $siteData['LANGUAGE_ID'])) && $statusData['NOTIFY'] == "Y") { $fields = array("ORDER_ID" => $order->getField("ACCOUNT_NUMBER"), "ORDER_DATE" => $order->getField("DATE_INSERT")->toString(), "ORDER_STATUS" => $statusData["NAME"], "EMAIL" => $userEmail, "ORDER_DESCRIPTION" => $statusData["DESCRIPTION"], "TEXT" => "", "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@" . $_SERVER["SERVER_NAME"])); foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ORDER_STATUS_EMAIL, true) as $oldEvent) { $fields["TEXT"] = ExecuteModuleEventEx($oldEvent, array($order->getId(), $statusData["ID"])); } $eventName = "SALE_STATUS_CHANGED_" . $order->getField("STATUS_ID"); $isSend = true; foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ORDER_STATUS_SEND_EMAIL, true) as $oldEvent) { if (ExecuteModuleEventEx($oldEvent, array($order->getId(), &$eventName, &$fields, $order->getField("STATUS_ID"))) === false) { $isSend = false; } } if ($isSend) { $b = ''; $o = ''; $eventMessage = new \CEventMessage(); $eventMessageRes = $eventMessage->GetList($b, $o, array("EVENT_NAME" => $eventName, "SITE_ID" => $order->getSiteId(), 'ACTIVE' => 'Y')); if (!($eventMessageData = $eventMessageRes->Fetch())) { $eventName = "SALE_STATUS_CHANGED"; } unset($o, $b); $event = new \CEvent(); $event->Send($eventName, $order->getSiteId(), $fields, "N"); } } return new Main\EventResult(Main\EventResult::SUCCESS, null, 'sale'); }
public static function notifyNewOrder($newOrderId, $siteId, $buyerEmail = "", $buyerFio = "") { if (strlen($newOrderId) <= 0) { throw new ArgumentNullException("newOrderId"); } if (strlen($siteId) <= 0) { throw new ArgumentNullException("siteId"); } global $DB; $strOrderList = ""; $baseLangCurrency = \CSaleLang::GetLangCurrency($siteId); $orderNew = \CSaleOrder::GetByID($newOrderId); $orderNew["BASKET_ITEMS"] = array(); $dbBasketTmp = \CSaleBasket::GetList(array("SET_PARENT_ID" => "DESC", "TYPE" => "DESC", "NAME" => "ASC"), array("ORDER_ID" => $newOrderId), false, false, array("ID", "PRICE", "QUANTITY", "NAME")); while ($arBasketTmp = $dbBasketTmp->GetNext()) { $orderNew["BASKET_ITEMS"][] = $arBasketTmp; } $orderNew["BASKET_ITEMS"] = getMeasures($orderNew["BASKET_ITEMS"]); foreach ($orderNew["BASKET_ITEMS"] as $val) { if (\CSaleBasketHelper::isSetItem($val)) { continue; } $measure = isset($val["MEASURE_TEXT"]) ? $val["MEASURE_TEXT"] : GetMessage("SALE_YMH_SHT"); $strOrderList .= $val["NAME"] . " - " . $val["QUANTITY"] . " " . $measure . ": " . SaleFormatCurrency($val["PRICE"], $baseLangCurrency); $strOrderList .= "\n"; } //send mail $arFields = array("ORDER_ID" => $orderNew["ACCOUNT_NUMBER"], "ORDER_DATE" => Date($DB->DateFormatToPHP(\CLang::GetDateFormat("SHORT", $siteId))), "ORDER_USER" => $buyerFio, "PRICE" => SaleFormatCurrency($orderNew["PRICE"], $baseLangCurrency), "BCC" => \COption::GetOptionString("sale", "order_email", "order@" . $_SERVER['SERVER_NAME']), "EMAIL_TO" => array("PAYER_NAME" => $buyerFio, "USER_EMAIL" => $buyerEmail), "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => \COption::GetOptionString("sale", "order_email", "order@" . $_SERVER['SERVER_NAME']), "DELIVERY_PRICE" => $orderNew["DELIVERY_PRICE"]); $eventName = "SALE_NEW_ORDER"; $bSend = true; foreach (GetModuleEvents("sale", "OnOrderNewSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($newOrderId, &$eventName, &$arFields)) === false) { $bSend = false; } } $emailSendRes = false; if ($bSend) { $event = new \CEvent(); $emailSendRes = $event->Send($eventName, $siteId, $arFields, "N"); } $pushSendResult = \CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER" => $orderNew)); return $emailSendRes && $pushSendResult; }
} } if ($isSavingOperation && $result->isSuccess()) { $res = OrderEdit::saveCoupons($order->getUserId(), $_POST); if (!$res) { $result->addError(new \Bitrix\Main\Entity\EntityError("Can't save coupons!")); } $res = $order->save(); if ($res->isSuccess()) { if (isset($_POST["BUYER_PROFILE_ID"])) { $profileId = intval($_POST["BUYER_PROFILE_ID"]); } else { $profileId = 0; } $profResult = OrderEdit::saveProfileData($profileId, $order, $_POST); \CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER_ID" => $order->getId())); if (isset($_POST["save"])) { LocalRedirect("/bitrix/admin/sale_order.php?lang=" . LANGUAGE_ID . GetFilterParams("filter_", false)); } else { LocalRedirect("/bitrix/admin/sale_order_edit.php?lang=" . LANGUAGE_ID . "&ID=" . $order->getId() . GetFilterParams("filter_", false)); } } else { $result->addErrors($res->getErrors()); } } } else { $result->addError(new \Bitrix\Main\Entity\EntityError("Can't create order!")); } } elseif ($createWithProducts) { $formData = array("USER_ID" => $_GET["USER_ID"], "SITE_ID" => $_GET["SITE_ID"]); $formData["PRODUCT"] = array();