function OnBeforeUserDeleteHandler($user_id) { \CModule::IncludeModule("iblock"); \CModule::IncludeModule("sale"); //Привязки к соц. сетям $arrFilter = array("IBLOCK_ID" => USER_SOCIAL_IB, "PROPERTY_USER_ID" => $user_id); $arSelect = array("ID"); $rsRes = \CIBlockElement::GetList($arOrder, $arrFilter, false, false, $arSelect); while ($arItem = $rsRes->GetNext()) { \CIBlockElement::Delete($arItem["ID"]); } //Удаляем записи $result = \Hawkart\Megatv\RecordTable::getList(array('filter' => array("UF_USER_ID" => $user_id), 'select' => array("ID"))); while ($arRecord = $result->fetch()) { \CRecordEx::delete($arRecord["ID"]); } //Удаляем счет if ($arAccount = \CSaleUserAccount::GetByUserID($user_id, "RUR")) { \CSaleUserAccount::Delete($arAccount["ID"]); } //Удаляем заказы $arFilter = array("USER_ID" => $user_id); $db_sales = \CSaleOrder::GetList(array("DATE_INSERT" => "ASC"), $arFilter); while ($ar_sales = $db_sales->Fetch()) { \CSaleOrder::Delete($ar_sales["ID"]); } //Удаляем подписки $result = \Hawkart\Megatv\SubscribeTable::getList(array('filter' => array("=UF_USER_ID" => $user_id), 'select' => array("ID"))); if ($arSub = $result->fetch()) { \Hawkart\Megatv\SubscribeTable::delete($arSub["ID"]); } }
/** * событие вызывается перед отправкой письма о новом заказе * @param $orderID * @param $eventName * @param $arFields */ function bxModifySaleMails($order_id, &$eventName, &$arFieldsEmail) { //unset($_SESSION['OnBeforeOrderAddHandler']); //$_SESSION['OnBeforeOrderAddHandler']['bxModifySaleMails']='bxModifySaleMails'; //$_SESSION['OnBeforeOrderAddHandler']['id']=$order_id; //$_SESSION['OnBeforeOrderAddHandler']['arFields']=$arFieldsorder_old; $basket_props=""; $post['INFO']=""; $id_product=array(); if( (CModule::IncludeModule("main")) && (CModule::IncludeModule("iblock")) && (CModule::IncludeModule("catalog")) && (CModule::IncludeModule("sale")) ){ /** * получаем параметры сформировавшегося старого заказа */ $arFieldsorder_old = CSaleOrder::GetByID($order_id); /* echo "<pre>"; var_dump($arFieldsorder_old);die(); echo "</pre>";*/ /** * выборка свойства сформировавшегося заказа по id заказа */ $db_props = CSaleOrderPropsValue::GetOrderProps($order_id); $arFields_props = array(); while ($arProps = $db_props->Fetch()) { $arFields_props_old[$arProps['CODE']]=$arProps; } //_debug($arFields_props_old); /** * выборка из корзины по id заказа * получаем масси id продукта */ $rsUser = CUser::GetByID(CUser::GetID()); $arUser = $rsUser->Fetch(); /*if (!$ORDER_ID = CSaleOrder::Add(array( "LID" => SITE_ID, "PERSON_TYPE_ID" => 1, "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => 0, "CURRENCY" => CSaleLang::GetLangCurrency(SITE_ID), "USER_ID" => $arUser['ID'], "PAY_SYSTEM_ID" => $arFieldsorder_old['PAY_SYSTEM_ID'], "PRICE_DELIVERY" => 0, "DELIVERY_ID" => $arFieldsorder_old['DELIVERY_ID'], "DISCOUNT_VALUE" => $arFieldsorder_old['DISCOUNT_VALUE'], "TAX_VALUE" => $arFieldsorder_old['TAX_VALUE'], "USER_DESCRIPTION" => $post['INFO'] ))){ $rows['msg'] = 'Ошибка создания заказа'; $fail = true; }else{ $rows['msg']=$ORDER_ID; //continue; }*/ $dbBasketItems = CSaleBasket::GetList( array("ID" => "ASC"), array( "LID" => SITE_ID, "ORDER_ID" => $order_id ), false, false, array() ); while ($arItem = $dbBasketItems->Fetch()){ $id_product[] = $arItem['PRODUCT_ID']; $products_basket[$arItem['PRODUCT_ID']]=$arItem; } foreach($products_basket as $product){ $price_product+=$product['PRICE']*$product['QUANTITY']; $products_descriptions.=$product['NAME']." - ".$product['QUANTITY']." шт: ".intval($product['PRICE'])." руб <br/>"; } $price_product+=$arFieldsorder_old["PRICE_DELIVERY"]; //$_SESSION['OnBeforeOrderAddHandler']['products_basket']=$products_basket; /** * получаем массив id партнеров из продукта */ //var_dump($id_product);die(); if($id_product){ $id_partner=array(); $partner_product=array(); $arSelect = Array("ID", "NAME","IBLOCK_ID","PROPERTY_PARTNER"); $arFilter = Array("ID"=>$id_product, "ACTIVE"=>"Y"); $res = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect); while($ob = $res->GetNextElement()) { $arFields = $ob->GetFields(); $partner_product[$arFields['PROPERTY_PARTNER_VALUE']][]=$products_basket[$arFields['ID']]; if($arFields['PROPERTY_PARTNER_VALUE']){ $id_partner[]=$arFields['PROPERTY_PARTNER_VALUE']; } } //$_SESSION['OnBeforeOrderAddHandler']['id_partner']=$id_partner; /** * получаем массив данных партнера */ if($id_partner){ $delivery_sum = null; $arSelect2 = Array("ID", "IBLOCK_ID", "NAME","PROPERTY_*"); $arFilter2 = Array("IBLOCK_ID"=>9, "ACTIVE"=>"Y","ID"=>$id_partner,); $res2 = CIBlockElement::GetList(Array(), $arFilter2, false, false, $arSelect2); /** * eсли в выборке корзине в продуктах больше чем один партнер * то разбиваем заказ по количеству партнеров */ if (intval($res2->SelectedRowsCount())>0){ while($ob2 = $res2->GetNextElement()){ $arFields_partners = $ob2->GetFields(); $arProperties_partners = $ob2->GetProperties(); //_debug($arProperties_partners); //$price_product=0; //$products_descriptions=""; $arEventFields=array(); //echo $arFields_partners['ID']; if($partner_product[$arFields_partners['ID']]){ $i=0; $size_of_productpartner=sizeof($partner_product[$arFields_partners['ID']]); foreach($partner_product[$arFields_partners['ID']] as $key_price=>$item_price){ //_debug($item_price); $quantity=1; /** * формируем новый пустой заказ */ if(!$i){ if (!$ORDER_ID = CSaleOrder::Add(array( "LID" => SITE_ID, "PERSON_TYPE_ID" => 1, "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => 0, "CURRENCY" => CSaleLang::GetLangCurrency(SITE_ID), "USER_ID" => $arUser['ID'], "PAY_SYSTEM_ID" => $arFieldsorder_old['PAY_SYSTEM_ID'], "PRICE_DELIVERY" => 0, "DELIVERY_ID" => $arFieldsorder_old['DELIVERY_ID'], "DISCOUNT_VALUE" => $arFieldsorder_old['DISCOUNT_VALUE'], "TAX_VALUE" => $arFieldsorder_old['TAX_VALUE'], "USER_DESCRIPTION" => $post['INFO'] ))){ $rows['msg'] = 'Ошибка создания заказа'; $fail = true; }else{ $rows['msg']=$ORDER_ID; //continue; } } /** * добавляем по id заказа в корзину товары партнера */ if (!Add2BasketByProductID($item_price['PRODUCT_ID'], $item_price['QUANTITY'], array( 'ORDER_ID' => $ORDER_ID, ), $basket_props)) { $rows['err'] = 'Ошибка добавления товара в заказ'; $fail = true; } /*$price_product+=$item_price['PRICE']*$item_price['QUANTITY']; $products_descriptions.=$item_price['NAME']." - ".$item_price['QUANTITY']." шт: ".intval($item_price['PRICE'])." руб <br/>"; */ $i++; /** * обновляем параметры нового заказа на актуальные */ if($size_of_productpartner==$i){ if (!$fail) { $dbBasketItems = CSaleBasket::GetList( array("NAME" => "ASC", "ID" => "ASC"), array( "LID" => SITE_ID, "ORDER_ID" => $ORDER_ID ), false, false, array( "ID", "NAME", "QUANTITY", "CURRENCY", "CAN_BUY", "PRICE", "WEIGHT", "DISCOUNT_PRICE" ) ); $summ = $weight = 0; $strOrderList = ""; $arBasket = array(); while ($arBasketItems = $dbBasketItems->GetNext()) { $strOrderList .= $arBasketItems["NAME"] . " - " . $arBasketItems["QUANTITY"] . " шт на " . SaleFormatCurrency($arBasketItems["PRICE"] * $arBasketItems["QUANTITY"], $arBasketItems["CURRENCY"]); $strOrderList .= "\n"; $rows['summ']=$summ += roundEx($arBasketItems["PRICE"], SALE_VALUE_PRECISION) * DoubleVal($arBasketItems["QUANTITY"]); $weight += doubleval($arBasketItems['WEIGHT']); $arBasket[] = $arBasketItems; } $arOrderForDiscount = array( 'SITE_ID' => SITE_ID, 'USER_ID' => $arUser['ID'], 'ORDER_PRICE' => $summ, 'ORDER_WEIGHT' => $weight, 'BASKET_ITEMS' => $arBasket, ); $arDiscountOptions = array(); $arDiscountErrors = array(); CSaleDiscount::DoProcessOrder($arOrderForDiscount, $arDiscountOptions, $arDiscountErrors); if($_REQUEST['comment']) $arOrderForDiscount['COMMENTS'] = $_REQUEST['comment']; if($arProperties_partners['DOSTAVKA']['VALUE']){ $arOrderForDiscount["PRICE_DELIVERY"] = $arProperties_partners['DOSTAVKA']['VALUE']; $arOrderForDiscount["DELIVERY_ID"] = 3; $summ += intval($arProperties_partners['DOSTAVKA']['VALUE']); $arOrderForDiscount['ORDER_PRICE']=$summ; } $arOrderForDiscount['PRICE_BEFORE'] = $summ; $arOrderForDiscount['PRICE'] = $summ; $arOrderForDiscount['WEIGHT'] = $arOrderForDiscount['ORDER_WEIGHT']; /** * обновляем заказ */ if (!CSaleOrder::Update($ORDER_ID, $arOrderForDiscount)) { $rows['err'] = 'Ошибка расчета цены заказа.'; $fail = true; }else{ /** * перезагружаем свойства заказ из старого */ $db_props_new = CSaleOrderPropsValue::GetOrderProps($ORDER_ID); $arFields_props_new = array(); while ($arProps_new = $db_props_new->Fetch()) { //_debug($arProps_new); foreach($arFields_props_old as $key_props_old=>$item_props_old){ if($arProps_new['CODE']==$key_props_old){ CSaleOrderPropsValue::Update($arProps_new['ID'], array("VALUE"=>$item_props_old['VALUE'])); unset($arFields_props_old[$key_props_old]); } } } if(sizeof($arFields_props_old)>0){ foreach($arFields_props_old as $key_props_old2=>$item_props_old2){ CSaleOrderPropsValue::Add(array( 'NAME' => $item_props_old2['NAME'], 'CODE' => $item_props_old2['CODE'], 'ORDER_PROPS_ID' => $item_props_old2['ORDER_PROPS_ID'], 'ORDER_ID' => $ORDER_ID, 'VALUE' => $item_props_old2['VALUE'] )); } } /** * добавляем в свойство заказа id партнера для дальнейшей фильтрации по партнерским заказам */ CSaleOrderPropsValue::Add(array( 'NAME' => "Привязка по партнеру", 'CODE' => "PATNERID", 'ORDER_PROPS_ID' => 21, 'ORDER_ID' => $ORDER_ID, 'VALUE' => $arFields_partners['ID'] )); //$price_product+=$arProperties_partners['DOSTAVKA']['VALUE']; //$price_product+=$arFieldsorder_old["PRICE_DELIVERY"]; /** * отправляем данные о товаре Партнерам */ if($arFields_partners['NAME']){ //если есть партнер у товара $arEventFields = Array( "ORDER_ID"=> $ORDER_ID, "ORDER_DATE"=> date("d.m.Y H:i:s"), "ORDER_USER"=> $arFields_partners['NAME'], "PRICE"=> $price_product, "EMAIL"=> $arProperties_partners['EMAIL']['VALUE'], "ORDER_LIST"=> $products_descriptions, //"DELIVERY_PRICE"=>$arProperties_partners['DOSTAVKA']['VALUE'] "DELIVERY_PRICE"=>$arFieldsorder_old["PRICE_DELIVERY"] ); $event = new CEvent; $event->SendImmediate("SALE_NEW_ORDERPARTNER", SITE_ID, $arEventFields); } } } // if(!$fail){ // $ar_res_product=CCatalogProduct::GetByID($PRODUCT['ID']); // $arFields_quant = array( // 'QUANTITY' => $ar_res_product['QUANTITY']-1 // ); // CCatalogProduct::Update($PRODUCT['ID'], $arFields_quant); // } } } } } /** * удаляем старый заказ после разбивки на новые */ if($ORDER_ID ){ CSaleOrder::Delete($order_id); } } } $arEventFields = Array( "ORDER_ID" =>$order_id, "ORDER_DATE" =>date("d.m.Y H:i:s"), "ORDER_USER" =>$arUser['NAME'], "PRICE" =>$price_product, "EMAIL" => $arUser['EMAIL'], "ORDER_LIST" =>$products_descriptions, "DELIVERY_PRICE"=>$arFieldsorder_old["PRICE_DELIVERY"] ); $event = new CEvent; $event->SendImmediate("SALE_NEW_BILET", SITE_ID, $arEventFields); } } //$_SESSION['OnBeforeOrderAddHandler']['rows']=$rows; return false; }
} } if(empty($arGeneralInfo["properies"][$personType])) { $dbProp = CSaleOrderProps::GetList(array(), Array("PERSON_TYPE_ID" => $personType)); while($arProp = $dbProp->Fetch()) $arGeneralInfo["properies"][$personType][$arProp["CODE"]] = $arProp; } if(WIZARD_INSTALL_DEMO_DATA) { $db_sales = CSaleOrder::GetList(array("DATE_INSERT" => "ASC"), array("LID" => WIZARD_SITE_ID), false, false, array("ID")); while ($ar_sales = $db_sales->Fetch()) { CSaleOrder::Delete($ar_sales["ID"]); } } $arData = Array( "SITE_ID" => WIZARD_SITE_ID, "PERSON_TYPE_ID" => $personType, "CURRENCY" => $defCurrency, "USER_ID" => 1, "PAY_SYSTEM_ID" => $paySystem, //"PRICE_DELIVERY" => "0", //"DELIVERY_ID" => "", "PROPS" => Array(), ); foreach($arGeneralInfo["properies"][$personType] as $key => $val) {
} else { switch ($_REQUEST['action']) { case "delete": $arItems = CSaleOrder::GetByID($ID); if (count($arItems) > 1) { @set_time_limit(0); if (CSaleOrder::CanUserDeleteOrder($ID, $arUserGroups, $intUserID)) { $DB->StartTransaction(); if (!CSaleOrder::Delete($ID)) { $DB->Rollback(); if ($ex = $APPLICATION->GetException()) $lAdmin->AddGroupError($ex->GetString(), $ID); else $lAdmin->AddGroupError(GetMessage("SALE_DELETE_ERROR"), $ID); } else $DB->Commit(); } else { $lAdmin->AddGroupError(str_replace("#ID#", $ID, GetMessage("SO_NO_PERMS2DEL")), $ID); }
public function Delete($ID) { /** @global CUserTypeManager $USER_FIELD_MANAGER */ global $USER_FIELD_MANAGER; if (!CModule::IncludeModule('sale')) { return false; } $dealID = 0; $dbResult = CCrmInvoice::GetList(array(), array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'UF_DEAL_ID')); $fields = is_object($dbResult) ? $dbResult->Fetch() : null; if (is_array($fields)) { $dealID = isset($fields['UF_DEAL_ID']) ? $fields['UF_DEAL_ID'] : 0; } $CSaleOrder = new CSaleOrder(); $result = $CSaleOrder->Delete($ID); if ($result) { $USER_FIELD_MANAGER->Delete(self::$sUFEntityID, $ID); CCrmProductRow::DeleteSettings('I', $ID); self::UnregisterLiveFeedEvent($ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Invoice, $ID); if ($dealID > 0) { Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($dealID); } CCrmSearch::DeleteSearch('INVOICE', $ID); } return $result; }
public function Delete($ID) { /** @global CUserTypeManager $USER_FIELD_MANAGER */ /** @global CMain $APPLICATION */ /** @var CApplicationException $ex */ global $USER_FIELD_MANAGER, $APPLICATION; $APPLICATION->ResetException(); foreach (GetModuleEvents('crm', 'OnBeforeCrmInvoiceDelete', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage('CRM_INVOICE_DELETE_CANCELED') . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } if (!CModule::IncludeModule('sale')) { return false; } $dealID = 0; $dbResult = CCrmInvoice::GetList(array(), array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'UF_DEAL_ID')); $fields = is_object($dbResult) ? $dbResult->Fetch() : null; if (is_array($fields)) { $dealID = isset($fields['UF_DEAL_ID']) ? $fields['UF_DEAL_ID'] : 0; } $CSaleOrder = new CSaleOrder(); $result = $CSaleOrder->Delete($ID); if ($result) { $USER_FIELD_MANAGER->Delete(self::$sUFEntityID, $ID); CCrmProductRow::DeleteSettings('I', $ID); self::UnregisterLiveFeedEvent($ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Invoice, $ID); if ($dealID > 0) { Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($dealID); } CCrmSearch::DeleteSearch('INVOICE', $ID); foreach (GetModuleEvents('crm', 'OnAfterCrmInvoiceDelete', true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID)); } } return $result; }