Skip to content

Instantly share code, notes, and snippets.

@brstcrt
Forked from nafilimonov/OnOrderNewSendEmail.php
Created January 15, 2022 15:41
Show Gist options
  • Select an option

  • Save brstcrt/f99fe5a47ecfdc8a411123866c8b80c4 to your computer and use it in GitHub Desktop.

Select an option

Save brstcrt/f99fe5a47ecfdc8a411123866c8b80c4 to your computer and use it in GitHub Desktop.

Revisions

  1. @nafilimonov nafilimonov revised this gist Jun 30, 2018. No changes.
  2. @nafilimonov nafilimonov revised this gist Nov 17, 2017. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions OnOrderNewSendEmail.php
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,6 @@ function OnOrderNewSendEmailNewFields($orderID, &$eventName, &$arFields){
    $arFields["COUNTRY"] = $country;
    $arFields["CITY"] = $city;
    $arFields["ADDRESS"] = $address;
    $payment = CSalePaySystem::GetByID($arOrder['PAY_SYSTEM_ID']);
    $arFields["PAYMENT"] = $payment['NAME'];

    //-- получаем название службы доставки
    if(intval($arOrder["DELIVERY_ID"])<=0){
    @@ -49,9 +47,15 @@ function OnOrderNewSendEmailNewFields($orderID, &$eventName, &$arFields){
    $deliveryName = $arDeliv["NAME"];
    }

    $arFields["DELIVERY"] = $deliveryName;
    $arFields["DELIVERY"] = $deliveryName;
    $arFields["PRICE_DELIVERY"] = $arOrder['PRICE_DELIVERY'];

    //-- получаем название платежной системы
    $arPaySystem = CSalePaySystem::GetByID($arOrder["PAY_SYSTEM_ID"]);
    if ($arPaySystem)
    {
    $arFields["PAY_SYSTEM_NAME"] = $arPaySystem["NAME"];
    }

    //таблица в письме
    if ($orderID>0 && CModule::IncludeModule('iblock')) {
  3. @nafilimonov nafilimonov created this gist Nov 17, 2017.
    96 changes: 96 additions & 0 deletions OnOrderNewSendEmail.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,96 @@
    <?
    AddEventHandler("sale", "OnOrderNewSendEmail", "OnOrderNewSendEmailNewFields");
    function OnOrderNewSendEmailNewFields($orderID, &$eventName, &$arFields){

    $arOrder = CSaleOrder::GetByID($orderID);
    $country = "";
    $city = "";
    $address = "";
    $order_props = CSaleOrderPropsValue::GetOrderProps($orderID);
    while ($arProps = $order_props->Fetch()){
    if ($arProps["CODE"] == "LOCATION"){
    $arRegion = CSaleLocation::GetByID(htmlspecialchars($arProps["VALUE"]));
    $country = $arRegion['COUNTRY_NAME'];
    $city = $arRegion['CITY_NAME'];
    }
    if ($arProps["CODE"] == "ADDRESS"){
    $address = htmlspecialchars($arProps["VALUE"]);
    }
    }
    $arFields["COUNTRY"] = $country;
    $arFields["CITY"] = $city;
    $arFields["ADDRESS"] = $address;
    $payment = CSalePaySystem::GetByID($arOrder['PAY_SYSTEM_ID']);
    $arFields["PAYMENT"] = $payment['NAME'];

    //-- получаем название службы доставки
    if(intval($arOrder["DELIVERY_ID"])<=0){
    $ar_active_list = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
    foreach($ar_active_list as $delivery){
    if($delivery["CODE"] == $arOrder["DELIVERY_ID"]){
    $arOrder["DELIVERY_ID"] = $delivery["ID"];
    $arOrder["DELIVERY_PARENT_ID"] = $delivery["PARENT_ID"];
    break;
    }
    }
    }
    if(intval($arOrder["DELIVERY_ID"])>0){
    $arDeliv = \Bitrix\Sale\Delivery\Services\Manager::getById($arOrder["DELIVERY_ID"]);
    if(intval($arOrder["DELIVERY_PARENT_ID"])>0){
    $arParDeliv = \Bitrix\Sale\Delivery\Services\Manager::getById($arOrder["DELIVERY_PARENT_ID"]);
    }
    }
    $deliveryName = "";
    if ($arDeliv && $arParDeliv)
    {
    $deliveryName = $arParDeliv['NAME']." ({$arDeliv["NAME"]})";
    }
    else if ($arDeliv) {
    $deliveryName = $arDeliv["NAME"];
    }

    $arFields["DELIVERY"] = $deliveryName;
    $arFields["PRICE_DELIVERY"] = $arOrder['PRICE_DELIVERY'];


    //таблица в письме
    if ($orderID>0 && CModule::IncludeModule('iblock')) {

    $arFields['ORDER_LIST'] = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>';
    $arFields['ORDER_LIST'] .= '<tr>';
    $arFields['ORDER_LIST'] .= '<td width="100">&nbsp;</td>';
    $arFields['ORDER_LIST'] .= '<td style="font-family:Tahoma, sans-serif; font-size:12px; line-height:12px; color:#7B7B7B">Название</td>';
    $arFields['ORDER_LIST'] .= '<td width="70" style="font-family:Tahoma, sans-serif; font-size:12px; line-height:12px; color:#7B7B7B">Кол-во</td>';
    $arFields['ORDER_LIST'] .= '<td style="font-family:Tahoma, sans-serif; font-size:12px; line-height:12px; color:#7B7B7B">Стоимость</td>';
    $arFields['ORDER_LIST'] .= '</tr>';

    $rsBasket = CSaleBasket::GetList(array(), array('ORDER_ID' => $orderID));

    while ($arBasket = $rsBasket->GetNext()) {
    $arPicture = false;
    //мы берем картинку только если это товар из инфоблока
    if ($arBasket['MODULE'] == 'catalog') {
    if ($arProduct = CIBlockElement::GetByID($arBasket['PRODUCT_ID'])->Fetch()) {
    if ($arProduct['PREVIEW_PICTURE'] > 0) {
    $fileID = $arProduct['PREVIEW_PICTURE'];
    } elseif ($arProduct['DETAIL_PICTURE'] > 0) {
    $fileID = $arProduct['DETAIL_PICTURE'];
    } else {
    $fileID = 0;
    }
    $arPicture = CFile::ResizeImageGet($fileID, array('width' => 80));
    $arPicture['SIZE'] = getimagesize($_SERVER['DOCUMENT_ROOT'].$arPicture['src']);
    }
    }

    $arFields['ORDER_LIST'] .= '<tr>';
    $arFields['ORDER_LIST'] .= '<td width="100">'.($arPicture ? '<img src="http://'.$GLOBALS['SERVER_NAME'].(str_replace(array('+', ' '), '%20', $arPicture['src'])).'" width="80" alt="">' : '').'</td>';
    $arFields['ORDER_LIST'] .= '<td style="font-family:Tahoma, sans-serif; font-size:12px; line-height:24px; color:#000000">'.$arBasket['NAME'].'</td>';
    $arFields['ORDER_LIST'] .= '<td width="70" style="font-family:Tahoma, sans-serif; font-size:12px; line-height:24px; color:#000000">'.(int)$arBasket['QUANTITY'].' шт.</td>';
    $arFields['ORDER_LIST'] .= '<td style="font-family:Tahoma, sans-serif; font-size:12px; line-height:24px; color:#000000">'.SaleFormatCurrency((int)$arBasket['QUANTITY']*$arBasket['PRICE'], $arBasket['CURRENCY']).'</td>';
    $arFields['ORDER_LIST'] .= '</tr>';
    }
    $arFields['ORDER_LIST'] .= '</tbody></table>';
    }

    }