From 24ee93d335f8b8016b43d537f4faf056c89d1e12 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 31 Aug 2018 11:18:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20=D0=B2=20=D0=BC=D0=B0=D1=80?= =?UTF-8?q?=D0=BA=D0=B5=D1=82=D0=BF=D0=BB=D0=B5=D0=B9=D1=81=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B5,=20=D0=B8=20=D0=BD=D0=B0=20=D0=B4=D0=B5=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/general/ApiClient_v5.php | 19 +++--- intaro.retailcrm/install/index.php | 60 ++++++++++++++++++- intaro.retailcrm/lang/ru/install/index.php | 1 + 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/intaro.retailcrm/classes/general/ApiClient_v5.php b/intaro.retailcrm/classes/general/ApiClient_v5.php index 2d032516..9476f2df 100644 --- a/intaro.retailcrm/classes/general/ApiClient_v5.php +++ b/intaro.retailcrm/classes/general/ApiClient_v5.php @@ -123,7 +123,7 @@ class ApiClient $parameters ); } - + /** * Change user status * @@ -608,7 +608,7 @@ class ApiClient $parameters ); } - + /** * Combine orders * @@ -723,13 +723,13 @@ class ApiClient 'Note id must be set' ); } - + return $this->client->makeRequest( "/orders/payments/$id/delete", Client::METHOD_POST ); } - + /** * Combine customers * @@ -1063,7 +1063,7 @@ class ApiClient Client::METHOD_GET ); } - + /** * Get tasks list * @@ -1168,7 +1168,7 @@ class ApiClient Client::METHOD_GET ); } - + /** * Get orders assembly list * @@ -1397,7 +1397,7 @@ class ApiClient $this->fillSite($site, array('offers' => json_encode($offers))) ); } - + /** * Upload store prices * @@ -1483,6 +1483,7 @@ class ApiClient Client::METHOD_GET ); } + /** * Edit module configuration * @@ -1857,7 +1858,7 @@ class ApiClient array('productStatus' => json_encode($data)) ); } - + /** * Get products groups * @@ -2196,7 +2197,7 @@ class ApiClient $parameters ); } - + /** * Get segments list * diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 50af5d2d..a0b96a3b 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -69,6 +69,8 @@ class intaro_retailcrm extends CModule var $CRM_API_VERSION = 'api_version'; var $HISTORY_TIME = 'history_time'; + var $CLIENT_ID = 'client_id'; + var $INSTALL_PATH; function intaro_retailcrm() @@ -1042,9 +1044,27 @@ class intaro_retailcrm extends CModule $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); + $api_version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0); $this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); + $clientId = hash('md5', date('Y-m-d H:i:s')); + try { - $this->RETAIL_CRM_API->statisticUpdate(); + $configuration = array( + 'clientId' => $clientId, + 'code' => 'bitrix', + 'integrationCode' => 'bitrix', + 'active' => true, + 'name' => GetMessage('API_MODULE_NAME'), + 'logo' => 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af47fe682bf2-1c-bitrix-logo.svg' + ); + + if ($api_version == 'v4') { + $this->RETAIL_CRM_API->marketplaceSettingsEdit($configuration); + } else { + $this->RETAIL_CRM_API->integrationModulesEdit($configuration); + } + + COption::SetOptionString($this->MODULE_ID, $this->CLIENT_ID, $clientId); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::statisticUpdate::CurlException', @@ -1062,6 +1082,35 @@ class intaro_retailcrm extends CModule { global $APPLICATION; + $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); + $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); + $api_version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0); + $clientId = COption::GetOptionString($this->MODULE_ID, $this->CLIENT_ID, 0); + + include($this->INSTALL_PATH . '/../classes/general/Http/Client.php'); + 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'); + + if ($api_version == 'v4') { + include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php'); + include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v4.php'); + include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v4.php'); + } elseif ($api_version == 'v5') { + include($this->INSTALL_PATH . '/../classes/general/ApiClient_v5.php'); + include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v5.php'); + include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v5.php'); + } + + $retail_crm_api = new \RetailCrm\ApiClient($api_host, $api_key); + + $configuration = array( + 'clientId' => $clientId, + 'code' => 'bitrix', + 'integrationCode' => 'bitrix', + 'active' => false, + ); + CAgent::RemoveAgent("RCrmActions::orderAgent();", $this->MODULE_ID); CAgent::RemoveAgent("RetailCrmInventories::inventoriesUpload();", $this->MODULE_ID); CAgent::RemoveAgent("RetailCrmPrices::pricesUpload();", $this->MODULE_ID); @@ -1108,6 +1157,7 @@ class intaro_retailcrm extends CModule COption::RemoveOption($this->MODULE_ID, $this->CRM_API_VERSION); COption::RemoveOption($this->MODULE_ID, $this->HISTORY_TIME); + COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID); UnRegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder"); UnRegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate"); @@ -1131,12 +1181,18 @@ class intaro_retailcrm extends CModule } } + if ($api_version == 'v4') { + $retail_crm_api->marketplaceSettingsEdit($configuration); + } else { + $retail_crm_api->integrationModulesEdit($configuration); + } + $this->DeleteFiles(); UnRegisterModule($this->MODULE_ID); $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_UNINSTALL_TITLE'), $this->INSTALL_PATH . '/unstep1.php' + GetMessage('MODULE_UNINSTALL_TITLE'), $this->INSTALL_PATH . '/unstep1.php' ); } diff --git a/intaro.retailcrm/lang/ru/install/index.php b/intaro.retailcrm/lang/ru/install/index.php index 3c933503..1af156b1 100644 --- a/intaro.retailcrm/lang/ru/install/index.php +++ b/intaro.retailcrm/lang/ru/install/index.php @@ -13,6 +13,7 @@ $MESS ['RETAILCRM_CURL_ERR'] = 'Для работы модуля интегра $MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы'; $MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.'; $MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.'; +$MESS ['API_MODULE_NAME'] = '1С-Битрикс'; /* $MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа retailCRM свойствам заказа 1С-Битрикс'; $MESS ['FIO'] = 'Ф.И.О.';