diff --git a/CHANGELOG.md b/CHANGELOG.md index 20634551..49ea329d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2018-10-25 v.2.4.0 +* Изменена привязка на событие сохранения заказа. Используется привязка к событию "OnSaleOrderSaved" +* Исправлено удаление событий модуля при удалении модуля интеграции из CMS +* Исправлен баг с некорректным удалением модуля из CMS + ## 2018-10-25 v.2.3.13 * Добавлен функционал для активации модуля в маркетплейсе retailCRM * Исправлен баг при генерации каталога с подстановкой схемы diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index 1b055502..b89af713 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -168,7 +168,6 @@ class RetailCrmEvent $arParams['crmOrder'] = $orderCrm['order']; } else { $methodApi = 'ordersCreate'; - $GLOBALS['RETAILCRM_ORDER_NEW_ORDER'] = true; } //user @@ -222,7 +221,6 @@ class RetailCrmEvent 'SUM' => $event->getField('SUM'), 'LID' => $event->getField('LID'), 'DATE_PAID' => $event->getField('DATE_PAID'), - 'METHOD' => $GLOBALS['RETAILCRM_ORDER_NEW_ORDER'], ); try { @@ -252,65 +250,52 @@ class RetailCrmEvent $payments = $orderCrm['order']['payments']; } - if ($arPayment['METHOD'] === true) { - if ($payments) { - foreach ($payments as $payment) { - if (!isset($payment['externalId'])) { - if ($payment['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { - $payment['externalId'] = $arPayment['ID']; - RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $payment, $site); - } - } + if ($payments) { + foreach ($payments as $payment) { + if (isset($payment['externalId'])) { + $paymentsExternalIds[$payment['externalId']] = $payment; } } + } + + if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) { + $paymentToCrm = array( + 'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']], + 'amount' => $arPayment['SUM'] + ); + + if (!empty($arPayment['ID'])) { + $paymentToCrm['externalId'] = $arPayment['ID']; + } + + if (!empty($arPayment['DATE_PAID'])) { + if (is_object($arPayment['DATE_PAID'])) { + $culture = new Bitrix\Main\Context\Culture(array("FORMAT_DATETIME" => "YYYY-MM-DD HH:MI:SS")); + $paymentToCrm['paidAt'] = $arPayment['DATE_PAID']->toString($culture); + } elseif (is_string($arPayment['DATE_PAID'])) { + $paymentToCrm['paidAt'] = $arPayment['DATE_PAID']; + } + } + + if (!empty($optionsPayStatuses[$arPayment['PAID']])) { + $paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']]; + } + + if (!empty($arPayment['ORDER_ID'])) { + $paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID']; + } } else { - if ($payments) { - foreach ($payments as $payment) { - if (isset($payment['externalId'])) { - $paymentsExternalIds[$payment['externalId']] = $payment; - } - } - } + RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.'); + return; + } - if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) { - $paymentToCrm = array( - 'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']], - 'amount' => $arPayment['SUM'] - ); - - if (!empty($arPayment['ID'])) { - $paymentToCrm['externalId'] = $arPayment['ID']; - } - - if (!empty($arPayment['DATE_PAID'])) { - if (is_object($arPayment['DATE_PAID'])) { - $culture = new Bitrix\Main\Context\Culture(array("FORMAT_DATETIME" => "YYYY-MM-DD HH:MI:SS")); - $paymentToCrm['paidAt'] = $arPayment['DATE_PAID']->toString($culture); - } elseif (is_string($arPayment['DATE_PAID'])) { - $paymentToCrm['paidAt'] = $arPayment['DATE_PAID']; - } - } - - if (!empty($optionsPayStatuses[$arPayment['PAID']])) { - $paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']]; - } - - if (!empty($arPayment['ORDER_ID'])) { - $paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID']; - } - } else { - RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.'); - return; - } - - if (!array_key_exists($arPayment['ID'], $paymentsExternalIds)) { - RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); - } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { - RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site); - } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { - RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $paymentsExternalIds[$arPayment['ID']]['id']); - RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); - } + if (!array_key_exists($arPayment['ID'], $paymentsExternalIds)) { + RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); + } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { + RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site); + } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { + RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $paymentsExternalIds[$arPayment['ID']]['id']); + RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); } } diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 86ad509e..5fd72fdc 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Добавлен функционал для активации модуля в маркетплейсе retailCRM \ No newline at end of file +- Изменена привязка на событие сохранения заказа. Теперь модуль привязан к событию, которое вызывается после сохранения всех сущностей. \ No newline at end of file diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 11ab0390..97fed83f 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -891,7 +891,7 @@ class intaro_retailcrm extends CModule RegisterModule($this->MODULE_ID); RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder"); RegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate"); - RegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "orderSave"); + RegisterModuleDependences("sale", \Bitrix\sale\EventActions::EVENT_ON_ORDER_SAVED, $this->MODULE_ID, "RetailCrmEvent", "orderSave"); RegisterModuleDependences("sale", "OnSaleOrderDeleted", $this->MODULE_ID, "RetailCrmEvent", "orderDelete"); RegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave"); RegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $this->MODULE_ID, "RetailCrmEvent", "paymentDelete"); @@ -1067,6 +1067,8 @@ class intaro_retailcrm extends CModule include($this->INSTALL_PATH . '/../classes/general/Response/ApiResponse.php'); include($this->INSTALL_PATH . '/../classes/general/Exception/InvalidJsonException.php'); include($this->INSTALL_PATH . '/../classes/general/Exception/CurlException.php'); + include($this->INSTALL_PATH . '/../classes/general/RCrmActions.php'); + include($this->INSTALL_PATH . '/../classes/general/Logger.php'); if ($api_version == 'v4') { include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php'); @@ -1128,10 +1130,19 @@ class intaro_retailcrm extends CModule COption::RemoveOption($this->MODULE_ID, $this->HISTORY_TIME); COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID); + if (CModule::IncludeModule('sale')) { + UnRegisterModuleDependences( + "sale", + \Bitrix\sale\EventActions::EVENT_ON_ORDER_SAVED, + $this->MODULE_ID, + "RetailCrmEvent", + "orderSave" + ); + } + UnRegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder"); UnRegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate"); - UnRegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "orderSave"); - UnRegisterModuleDependences("sale", "OnSaleBeforeOrderDelete", $this->MODULE_ID, "RetailCrmEvent", "orderDelete"); + UnRegisterModuleDependences("sale", "OnSaleOrderDeleted", $this->MODULE_ID, "RetailCrmEvent", "orderDelete"); UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmCollector", "add"); UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmUa", "add"); UnRegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave"); diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 2b65720e..df485965 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -276,12 +276,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { // remove depenedencies - UnRegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $mid, "RetailCrmEvent", "orderSave"); + UnRegisterModuleDependences("sale", \Bitrix\sale\EventActions::EVENT_ON_ORDER_SAVED, $mid, "RetailCrmEvent", "orderSave"); UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); UnRegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete"); } elseif (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { // event dependencies - RegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $mid, "RetailCrmEvent", "orderSave"); + RegisterModuleDependences("sale", \Bitrix\sale\EventActions::EVENT_ON_ORDER_SAVED, $mid, "RetailCrmEvent", "orderSave"); RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete"); }