1
0
mirror of synced 2024-11-22 13:26:10 +03:00

Merge pull request #54 from sergeygw1990/master

v2.4.0
This commit is contained in:
Alex Lushpai 2018-11-07 12:52:47 +03:00 committed by GitHub
commit e4ba1db330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 77 deletions

View File

@ -1,3 +1,10 @@
## 2018-11-02 v.2.4.0
* Изменена привязка на событие сохранения заказа. Используется привязка к событию "OnSaleOrderSaved"
* Исправлено удаление событий модуля при удалении модуля интеграции из CMS
* Добавлено подключение файла Logger.php при удалении модуля
* Изменен механизм определения протокола, с которым работает сайт. Используется метод isHttps() 1С-Bitrix
* Исправлена передача веса товара при отправке габбаритов заказа
## 2018-10-29 v.2.3.14 ## 2018-10-29 v.2.3.14
* Добавлено подключение файла RCrmActions.php при удалении модуля * Добавлено подключение файла RCrmActions.php при удалении модуля

View File

@ -168,7 +168,6 @@ class RetailCrmEvent
$arParams['crmOrder'] = $orderCrm['order']; $arParams['crmOrder'] = $orderCrm['order'];
} else { } else {
$methodApi = 'ordersCreate'; $methodApi = 'ordersCreate';
$GLOBALS['RETAILCRM_ORDER_NEW_ORDER'] = true;
} }
//user //user
@ -222,7 +221,6 @@ class RetailCrmEvent
'SUM' => $event->getField('SUM'), 'SUM' => $event->getField('SUM'),
'LID' => $event->getField('LID'), 'LID' => $event->getField('LID'),
'DATE_PAID' => $event->getField('DATE_PAID'), 'DATE_PAID' => $event->getField('DATE_PAID'),
'METHOD' => $GLOBALS['RETAILCRM_ORDER_NEW_ORDER'],
); );
try { try {
@ -252,65 +250,52 @@ class RetailCrmEvent
$payments = $orderCrm['order']['payments']; $payments = $orderCrm['order']['payments'];
} }
if ($arPayment['METHOD'] === true) { if ($payments) {
if ($payments) { foreach ($payments as $payment) {
foreach ($payments as $payment) { if (isset($payment['externalId'])) {
if (!isset($payment['externalId'])) { $paymentsExternalIds[$payment['externalId']] = $payment;
if ($payment['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
$payment['externalId'] = $arPayment['ID'];
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $payment, $site);
}
}
} }
} }
}
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 { } else {
if ($payments) { RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
foreach ($payments as $payment) { return;
if (isset($payment['externalId'])) { }
$paymentsExternalIds[$payment['externalId']] = $payment;
}
}
}
if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) { if (!array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
$paymentToCrm = array( RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']], } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
'amount' => $arPayment['SUM'] 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']);
if (!empty($arPayment['ID'])) { RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
$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);
}
} }
} }

View File

@ -36,6 +36,7 @@ class RetailCrmICML
protected $MODULE_ID = 'intaro.retailcrm'; protected $MODULE_ID = 'intaro.retailcrm';
protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
protected $PROTOCOL_OPTION = 'protocol';
protected $measurement = array ( protected $measurement = array (
'mm' => 1, // 1 mm = 1 mm 'mm' => 1, // 1 mm = 1 mm
@ -74,17 +75,7 @@ class RetailCrmICML
$defaultSite = CSite::GetList($by = "def", $order = "desc", array('DEF' => 'Y'))->Fetch(); $defaultSite = CSite::GetList($by = "def", $order = "desc", array('DEF' => 'Y'))->Fetch();
$this->encodingDefault = $defaultSite["CHARSET"]; $this->encodingDefault = $defaultSite["CHARSET"];
$url = 'https://' . $this->defaultServerName; $this->protocol = COption::GetOptionString($this->MODULE_ID, $this->PROTOCOL_OPTION);
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
curl_close($curlHandler);
if ($statusCode == 200) {
$this->protocol = 'https://';
} else {
$this->protocol = 'http://';
}
$this->PrepareSettings(); $this->PrepareSettings();

View File

@ -171,7 +171,7 @@ class RetailCrmOrder
$width += $dimensions['WIDTH']; $width += $dimensions['WIDTH'];
$height += $dimensions['HEIGHT']; $height += $dimensions['HEIGHT'];
$length += $dimensions['LENGTH']; $length += $dimensions['LENGTH'];
$weight += $product['WEIGHT']; $weight += $product['WEIGHT'] * $product['QUANTITY'];
} }
} }
} }

View File

