/** * [addOrder функция добавления заказа] * @param array $arParams * @return array or false */ function addOrder($arParams) { if (!CModule::IncludeModule('sale')) { return false; } global $USER; global $DB; $addCommentsOrder = false; $commentForManager = ""; updateBasketPreOrder(); // обновляем корзину $arBasketItems = array(); $dbBasketItems = CSaleBasket::GetList(array("NAME" => "ASC", "ID" => "ASC"), array("FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => "NULL"), false, false, array("ID", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "NAME", "CURRENCY", "CATALOG_XML_ID", "VAT_RATE", "NOTES", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "DIMENSIONS", "TYPE", "SET_PARENT_ID", "DETAIL_PAGE_URL")); while ($arItem = $dbBasketItems->Fetch()) { $arPropItem = getItemCart($arItem["PRODUCT_ID"]); $db_res = CSaleBasket::GetPropsList(array("SORT" => "ASC", "NAME" => "ASC"), array("BASKET_ID" => $arItem['ID']), false, array()); while ($ar_res = $db_res->Fetch()) { if ($ar_res["CODE"] == "DEPOSIT" && $ar_res["VALUE"] == "N") { $addCommentsOrder = true; } } $arBasketItems[] = $arItem; $arItem["ARTIKUL"] = $arPropItem["PROPERTY_ARTIKUL_VALUE"]; $strOrderList .= '<a href="http://' . $_SERVER["HTTP_HOST"] . $arItem["DETAIL_PAGE_URL"] . '">' . $arItem["ARTIKUL"] . '</a> ' . $arItem["NAME"] . ' - ' . $arItem["QUANTITY"] * 1 . ' шт. x ' . SaleFormatCurrency($arItem["PRICE"], $arItem["CURRENCY"]); $strOrderList .= "<br />"; $allDiscountItems += $arItem["DISCOUNT_PRICE"]; } if (!$arBasketItems) { return false; } $arOrderDat = CSaleOrder::DoCalculateOrder(SITE_ID, $USER->GetID(), $arBasketItems, 1, $arUserResult["ORDER_PROP"], $arParams["DELIVERY_ID"], $arParams["PAY_SYSTEM_ID"], array(), $arErrors, $arWarnings); $arOrderDat["ORDER_PROP"][20] = $arParams["ORDER_PROP_20"]; $arOrderDat["ORDER_PROP"][7] = $arParams["ORDER_PROP_7"]; $arOrderDat["ORDER_PROP"][3] = $arParams["ORDER_PROP_3"]; //echo "<pre>";print_r($PRICE);echo "</pre>";die(); //echo "<pre>";print_r($arOrderDat);echo "</pre>";die(); //echo "<pre>";print_r($arParams);echo "</pre>";die(); $arFields = array("LID" => SITE_ID, "PERSON_TYPE_ID" => 1, "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => $arOrderDat["ORDER_PRICE"], "CURRENCY" => $arOrderDat["CURRENCY"], "USER_ID" => IntVal($USER->GetID()), "PAY_SYSTEM_ID" => $arOrderDat["PAY_SYSTEM_ID"], "PRICE_DELIVERY" => $arOrderDat["PRICE_DELIVERY"], "DELIVERY_ID" => $arOrderDat["DELIVERY_ID"], "DISCOUNT_VALUE" => $arOrderDat["DISCOUNT_VALUE"], "TAX_VALUE" => $arOrderDat["TAX_VALUE"], "DELIVERY_LOCATION" => $arOrderDat["DELIVERY_LOCATION"], "USER_DESCRIPTION" => $arParams["ORDER_DESCRIPTION"], "COMMENTS" => $commentForManager); $ORDER_ID = (int) CSaleOrder::DoSaveOrder($arOrderDat, $arFields, 0, $arResult["ERROR"]); if ($ORDER_ID > 0) { $arOrder = getOrder($ORDER_ID); // для менеджера if ($addCommentsOrder === true && $arParams["PAY_SYSTEM_ID"] == 10) { // сообщение для менеджера $commentForManager .= 'Выбран способ оплаты PayKeeper, но в заказе есть товары "По запросу".'; $commentForManager .= "\n"; $commentForManager .= "Ссылка для оплаты: http://" . $_SERVER["HTTP_HOST"] . "/personal/order/payment/?ORDER_ID=" . $ORDER_ID; $arFields = array("COMMENTS" => $commentForManager); CSaleOrder::Update($ORDER_ID, $arFields); } // отправляем письмо $arFieldsEvent = array("ORDER_ID" => getNumberOrder($ORDER_ID), "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", SITE_ID))), "ORDER_USER" => $USER->GetFormattedName(false), "PRICE" => SaleFormatCurrency($arOrderDat["ORDER_PRICE"], $arOrderDat["CURRENCY"]), "BCC" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "EMAIL" => strlen($arUserResult["USER_EMAIL"]) > 0 ? $arUserResult["USER_EMAIL"] : $USER->GetEmail(), "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "DISCOUNT" => $allDiscountItems . " руб.", "DELIVERY_PRICE" => "", "DELIVERY_TYPE" => getDeliveryName($arOrderDat["DELIVERY_ID"]), "ADDRESS" => strlen($arParams["ORDER_PROP_7"]) > 0 ? $arParams["ORDER_PROP_7"] : "Адрес не указан", "COMMENT" => strlen($arParams["ORDER_DESCRIPTION"]) > 0 ? $arParams["ORDER_DESCRIPTION"] : "Нет комментария"); //Формируем писмо для отправки менеджеру switch ($arParams["PAY_SYSTEM_ID"]) { case 10: $price_method = 'Оплата банковской картой VISA, MASTERCARD, MAESTRO'; break; case 8: $price_method = 'Безналичный расчет'; break; case 1: $price_method = 'Наличными при получении'; break; } $rsGroups = CGroup::GetList($by = "c_sort", $order = "asc", array("ID" => implode('|', $USER->GetUserGroupArray()))); $groups = array(); if (intval($rsGroups->SelectedRowsCount()) > 0) { while ($arGroups = $rsGroups->Fetch()) { if ((int) $arGroups['ID'] != 2 && (int) $arGroups['ID'] != 3 && (int) $arGroups['ID'] != 4) { $groups[] = $arGroups['NAME']; } } } $arFieldsManager = array('NUMBER' => getNumberOrder($ORDER_ID), 'DATE' => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", SITE_ID))), 'SELLER_TYPE' => implode(',', $groups), 'FIO' => $USER->GetFormattedName(false), 'PHONE' => strlen($arParams["ORDER_PROP_3"]) > 0 ? $arParams["ORDER_PROP_3"] : "Телефон не указан", 'EMAIL' => $USER->GetEmail(), 'ADRESS' => strlen($arParams["ORDER_PROP_7"]) > 0 ? $arParams["ORDER_PROP_7"] : "Адрес не указан", 'DOSTAVKA' => getDeliveryName($arOrderDat["DELIVERY_ID"]), 'PRICE_METHOD' => $price_method, 'ORDERS' => $strOrderList . '<br />Итого: ' . $arOrderDat["ORDER_PRICE"], 'DISCOUNT' => $allDiscountItems . " руб.", 'COMMENT' => strlen($arParams["ORDER_DESCRIPTION"]) > 0 ? $arParams["ORDER_DESCRIPTION"] : "Нет комментария"); $eventName = "SALE_NEW_ORDER"; $eventNameManager = "FORM_FILLING_NEW_ORDER"; $bSend = true; foreach (GetModuleEvents("sale", "OnOrderNewSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($arResult["ORDER_ID"], &$eventName, &$arFields)) === false) { $bSend = false; } } if ($bSend) { $event = new CEvent(); $event->Send($eventName, SITE_ID, $arFieldsEvent, "N"); $event->Send($eventNameManager, SITE_ID, $arFieldsManager, "N"); } return $ORDER_ID; } return false; }
break; case 'N': $msgStatus = "Принят"; break; case 'P': $msgStatus = "Оплачен"; break; case 'F': $msgStatus = "Выполнен"; break; case 'D': $msgStatus = "Отменен"; break; } ?> <p class="lk-payment-info">Способ доставки: <?=getDeliveryName($arOrder["DELIVERY_ID"])?></p> <p class="lk-payment-info">Статус: <?=$msgStatus?></p> </div> <a class="btn small-btn js-order-contents-trigger" href="#">Состав заказа</a> <div class="lk-order-contents-wrapper"> <ul class="checkout-order-list"> <?foreach ($arOrder["ITEMS"] as $key => $arItems) :?> <li class="checkout-order-item"> <? //$waterImage = waterImage($arItems["PRODUCTS"]["~PREVIEW_PICTURE"]); // $waterImage["src"] $waterImage["src"] = CFIle::GetPath($arItems["PRODUCTS"]["~PREVIEW_PICTURE"]); ?> <aside> <div class="img-cnt"> <img src="<?=$waterImage["src"]?>" alt="item"/>
endforeach;?> <div class="lk-order"> <p class="last-order-info big">Заказ №<?=$arOrder["ACCOUNT_NUMBER"]?><span><?=$arOrder["DATE_INSERT"]?></span></p> <div class="order-params"> <div class="col12"> <div class="lk-toc-row"> <span>Стоимость товаров</span> <span><?=number_format(($arOrder["PRICE"]+$arOrder["DISCOUNT_VALUE"])-$arOrder["PRICE_DELIVERY"], 0, 0, " ")?> руб.</span> </div> <div class="lk-toc-row"> <span>Со скидкой</span> <span><?=number_format($arOrder["PRICE"]-$arOrder["PRICE_DELIVERY"], 0, 0, " ")?> руб.</span> </div> <div class="lk-toc-row"> <span>Способ доставки</span> <span><?=getDeliveryName($arOrder["DELIVERY_ID"])?></span> </div> </div> <div class="col12"> <div class="lk-toc-row"> <span>Ваша экономия</span> <span><?=number_format($arOrder["PRICE"] - ($arOrder["PRICE"]-$arOrder["DISCOUNT_VALUE"]), 0, 0, " ")?> руб.</span> </div> <div class="lk-toc-row"> <span><strong>ИТОГО</strong></span> <span><strong><?=number_format($arOrder["PRICE"], 0, 0, " ")?> руб.</strong></span> </div> <? switch ($arOrder["STATUS_ID"]) { case 'A': $msgStatus = "Внесены изменения, подтвержден";