From 5ef7ec6538e4a17abb5c60625b1f3836be0c5c3e Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 10 Sep 2013 17:15:41 +0400 Subject: [PATCH] mode change in options --- .../classes/general/ICrmOrderActions.php | 4 +- .../classes/general/events/ICrmOrderEvent.php | 5 +- intaro.intarocrm/lang/ru/options.php | 7 ++- intaro.intarocrm/options.php | 51 +++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 8c180f01..7a5c79d5 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -338,7 +338,7 @@ class ICrmOrderActions $resOrder = self::clearArr($resOrder); if($send) - return $api->createOrder($resOrder); + return $api->orderEdit($resOrder); return array( 'order' => $resOrder, @@ -392,7 +392,7 @@ class ICrmOrderActions return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); } - public static function expodeFIO($str) { + public static function explodeFIO($str) { if(!$str) return array(); diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 5e9470ff..13c19c78 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -21,8 +21,9 @@ class ICrmOrderEvent { * @param mixed $arFields - Order arFields */ function onUpdateOrder($ID, $arFields = array()) { - //self::writeDataOnOrderCreate($ID); + self::writeDataOnOrderCreate($ID); } + /** * onSendOrderMail @@ -61,7 +62,7 @@ class ICrmOrderEvent { } $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); - $api_key = COption::GetOptionString(Iself::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); + $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0)); diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 34572124..688b15fa 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -22,4 +22,9 @@ $MESS ['ERR_403'] = 'Неверный apiKey.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; $MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; $MESS ['CANCELED'] = 'Флаг «Отменен»'; -$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; \ No newline at end of file +$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; + +$MESS ['ICRM_OPTIONS_ORDER_DISCHARGE_TAB'] = 'Режим выгрузки заказов'; +$MESS ['ORDER_DISCH'] = 'Режим выгрузки заказов'; +$MESS ['DISCHARGE_AGENT'] = 'Выгрузка заказов с помощью агента'; +$MESS ['DISCHARGE_EVENTS'] = 'Выгрузка заказов по событию'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index 3f1d439a..e6122189 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -11,6 +11,7 @@ $CRM_PAYMENT_TYPES = 'pay_types_arr'; $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; $CRM_PAYMENT = 'payment_arr'; //order payment Y/N $CRM_ORDER_LAST_ID = 'order_last_id'; +$CRM_ORDER_DISCHARGE = 'order_discharge'; if(!CModule::IncludeModule('intaro.intarocrm') || !CModule::IncludeModule('sale')) @@ -132,11 +133,42 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); + $previousDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); + //order discharge mode + // 0 - agent + // 1 - event + $orderDischarge = 0; + $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); + + if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { + // remove depenedencies + UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); + UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); + // new agent + $dateAgent = new DateTime(); + $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; + $dateAgent->add($intAgent); + CAgent::AddAgent( + "ICrmOrderActions::uploadOrdersAgent();", $mid, "N", 600, // interval - 10 mins + $dateAgent->format('d.m.Y H:i:s'), // date of first check + "Y", // агент активен + $dateAgent->format('d.m.Y H:i:s'), // date of first start + 30 + ); + } else if (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { + // remove agent + CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $mid); + // event dependencies + RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); + RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); + } + COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($mid, $CRM_PAYMENT, serialize($paymentArr)); + COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge); $uri .= '&ok=Y'; LocalRedirect($uri); @@ -249,6 +281,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0)); + $optionsDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); $aTabs = array( array( @@ -263,6 +296,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION') ), + array( + "DIV" => "edit4", + "TAB" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_TAB'), + "ICON" => '', + "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION') + ) ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); @@ -394,6 +433,18 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { BeginNextTab(); ?> + + + + + + + + + + + + Buttons(); ?>