From e210a7a26fee5d278bf8de472072f607e66a6b66 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 19 Sep 2013 00:18:32 +0400 Subject: [PATCH] histore update fixes --- .../classes/general/ICrmOrderActions.php | 65 ++++++++++--------- .../classes/general/events/ICrmOrderEvent.php | 27 +++++++- intaro.intarocrm/install/index.php | 10 +-- intaro.intarocrm/install/step1.php | 3 - intaro.intarocrm/install/step3.php | 9 ++- intaro.intarocrm/lang/ru/install/step3.php | 1 + intaro.intarocrm/lang/ru/options.php | 4 +- intaro.intarocrm/options.php | 9 +-- 8 files changed, 75 insertions(+), 53 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 092f80b0..6f237ecc 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -200,7 +200,7 @@ class ICrmOrderActions $api = new IntaroCrm\RestApi($api_host, $api_key); $orderHistory = $api->orderHistory(); - + // pushing existing orders foreach ($orderHistory as $order) { @@ -249,7 +249,9 @@ class ICrmOrderActions if(isset($order['customer']) && $order['customer']) $userId = $order['customer']; $LID = $arFields['LID']; + $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); + while ($ar = $rsOrderProps->Fetch()) { if (isset($order['deliveryAddress']) && $order['deliveryAddress']) { switch ($ar['CODE']) { @@ -403,24 +405,26 @@ class ICrmOrderActions CSaleBasket::Update($p['ID'], $arProduct); }*/ - + // orderUpdate $arFields = self::clearArr(array( - 'PRICE_DELIVERY' => $order['deliveryCost'], - 'PRICE' => $order['summ'], - 'DATE_MARKED' => $order['markDatetime'], - 'USER_ID' => $userId, //$order['customer'] - 'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']], - 'PAYED' => $optionsPayment[$order['paymentStatus']], + 'PRICE_DELIVERY' => $order['deliveryCost'], + 'PRICE' => $order['summ'], + 'DATE_MARKED' => $order['markDatetime'], + 'USER_ID' => $userId, //$order['customer'] + 'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']], + 'PAYED' => $optionsPayment[$order['paymentStatus']], //'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']], - 'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']], - 'STATUS_ID' => $optionsPayStatuses[$order['status']] + 'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']], + 'STATUS_ID' => $optionsPayStatuses[$order['status']], + 'REASON_CANCELED' => $order['statusComment'], + 'USER_DESCRIPTION' => $order['customerComment'], + 'COMMENTS' => $order['managerComment'] )); - $GLOBALS['FROM_HISTORY'] = true; + $GLOBALS['INTARO_CRM_FROM_HISTORY'] = true; CSaleOrder::Update($order['externalId'], $arFields); - } } @@ -550,46 +554,46 @@ class ICrmOrderActions $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); while ($ar = $rsOrderProps->Fetch()) { switch ($ar['CODE']) { - case $arParams['optionsOrderProps']['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); break; case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['text']: $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['text']: $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); break; case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); } break; - case $arParams['optionsOrderProps']['fio']: $contactNameArr = self::explodeFIO($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['fio']: $contactNameArr = self::explodeFIO($ar['VALUE']); break; - case $arParams['optionsOrderProps']['phone']: $resOrder['phone'] = $ar['VALUE']; + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['phone']: $resOrder['phone'] = $ar['VALUE']; break; - case $arParams['optionsOrderProps']['email']: $resOrder['email'] = $ar['VALUE']; + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['email']: $resOrder['email'] = $ar['VALUE']; break; } - if (count($arParams['optionsOrderProps'] > 5)) { + if (count($arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']] > 5)) { switch ($ar['CODE']) { - /*case $arParams['optionsOrderProps']['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); + /*case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); break; */ - case $arParams['optionsOrderProps']['street']: $resOrderDeliveryAddress['street'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['street']: $resOrderDeliveryAddress['street'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['building']: $resOrderDeliveryAddress['building'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['building']: $resOrderDeliveryAddress['building'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['block']: $resOrderDeliveryAddress['block'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['block']: $resOrderDeliveryAddress['block'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['house']: $resOrderDeliveryAddress['house'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['house']: $resOrderDeliveryAddress['house'] = self::toJSON($ar['VALUE']); break; } } @@ -626,6 +630,7 @@ class ICrmOrderActions $createdAt = $createdAt->format('Y-m-d H:i:s'); $resOrder = array( + 'number' => $resOrder['ACCOUNT_NUMBER'], 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], 'deliveryCost' => $arFields['PRICE_DELIVERY'], @@ -638,7 +643,9 @@ class ICrmOrderActions 'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']], 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], - 'statusComment' => $arFields['USER_DESCRIPTION'], + 'statusComment' => $arFields['REASON_CANCELED'], + 'customerComment' => $arFields['USER_DESCRIPTION'], + 'managerComment' => $arFields['COMMENTS'], 'createdAt' => $createdAt, 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 951c6d55..dca02903 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -13,7 +13,18 @@ class ICrmOrderEvent { protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N protected static $CRM_ORDER_LAST_ID = 'order_last_id'; - + protected static $CRM_ORDER_PROPS = 'order_props'; + + /** + * onBeforeOrderAdd + * + * @param mixed $arFields - Order arFields + */ + function onBeforeOrderAdd($arFields = array()) { + $GLOBALS['INTARO_CRM_ORDER_ADD'] = true; + return; + } + /** * onUpdateOrder * @@ -21,7 +32,10 @@ class ICrmOrderEvent { * @param mixed $arFields - Order arFields */ function onUpdateOrder($ID, $arFields = array()) { - if(isset($GLOBALS['FROM_HISTORY']) && $GLOBALS['FROM_HISTORY']) + if(isset($GLOBALS['INTARO_CRM_ORDER_ADD']) && $GLOBALS['INTARO_CRM_ORDER_ADD']) + return; + + if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY']) return; self::writeDataOnOrderCreate($ID); @@ -47,6 +61,7 @@ class ICrmOrderEvent { * @param integer $ID - Order Id */ function writeDataOnOrderCreate($ID) { + if (!CModule::IncludeModule('iblock')) { //handle err ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found'); @@ -64,6 +79,9 @@ class ICrmOrderEvent { ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'catalog', 'module not found'); return true; } + + $GLOBALS['INTARO_CRM_ORDER_ADD'] = false; + $GLOBALS['INTARO_CRM_FROM_HISTORY'] = false; $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); @@ -74,6 +92,7 @@ class ICrmOrderEvent { $optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); + $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); $api = new IntaroCrm\RestApi($api_host, $api_key); @@ -82,7 +101,8 @@ class ICrmOrderEvent { 'optionsDelivTypes' => $optionsDelivTypes, 'optionsPayTypes' => $optionsPayTypes, 'optionsPayStatuses' => $optionsPayStatuses, - 'optionsPayment' => $optionsPayment + 'optionsPayment' => $optionsPayment, + 'optionsOrderProps' => $optionsOrderProps ); $arOrder = CSaleOrder::GetById($ID); @@ -190,6 +210,7 @@ class ICrmOrderEvent { ); $api->orderEdit($order); + // error pushing order if ($api->getStatusCode() != 201) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index ae64533d..54a332ab 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -68,13 +68,6 @@ class intaro_intarocrm extends CModule { } } - if (!date_default_timezone_get()) { - if (!ini_get('date.timezone')) { - $APPLICATION->ThrowException(GetMessage("DATE_TIMEZONE_ERR")); - return false; - } - } - include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); include($this->INSTALL_PATH . '/../classes/general/ICMLLoader.php'); @@ -697,7 +690,7 @@ class intaro_intarocrm extends CModule { //form orderProps $dbProp = CSaleOrderProps::GetList(array(), array()); while ($arProp = $dbProp->GetNext()) { - $arResult['arProp'][$arProp['PERSON_TYPE_ID']] = $arProp; + $arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp; } COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); @@ -876,6 +869,7 @@ class intaro_intarocrm extends CModule { } RegisterModule($this->MODULE_ID); + RegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); $this->CopyFiles(); if (isset($_POST['LOAD_NOW'])) { diff --git a/intaro.intarocrm/install/step1.php b/intaro.intarocrm/install/step1.php index 9f3ff0b9..587334c1 100755 --- a/intaro.intarocrm/install/step1.php +++ b/intaro.intarocrm/install/step1.php @@ -29,9 +29,6 @@ - - -   diff --git a/intaro.intarocrm/install/step3.php b/intaro.intarocrm/install/step3.php index c40ca3d2..81668f47 100755 --- a/intaro.intarocrm/install/step3.php +++ b/intaro.intarocrm/install/step3.php @@ -58,13 +58,12 @@ $defaultOrderProps = array( - + - - + @@ -74,14 +73,14 @@ $defaultOrderProps = array( 4) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 4) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>> - + ConvertCharset($orderProp['NAME'], 'utf-8', SITE_CHARSET);; ?> diff --git a/intaro.intarocrm/lang/ru/install/step3.php b/intaro.intarocrm/lang/ru/install/step3.php index 852511e5..1d840812 100755 --- a/intaro.intarocrm/lang/ru/install/step3.php +++ b/intaro.intarocrm/lang/ru/install/step3.php @@ -12,6 +12,7 @@ $MESS ['START_3'] = 'Возобновить выгрузку'; $MESS ['MOD_NEXT_STEP'] = 'Следующий шаг'; $MESS ['MOD_PREV_STEP'] = 'Предыдущий шаг'; $MESS ['INFO_2'] = ' Задайте соответствие между полями заказа 1C-Битрикс и IntaroCRM.'; +$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; $MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа IntaroCRM свойствам заказа 1С-Битрикс'; $MESS ['FIO'] = 'Ф.И.О.'; diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 0eed5b14..442fccdb 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -50,4 +50,6 @@ $MESS ['FLOOR'] = 'Этаж'; $MESS ['BLOCK'] = 'Подъезд'; $MESS ['HOUSE'] = 'Строение / корпус'; $MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; -$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; \ No newline at end of file +$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; + +$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index be1efdc6..aca82213 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -219,6 +219,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { // remove depenedencies UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); + UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd"); // new agent $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; @@ -236,7 +237,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { // event dependencies RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); - + RegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd"); } $orderPropsArr = array(); @@ -576,13 +577,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - + - + @@ -599,7 +600,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {