Answer the question
In order to leave comments, you need to log in
How to display information in the order email depending on the type of delivery?
Good afternoon!
For example, if the user has chosen the "Pickup" delivery method, specify the store's working hours in the order letter. Or if you chose "Curre" - the time frame in which the courier can arrive
Answer the question
In order to leave comments, you need to log in
Can be done through the OnBeforeEventAdd event handler . It is called when a mail event is added to the b_event table .
It is possible to catch a mail event of the SALE_NEW_ORDER type in the handler. In it, having the order ID, get all the additional information and add it to a new field in the $arFields array, for example $arFields["DELIVERY_INFO"]. And already in the mail template, display this information by analogy with other fields #DELIVERY_INFO#.
The link to the documentation has an example of working with this event. I also solved another problem (adding a tracking link), but the principle will be the same:
public static function addTrackingUrlToMail(&$event, &$lid, &$arFields)
{
if ($event == "SALE_ORDER_TRACKING_NUMBER") {
$order = \Bitrix\Sale\Order::load($arFields["ORDER_REAL_ID"]);
$shipmentCollection = $order->getShipmentCollection();
/* @var $shipmentColletion \Bitrix\Sale\ShipmentCollection */
$deliveryId = 0;
foreach ($shipmentCollection as $shipment) {
/* @var $shipment \Bitrix\Sale\Shipment */
if (!$shipment->isSystem()) {
$delivery = $shipment->getDelivery();
$deliveryId = $delivery->getParentId();
$arFields["DELIVERY_NAME"] = $delivery->getNameWithParent();
}
}
$urlTemplate = "<a href='%s'>%s</a>";
$trackMessage = "";
if (\Gricuk\Sale\Delivery\Helper::isRussianPostDelivery($deliveryId)) {
$trackUrl = "https://www.pochta.ru/tracking#{$arFields["ORDER_TRACKING_NUMBER"]}";
$trackMessage = sprintf($urlTemplate, $trackUrl, $trackUrl);
} else {
switch ($deliveryId) {
case Conf::ID_DELIVERY_CDEK://ID службы доставки СДЕК
$trackUrl = "https://www.cdek.ru/track.html?order_id={$arFields["ORDER_TRACKING_NUMBER"]}";
$trackMessage = sprintf($urlTemplate, $trackUrl, $trackUrl);
break;
}
}
$arFields["TRACK_URL"] = $trackMessage;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question