A
A
Alexander2021-06-09 10:53:02
1C-Bitrix
Alexander, 2021-06-09 10:53:02

How to add a text file with order data to a letter with order data sent to a customer?

Actually, the question is in the subject, how to add a text file with order data to the letter with order data sent to the buyer?
I don't know where to drop

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2021-06-12
@udjin123

Mail events allow you to attach files to a letter, but you cannot intervene in the SALE_NEW_ORDER event of sending a letter about a new order. As an option, deactivate the regular mail event SALE_NEW_ORDER, create your own and call it by attaching a file by subscribing to an event in php_interface to create an order, an event from d7 - OnSaleOrderSaved to check the IS_NEW flag. Documentation for it here

S
Sergey, 2021-06-14
@Firsov36

Subscribe to the OnBeforeEventAdd event
(taken from a very old working code, cutting out part of the code not for general viewing, but the idea should be clear)

AddEventHandler("main", "OnBeforeEventAdd", array("NewOrderWithPdf", "OnBeforeEventAddHandler"));

class NewOrderWithPdf
{
    public function OnBeforeEventAddHandler($event, $lid, $arFields)
    {
        if ($event == "SALE_NEW_ORDER" && $arFields['ORDER_ID'] > 0) {
            $arrMailProps["EVENT_NAME"] = $event;
            $arrMailProps["LID"] = $lid;
            $arrMailProps["C_FIELDS"] = $arFields;
            $arrMailProps['FILE'] = [$pathToFile];

            \Bitrix\Main\Mail\Event::send($arrMailProps);

            return false;
        }

        return true;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question