Where is the bug in the code sending the letter?


I need to make it so that when the order status is "Order is adjusted" and if you change the order, save the updated order, the customer sent an email with a new list of products.
Moreover, the letter must go as many times as the order is edited.

Add in init.php the following code:

AddEventHandler("sale", "OnSaleOrderSaved", "SendCorrectedOrder");

SendCorrectedOrder function($ID) {
 if (CModule::IncludeModule("sale"))
 $arOrder = CSaleOrder::GetByID($ID);

 if($arOrder["STATUS_ID"] == "CR") {

 $payerName = "";
 $payerEMail = "";

 $userId = $arOrder["USER_ID"];

 $dbUser = CUser::GetByID($userId);
 if ($arUser = $dbUser->Fetch())
 if (strlen($payerName) <= 0)
 $payerName = $arUser["NAME"].((strlen($arUser["NAME"])<=0 || strlen($arUser["LAST_NAME"])<=0) ? "" : "").$arUser["LAST_NAME"];
 if (strlen($payerEMail) <= 0)
 $payerEMail = $arUser["EMAIL"]; 

 $arEmailFields = Array(
 "ORDER_ID" => $arOrder["ID"],
 "ORDER_DATE" => $arOrder["DATE_INSERT"],
 "ORDER_USER" => $payerName,
 "BCC" => COption::GetOptionString("sale", "order_email", "order@".$_SERVER['SERVER_NAME']),
 "EMAIL" => $payerEMail,
 "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@".$_SERVER['SERVER_NAME'])

 $event = new CEvent;
 $event->Send("SALE_STATUS_CHANGED_CR", $arOrder["LID"], $arEmailFields, "N");

And letters cease to come at all, i.e. there is some mistake, but can't figure out what it is... Help, please. What is wrong here?
April 4th 20 at 13:08
0 answer

Find more questions by tags 1C-Bitrix