$bxEventManager = \Bitrix\Main\EventManager::getInstance();
$bxEventManager->addEventHandler(
'sale',
'OnSaleShipmentEntitySaved',
array(
"\\Gricuk\\Shipment",
"onSaleShipmentSavedHandler"
)
);
<?php
namespace Gricuk;
use Bitrix\Main\Event;
use Bitrix\Main\EventResult;
use Bitrix\Main\Result;
class Shipment
{
public static function onSaleShipmentSavedHandler(\Bitrix\Main\Event $event)
{
/** @var \Bitrix\Sale\Shipment $shipment */
$shipment = $event->getParameter("ENTITY");
$oldValues = $event->getParameter("VALUES");
$shipmentFields = $shipment->getFieldValues();
/**
* Ключ - статус ДОСТАВКИ
* Значение - статус ЗАКАЗА
*/
$statusMap = [
"DR" => "F",
"DB" => "RS"
];
if (isset($statusMap[$shipmentFields["STATUS_ID"]])) {
try {
$orderId = $shipment->getParentOrderId();
$order = \Bitrix\Sale\Order::load($orderId);
$order->setField("STATUS_ID", $statusMap[$shipmentFields["STATUS_ID"]]);
/** @var Result $saveResult */
$saveResult = $order->save();
if (!$saveResult->isSuccess()) {
\Bitrix\Main\Diag\Debug::dumpToFile($saveResult, '$saveResult', 'onSaleShipmentSavedHandler.log');
}
} catch (\Exception $e) {
\Bitrix\Main\Diag\Debug::dumpToFile($e, '$e', 'onSaleShipmentSavedHandler.log');
}
}
}
}