@ -1 +1,2 @@
- Исправлены ошибки - Изменена привязка на событие сохранения заказа. Теперь модуль привязан к событию, которое вызывается после сохранения всех сущностей.
- Изменена механика получения протокола, с которым работает сайт клиента. ТЕперь используется внутренний метод 1C-Bitrix

View File

@ -70,6 +70,7 @@ class intaro_retailcrm extends CModule
var $HISTORY_TIME = 'history_time'; var $HISTORY_TIME = 'history_time';
var $CLIENT_ID = 'client_id'; var $CLIENT_ID = 'client_id';
var $PROTOCOL = 'protocol';
var $INSTALL_PATH; var $INSTALL_PATH;
@ -512,6 +513,14 @@ class intaro_retailcrm extends CModule
//form orderProps //form orderProps
$arResult['arProp'] = RCrmActions::OrderPropsList(); $arResult['arProp'] = RCrmActions::OrderPropsList();
$request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
if ($request->isHttps() === true) {
COption::SetOptionString($this->MODULE_ID, $this->PROTOCOL, 'https://');
} else {
COption::SetOptionString($this->MODULE_ID, $this->PROTOCOL, 'http://');
}
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr))); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr))); COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr))); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
@ -891,7 +900,7 @@ class intaro_retailcrm extends CModule
RegisterModule($this->MODULE_ID); RegisterModule($this->MODULE_ID);
RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder");
RegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate"); 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", "OnSaleOrderDeleted", $this->MODULE_ID, "RetailCrmEvent", "orderDelete");
RegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave"); RegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave");
RegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $this->MODULE_ID, "RetailCrmEvent", "paymentDelete"); RegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $this->MODULE_ID, "RetailCrmEvent", "paymentDelete");
@ -1068,6 +1077,8 @@ class intaro_retailcrm extends CModule
include($this->INSTALL_PATH . '/../classes/general/Exception/InvalidJsonException.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/Exception/CurlException.php');
include($this->INSTALL_PATH . '/../classes/general/RCrmActions.php'); include($this->INSTALL_PATH . '/../classes/general/RCrmActions.php');
include($this->INSTALL_PATH . '/../classes/general/Logger.php');
if ($api_version == 'v4') { if ($api_version == 'v4') {
include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php'); include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php');
@ -1128,11 +1139,21 @@ class intaro_retailcrm extends CModule
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_VERSION); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_VERSION);
COption::RemoveOption($this->MODULE_ID, $this->HISTORY_TIME); COption::RemoveOption($this->MODULE_ID, $this->HISTORY_TIME);
COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID); COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID);
COption::RemoveOption($this->MODULE_ID, $this->PROTOCOL);
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("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder");
UnRegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate"); UnRegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate");
UnRegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "orderSave"); UnRegisterModuleDependences("sale", "OnSaleOrderDeleted", $this->MODULE_ID, "RetailCrmEvent", "orderDelete");
UnRegisterModuleDependences("sale", "OnSaleBeforeOrderDelete", $this->MODULE_ID, "RetailCrmEvent", "orderDelete");
UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmCollector", "add"); UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmCollector", "add");
UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmUa", "add"); UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmUa", "add");
UnRegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave"); UnRegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave");

View File

@ -1,5 +1,5 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
"VERSION" => "2.3.14", "VERSION" => "2.4.0",
"VERSION_DATE" => "2018-10-29 11:40:00" "VERSION_DATE" => "2018-11-02 14:20:00"
); );

View File

@ -43,6 +43,7 @@ $CRM_API_VERSION = 'api_version';
$CRM_CURRENCY = 'currency'; $CRM_CURRENCY = 'currency';
$CRM_ADDRESS_OPTIONS = 'address_options'; $CRM_ADDRESS_OPTIONS = 'address_options';
$CRM_DIMENSIONS = 'order_dimensions'; $CRM_DIMENSIONS = 'order_dimensions';
$PROTOCOL = 'protocol';
if(!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog')) if(!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog'))
return; return;
@ -276,12 +277,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge']));
if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) {
// remove depenedencies // 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", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder");
UnRegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete"); UnRegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete");
} elseif (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { } elseif (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) {
// event dependencies // 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", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder");
RegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete"); RegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete");
} }
@ -513,6 +514,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys))); COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys)));
COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions); COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions);
if ($request->isHttps() === true) {
COption::SetOptionString($mid, $PROTOCOL, 'https://');
} else {
COption::SetOptionString($mid, $PROTOCOL, 'http://');
}
$uri .= '&ok=Y'; $uri .= '&ok=Y';
LocalRedirect($uri); LocalRedirect($uri);
} else { } else {