Created
October 24, 2017 11:20
-
-
Save steepzero-old/0f10e7986c03608cfb0089b5f9b2c4c3 to your computer and use it in GitHub Desktop.
OnSaleOrderSaved Handler
This file contains hidden or 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
function my_OnSaleOrderSaved(Main\Event $event){ | |
$order = $event->getParameter('ENTITY'); | |
$isNew = $event->getParameter('IS_NEW'); | |
$propsCollection = $order->getPropertyCollection(); | |
if($isNew){ | |
$out = ''; | |
$arProps = array(); | |
foreach($propsCollection->getGroupProperties(1) as $prop){ | |
$propValue = $prop->getValue(); | |
$p = $prop->getProperty(); | |
$arProps[$p['CODE']] = $propValue; | |
} | |
$basket = $order->getBasket()->getBasketItems(); | |
$arItems = array(); | |
foreach ($basket as $item){ | |
$qtty = $item->formatQuantity($item->getQuantity()); | |
$price = $item->getPrice(); | |
$name = $item->getField('NAME'); | |
$arItems[] = array( | |
'NAME' => $name, | |
'QUANTITY' => $qtty, | |
'PRICE' => CurrencyFormat($price,'RUB'), | |
); | |
} | |
$basket_html = ''; | |
foreach ($arItems as $arItem){ | |
$basket_html .= $arItem['NAME'].' - '.$arItem['QUANTITY'].' x '.$arItem['PRICE']."<br>"; | |
} | |
$arFields = array( | |
'ORDER_ID' => $order->getId(), | |
'ORDER_DATE' => $order->getDateInsert(), | |
'PRICE' => CurrencyFormat($order->getPrice(),'RUB'), | |
'ORDER_LIST' => $basket_html, | |
'DESCRIPTION' => $order->getField('USER_DESCRIPTION'), | |
); | |
$arFields = array_merge($arFields,$arProps); | |
\Bitrix\Main\Mail\Event::send(array( | |
"EVENT_NAME" => "SALE_NEW_ORDER_ADMIN", | |
"LID" => "s1", | |
"C_FIELDS" => $arFields | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
before 10 better:
foreach ($propsCollection->getGroups() as $group)
{
foreach($propsCollection->getGroupProperties($group["ID"]) as $prop){