diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index 9b827946..d496d857 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -574,7 +574,8 @@ class RetailCrmOrder } } - $orderIds = array_unique(array_merge($orderIds, $orderUpdateIds)); + $orderIds = array_unique(array_merge($orderIds, $orderUpdateIds)); + if (count($orderIds) <= 0) { return false; } @@ -634,11 +635,15 @@ class RetailCrmOrder continue; } - $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $orderId, $site); + if((int)$uploadMethod === 0) { + $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $orderId, $site); - if (isset($orderCrm['order'])) { - $methodApi = 'ordersEdit'; - $arParams['crmOrder'] = $orderCrm['order']; + if (isset($orderCrm['order'])) { + $methodApi = 'ordersEdit'; + $arParams['crmOrder'] = $orderCrm['order']; + } else { + $methodApi = 'ordersCreate'; + } } else { $methodApi = 'ordersCreate'; } @@ -651,6 +656,7 @@ class RetailCrmOrder if ($methodApi === 'ordersEdit') { $updateDate = $bitrixOrder->getField('DATE_UPDATE')->format("Y-m-d H:i:s"); $maxUpdateDate = $updateDate > $maxUpdateDate ? $updateDate : $maxUpdateDate; + self::orderSend($order, $api, $arParams, true, $site); continue; } diff --git a/intaro.retailcrm/lang/en/options.php b/intaro.retailcrm/lang/en/options.php index 3c218b98..5877baef 100644 --- a/intaro.retailcrm/lang/en/options.php +++ b/intaro.retailcrm/lang/en/options.php @@ -23,6 +23,7 @@ $MESS ['ORDER_CUSTOM'] = 'Custom fields'; $MESS ['COUPON_CUSTOM_FIELD'] = 'Select a custom field in the CRM to transfer the applied coupon in the Bitrix order'; $MESS ['SELECT_VALUE'] = '-- Select a value --'; $MESS ['ORDER_UPLOAD'] = 'Re-upload orders'; +$MESS ['LP_WARNING'] = 'Loyalty program of RetailCRM is available only with the “Uploading orders by event” options active'; $MESS ['ORDER_NUMBER'] = 'Order numbers: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.'; $MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Save settings'; diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index e03b4632..8dc5f5a8 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -21,6 +21,7 @@ $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы'; $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа'; $MESS ['CRM_ORDER_METHODS'] = 'Передача заказов из CRM в Битрикс'; +$MESS ['LP_WARNING'] = 'Программа лояльности RetailCRM доступна только при активной опции "Выгрузка заказов по событию"'; $MESS ['CRM_ORDER_METHODS_OPTION'] = 'Выгружать из RetailCRM заказы оформленные выбранными способами'; $MESS ['CONTRAGENTS_TYPES_LIST'] = 'Тип контрагента'; $MESS ['PAYMENT_LIST'] = 'Оплата'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 7074a247..dd8db755 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -23,6 +23,7 @@ IncludeModuleLangFile(__FILE__); include (__DIR__ . '/lib/component/advanced/loyaltyinstaller.php'); $mid = 'intaro.retailcrm'; +$loyaltyEventClass = 'Intaro\RetailCrm\Component\Handlers\EventsHandlers'; $uri = $APPLICATION->GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID; if (!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog')) { @@ -323,6 +324,9 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { UnRegisterModuleDependences('sale', 'OnSaleOrderDeleted', $mid, 'RetailCrmEvent', "orderDelete"); UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', $mid, 'RetailCrmEvent', "orderSave"); UnRegisterModuleDependences('sale', 'OnOrderUpdate', $mid, 'RetailCrmEvent', "onUpdateOrder"); + UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', 'intaro.retailcrm', $loyaltyEventClass, 'OnSaleOrderSavedHandler'); + UnRegisterModuleDependences('sale', 'OnSaleComponentOrderResultPrepared', 'intaro.retailcrm', $loyaltyEventClass, 'OnSaleComponentOrderResultPreparedHandler'); + ConfigProvider::setLoyaltyProgramStatus('N'); $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); @@ -352,6 +356,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { ]); $arOrder = $dbOrder->fetch(); + if ($dbOrder) { COption::SetOptionString($mid, Constants::CRM_ORDER_LAST_ID, $arOrder['ID']); } else { @@ -645,22 +650,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { } } catch (Exception $exception) { RCrmActions::eventLog( - 'intaro.retailcrm/options.php', 'Options_Loyalty_toggle::enable', + 'intaro.retailcrm/options.php', 'OrderLoyaltyDataService::createLoyaltyHlBlock', $e->getCode() . ': ' . $exception->getMessage() ); } ConfigProvider::setLoyaltyProgramStatus('Y'); } else { - try { - ConfigProvider::setLoyaltyProgramStatus('N'); - $loyaltySetup->deleteLPEvents(); - } catch (Exception $exception) { - RCrmActions::eventLog( - 'intaro.retailcrm/options.php', 'Options_Loyalty_toggle::disable', - $e->getCode() . ': ' . $exception->getMessage() - ); - } + ConfigProvider::setLoyaltyProgramStatus('N'); + UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', $mid, $loyaltyEventClass, 'OnSaleOrderSavedHandler'); + UnRegisterModuleDependences('sale', 'OnSaleComponentOrderResultPrepared', $mid, $loyaltyEventClass, 'OnSaleComponentOrderResultPreparedHandler'); } try { @@ -3062,6 +3061,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { + + + + + diff --git a/intaro.retailcrm/updater.php b/intaro.retailcrm/updater.php index 989cc2f0..a9ed1f19 100644 --- a/intaro.retailcrm/updater.php +++ b/intaro.retailcrm/updater.php @@ -1197,8 +1197,9 @@ function update() $orderDischarge = Option::get('intaro.retailcrm', 'order_discharge'); - if ($orderDischarge === '0' || $orderDischarge === '2') { + if ($orderDischarge === '0') { $dateAgent = new DateTime(); + $dateAgent->add('PT60S'); CAgent::AddAgent( 'RCrmActions::uploadOrdersAgent();', @@ -1210,10 +1211,8 @@ function update() $dateAgent->format('d.m.Y H:i:s'), 30 ); - - if ($orderDischarge === '0') { - COption::SetOptionString('intaro.retailcrm', 'last_order_update', date("Y-m-d H:i:s")); - } + + COption::SetOptionString('intaro.retailcrm', 'order_discharge', '2'); } }