From 1e12e4d418ba49e45808981a738176ab11cf074f Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Mon, 13 Nov 2017 11:05:11 +0300 Subject: [PATCH] v.2.2.9 (#33) --- CHANGELOG.md | 4 +++ .../classes/general/RCrmActions.php | 10 +++--- .../general/history/RetailCrmHistory_v4.php | 10 +++--- .../general/history/RetailCrmHistory_v5.php | 16 ++++----- .../general/order/RetailCrmOrder_v4.php | 20 +++++++++-- .../general/order/RetailCrmOrder_v5.php | 36 +++++++++---------- intaro.retailcrm/description.ru | 3 +- intaro.retailcrm/include.php | 18 +++++----- intaro.retailcrm/install/version.php | 4 +-- intaro.retailcrm/options.php | 4 +++ 10 files changed, 74 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c6d184..1c2b21b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2017-11-01 v.2.2.8 +* Исправлены баги пакетной выгрузки +* Исправлена ошибка при работе на php7.1 + ## 2017-10-26 v.2.2.7 * Исправлен баг при работе с одним сайтом diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index 66af6ae3..5feecf42 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -326,7 +326,7 @@ class RCrmActions return self::proxy($api, $methodApi, $method, array($params, $site)); } } - + private function proxy($api, $methodApi, $method, $params) { $log = new Logger(); $version = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_VERSION, 0); @@ -360,11 +360,11 @@ class RCrmActions 'params' => $params ), 'apiErrors'); } - + if (function_exists('retailCrmApiResult')) { retailCrmApiResult($methodApi, false, $result->getStatusCode()); } - + if ($result->getStatusCode() == 460) { return true; } @@ -408,11 +408,11 @@ class RCrmActions return false; } - + if (function_exists('retailCrmApiResult')) { retailCrmApiResult($methodApi, true, $result->getStatusCode()); } - + return $result; } } diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php index 35db0eae..0315d3d9 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php @@ -614,7 +614,7 @@ class RetailCrmHistory 'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(), 'LID' => $site, 'BASE_PRICE' => $product['initialPrice'], - 'NAME' => $product['name'] ? RCrmActions::fromJSON($product['name']) : $elem['NAME'], + 'NAME' => $product['offer']['name'] ? RCrmActions::fromJSON($product['offer']['name']) : $elem['NAME'], 'DETAIL_PAGE_URL' => $elem['URL'] )); } else { @@ -1186,16 +1186,16 @@ class RetailCrmHistory return $outputArray; } - public static function setProp($obj, $value = '', $prop) + public static function setProp($obj, $value = '', $prop = '') { if (!isset($obj)) { return false; } - if ($prop) { + if ($prop && $value) { $obj->setField($prop, $value); - } elseif ($value) { + } elseif ($value && !$prop) { $obj->setValue($value); - } else { + } elseif (!$value && !$prop) { $obj->delete(); } diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 5c29b037..de3ddd33 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -629,7 +629,7 @@ class RetailCrmHistory 'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(), 'LID' => $site, 'BASE_PRICE' => $product['initialPrice'], - 'NAME' => $product['name'] ? RCrmActions::fromJSON($product['name']) : $elem['NAME'], + 'NAME' => $product['offer']['name'] ? RCrmActions::fromJSON($product['offer']['name']) : $elem['NAME'], 'DETAIL_PAGE_URL' => $elem['URL'], 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider', 'DIMENSIONS' => $elem['DIMENSIONS'], @@ -1155,7 +1155,7 @@ class RetailCrmHistory //data from crm $paySumm = 0; foreach ($paymentsCrm['payments'] as $paymentCrm) { - if (!empty($paymentCrm['externalId'])) { + if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) { //find the payment $nowPayment = $paymentsList[$paymentCrm['externalId']]; //update data @@ -1189,9 +1189,9 @@ class RetailCrmHistory unset($paymentsList[$newPaymentId]); - RCrmActions::apiMethod($api, 'ordersPaymentEdit', __METHOD__, array('id' => $paymentCrm['id'], 'externalId' => $newPaymentId)); + RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, array('id' => $paymentCrm['id'], 'externalId' => $newPaymentId)); } - + if ($optionsPayment[$paymentCrm['status']] == 'Y') { $paySumm += $paymentCrm['amount']; } @@ -1242,16 +1242,16 @@ class RetailCrmHistory return $outputArray; } - public static function setProp($obj, $value = '', $prop) + public static function setProp($obj, $value = '', $prop = '') { if (!isset($obj)) { return false; } - if ($prop) { + if ($prop && $value) { $obj->setField($prop, $value); - } elseif ($value) { + } elseif ($value && !$prop) { $obj->setValue($value); - } else { + } elseif (!$value && !$prop) { $obj->delete(); } diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php index f184300c..7fab2660 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php @@ -272,7 +272,15 @@ class RetailCrmOrder if (count($resOrders) > 0) { foreach ($resCustomers as $key => $customerLoad) { - $site = count($optionsSitesList) > 1 ? $optionsSitesList[$key] : null; + if ($optionsSitesList) { + if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) { + $site = $optionsSitesList[$key]; + } else { + continue; + } + } elseif (!$optionsSitesList) { + $site == null; + } if (RCrmActions::apiMethod($api, 'customersUpload', __METHOD__, $customerLoad, $site) === false) { return false; } @@ -281,7 +289,15 @@ class RetailCrmOrder } } foreach ($resOrders as $key => $orderLoad) { - $site = count($optionsSitesList) > 1 ? $optionsSitesList[$key] : null; + if ($optionsSitesList) { + if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) { + $site = $optionsSitesList[$key]; + } else { + continue; + } + } elseif (!$optionsSitesList) { + $site == null; + } if (RCrmActions::apiMethod($api, 'ordersUpload', __METHOD__, $orderLoad, $site) === false) { return false; } diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index 2b22526a..01320ebf 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -173,7 +173,7 @@ class RetailCrmOrder $order = $newResOrder; } elseif ($newResOrder === false) { RCrmActions::eventLog('RetailCrmOrder::orderSend', 'retailCrmBeforeOrderSend()', 'OrderID = ' . $arFields['ID'] . '. Sending canceled after retailCrmBeforeOrderSend'); - + return false; } } @@ -279,16 +279,6 @@ class RetailCrmOrder $order = self::orderObjToArr($id); $user = Bitrix\Main\UserTable::getById($order['USER_ID'])->fetch(); - if(array_key_exists($arOrder['LID'], $optionsSitesList)) { - $site = $optionsSitesList[$arOrder['LID']]; - } else { - $site = null; - } - - if ($site == null) { - continue; - } - $arCustomers = RetailCrmUser::customerSend($user, $api, $optionsContragentType[$order['PERSON_TYPE_ID']], false, $site); $arOrders = self::orderSend($order, $api, $arParams, false, $site); @@ -304,10 +294,14 @@ class RetailCrmOrder if (count($resOrders) > 0) { foreach ($resCustomers as $key => $customerLoad) { - if(array_key_exists($key, $optionsSitesList)) { - $site = $optionsSitesList[$key]; - } else { - $site = null; + if ($optionsSitesList) { + if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) { + $site = $optionsSitesList[$key]; + } else { + continue; + } + } elseif (!$optionsSitesList) { + $site == null; } if (RCrmActions::apiMethod($api, 'customersUpload', __METHOD__, $customerLoad, $site) === false) { return false; @@ -317,10 +311,14 @@ class RetailCrmOrder } } foreach ($resOrders as $key => $orderLoad) { - if(array_key_exists($key, $optionsSitesList)) { - $site = $optionsSitesList[$key]; - } else { - $site = null; + if ($optionsSitesList) { + if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) { + $site = $optionsSitesList[$key]; + } else { + continue; + } + } elseif (!$optionsSitesList) { + $site == null; } if (RCrmActions::apiMethod($api, 'ordersUpload', __METHOD__, $orderLoad, $site) === false) { return false; diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 2d807217..5834571e 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1,2 @@ -- Исправлен баг при работе с одним сайтом \ No newline at end of file +- Исправлены ошибки подключения кастомных классов +- Улучшена обработка истории \ No newline at end of file diff --git a/intaro.retailcrm/include.php b/intaro.retailcrm/include.php index def2ac68..e6c2a4cf 100644 --- a/intaro.retailcrm/include.php +++ b/intaro.retailcrm/include.php @@ -5,20 +5,20 @@ $version = COption::GetOptionString('intaro.retailcrm', 'api_version'); CModule::AddAutoloadClasses( 'intaro.retailcrm', // module name array ( - 'RestNormalizer' => file_exists($server . '/bitrix/php_interface/retailcrm/RestNormalizer.php') ? $server . '/bitrix/php_interface/retailcrm/RestNormalizer.php' : 'classes/general/RestNormalizer.php', - 'Logger' => file_exists($server . '/bitrix/php_interface/retailcrm/Logger.php') ? $server . '/bitrix/php_interface/retailcrm/Logger.php' : 'classes/general/Logger.php', - 'RetailCrm\ApiClient' => file_exists($server . '/bitrix/php_interface/retailcrm/ApiClient.php') ? $server . '/bitrix/php_interface/retailcrm/ApiClient.php' : 'classes/general/ApiClient_' . $version . '.php', - 'RetailCrm\Http\Client' => file_exists($server . '/bitrix/php_interface/retailcrm/Client.php') ? $server . '/bitrix/php_interface/retailcrm/Client.php' : 'classes/general/Http/Client.php', - 'RCrmActions' => file_exists($server . '/bitrix/php_interface/retailcrm/RCrmActions.php') ? $server . '/bitrix/php_interface/retailcrm/RCrmActions.php' : 'classes/general/RCrmActions.php', - 'RetailCrmUser' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php' : 'classes/general/user/RetailCrmUser.php', - 'RetailCrmOrder' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php' : 'classes/general/order/RetailCrmOrder_' . $version . '.php', - 'RetailCrmHistory' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php' : 'classes/general/history/RetailCrmHistory_' . $version . '.php', + 'RestNormalizer' => file_exists($server . '/bitrix/php_interface/retailcrm/RestNormalizer.php') ? '../../php_interface/retailcrm/RestNormalizer.php' : 'classes/general/RestNormalizer.php', + 'Logger' => file_exists($server . '/bitrix/php_interface/retailcrm/Logger.php') ? '../../php_interface/retailcrm/Logger.php' : 'classes/general/Logger.php', + 'RetailCrm\ApiClient' => file_exists($server . '/bitrix/php_interface/retailcrm/ApiClient.php') ? '../../php_interface/retailcrm/ApiClient.php' : 'classes/general/ApiClient_' . $version . '.php', + 'RetailCrm\Http\Client' => file_exists($server . '/bitrix/php_interface/retailcrm/Client.php') ? '../../php_interface/retailcrm/Client.php' : 'classes/general/Http/Client.php', + 'RCrmActions' => file_exists($server . '/bitrix/php_interface/retailcrm/RCrmActions.php') ? '../../php_interface/retailcrm/RCrmActions.php' : 'classes/general/RCrmActions.php', + 'RetailCrmUser' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php') ? '../../php_interface/retailcrm/RetailCrmUser.php' : 'classes/general/user/RetailCrmUser.php', + 'RetailCrmOrder' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php') ? '../../php_interface/retailcrm/RetailCrmOrder.php' : 'classes/general/order/RetailCrmOrder_' . $version . '.php', + 'RetailCrmHistory' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php') ? '../../php_interface/retailcrm/RetailCrmHistory.php' : 'classes/general/history/RetailCrmHistory_' . $version . '.php', 'RetailCrmICML' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmICML.php') ? '../../php_interface/retailcrm/RetailCrmICML.php' : 'classes/general/icml/RetailCrmICML.php', 'RetailCrmInventories' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmInventories.php') ? '../../php_interface/retailcrm/RetailCrmInventories.php' : 'classes/general/inventories/RetailCrmInventories.php', 'RetailCrmPrices' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmPrices.php') ? '../../php_interface/retailcrm/RetailCrmPrices.php' : 'classes/general/prices/RetailCrmPrices.php', 'RetailCrmCollector' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmCollector.php') ? '../../php_interface/retailcrm/RetailCrmCollector.php' : 'classes/general/collector/RetailCrmCollector.php', 'RetailCrmUa' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUa.php') ? '../../php_interface/retailcrm/RetailCrmUa.php' : 'classes/general/ua/RetailCrmUa.php', - 'RetailCrmEvent' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmEvent.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmEvent.php' : 'classes/general/events/RetailCrmEvent.php', + 'RetailCrmEvent' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmEvent.php') ? '../../php_interface/retailcrm/RetailCrmEvent.php' : 'classes/general/events/RetailCrmEvent.php', 'RetailCrm\Response\ApiResponse' => 'classes/general/Response/ApiResponse.php', 'RetailCrm\Exception\InvalidJsonException' => 'classes/general/Exception/InvalidJsonException.php', 'RetailCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php', diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 912acfec..c1ab8ca6 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,5 +1,5 @@ "2.2.7", - "VERSION_DATE" => "2017-09-25 14:50:00" + "VERSION" => "2.2.9", + "VERSION_DATE" => "2017-11-13 11:00:00" ); diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 12b0ee63..fa818c6e 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -276,12 +276,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { UnRegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $mid, "RetailCrmEvent", "orderSave"); UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); UnRegisterModuleDependences("sale", "OnSaleOrderEntityDelete", $mid, "RetailCrmEvent", "orderDelete"); + UnRegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $mid, "RetailCrmEvent", "paymentSave"); + UnRegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $mid, "RetailCrmEvent", "paymentDelete"); } elseif (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { // event dependencies RegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $mid, "RetailCrmEvent", "orderSave"); RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnSaleOrderEntityDelete", $mid, "RetailCrmEvent", "orderDelete"); + RegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $mid, "RetailCrmEvent", "paymentSave"); + RegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $mid, "RetailCrmEvent", "paymentDelete"); } $orderPropsArr = array();