Interception of sending a letter when placing an order in Bitrix
The last notes
All English-language materials have been translated fully automatically using the Google service
Often, I am tasked with adding or updating data sent by the sale.order.ajax component by a letter to a client when a new order is formed.
AddEventHandler ("sale", "OnOrderNewSendEmail", Array ("OnOrderNewSendEmailClass", "OnOrderNewSendEmailModify"));
class OnOrderNewSendEmailClass
{
function OnOrderNewSendEmailModify ($ orderID, & $ eventName, & $ arFields)
{
if (CModule :: IncludeModule ("sale") && CModule :: IncludeModule ("iblock"))
{
// Add new data to the email template variable
$ arFields ["SOME_ADDITIONAL_VARIABLE"] = $ newData;
// You can work with order data using the $ orderID variable
// For example, you can get the contents of the basket and display the names of the finished products in a letter to the user
$ items = CSaleBasket :: GetList (array ("NAME" => "DESC"), array ("ORDER_ID" => $ orderID), false, false, array ("*"));
$ temp = '';
while ($ item = $ items-> Fetch ()) {
$ temp. = 'Name:'. $ item ['NAME']. ' ('. $ item [' QUANTITY '].') / r / n / ';
}
// Fill in new variables with the name and quantity of the product
$ arFields ["ORDER_ITEMS"] = $ temp;
// You can also get the composition of the order and post it to the variables of the mail template
// $ order = CSaleOrder :: GetByID ($ orderID); // Getting the order content
$ props = CSaleOrderPropsValue :: GetOrderProps ($ orderID); // Get order properties
// You can view the property ID in the store settings, on the "Property List" page
// This page is located at Store -> Settings -> Order properties -> List of properties
$ temp = '';
while ($ prop = $ props-> Fetch ()) {
if ($ prop ['ORDER_PROPS_ID'] == $ id) {// where $ id is the id of the property on the specified page
$ temp. = 'New property:'. $ prop ['VALUE'];
}
}
$ arFields ["ORDER_PROPS"] = $ temp;
}
}
}
Comments