Last active
January 15, 2022 15:41
-
-
Save nafilimonov/fc1060b699e985e6118484845e0d9a4d to your computer and use it in GitHub Desktop.
Bitrix. Sale. Письмо после заказа.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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; | |
//-- получаем название службы доставки | |
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']; | |
//-- получаем название платежной системы | |
$arPaySystem = CSalePaySystem::GetByID($arOrder["PAY_SYSTEM_ID"]); | |
if ($arPaySystem) | |
{ | |
$arFields["PAY_SYSTEM_NAME"] = $arPaySystem["NAME"]; | |
} | |
//таблица в письме | |
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"> </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>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment