From 24ee93d335f8b8016b43d537f4faf056c89d1e12 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 31 Aug 2018 11:18:42 +0300 Subject: [PATCH 1/6] =?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'] = 'Ф.И.О.'; From e1f429449fc4a57386750e9e03bedef1068cfad2 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 31 Aug 2018 14:03:04 +0300 Subject: [PATCH 2/6] =?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=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D1=8F=20=D0=B2=20=D0=B0=D0=B4=D0=BC=D0=B8?= =?UTF-8?q?=D0=BD=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/install/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index a0b96a3b..bd16df2b 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -1047,6 +1047,8 @@ class intaro_retailcrm extends CModule $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')); + $scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; + $baseUrl = $scheme . $_SERVER['HTTP_HOST']; try { $configuration = array( @@ -1055,7 +1057,9 @@ class intaro_retailcrm extends CModule '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' + 'logo' => 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af47fe682bf2-1c-bitrix-logo.svg', + 'baseUrl' => $baseUrl, + 'accountUrl' => $baseUrl . '/bitrix/admin/settings.php?mid=intaro.retailcrm' ); if ($api_version == 'v4') { From 5f80630806deeeeee77eb70190a909e2318d3d74 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 31 Aug 2018 15:00:46 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D1=83=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D0=BE=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D1=8E=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=B4?= =?UTF-8?q?=D0=BB=D1=8F=20v4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/install/index.php | 43 +++++++++++++++++++----------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index bd16df2b..0bca1b63 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -1046,29 +1046,40 @@ class intaro_retailcrm extends CModule $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')); $scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; $baseUrl = $scheme . $_SERVER['HTTP_HOST']; + $code = 'bitrix'; + $logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af47fe682bf2-1c-bitrix-logo.svg'; + $accountUrl = $baseUrl . '/bitrix/admin/settings.php?mid=intaro.retailcrm'; try { - $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', - 'baseUrl' => $baseUrl, - 'accountUrl' => $baseUrl . '/bitrix/admin/settings.php?mid=intaro.retailcrm' - ); - if ($api_version == 'v4') { + $configuration = array( + 'name' => GetMessage('API_MODULE_NAME'), + 'code' => $code, + 'logo' => $logo, + 'configurationUrl' => $accountUrl, + 'active' => true + ); + $this->RETAIL_CRM_API->marketplaceSettingsEdit($configuration); } else { - $this->RETAIL_CRM_API->integrationModulesEdit($configuration); - } + $clientId = hash('md5', date('Y-m-d H:i:s')); - COption::SetOptionString($this->MODULE_ID, $this->CLIENT_ID, $clientId); + $configuration = array( + 'clientId' => $clientId, + 'code' => $code, + 'integrationCode' => $code, + 'active' => true, + 'name' => GetMessage('API_MODULE_NAME'), + 'logo' => $logo, + 'baseUrl' => $baseUrl, + 'accountUrl' => $accountUrl + ); + + $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', @@ -1186,6 +1197,8 @@ class intaro_retailcrm extends CModule } if ($api_version == 'v4') { + unset($configuration['integrationCode']); + unset($configuration['clientId']); $retail_crm_api->marketplaceSettingsEdit($configuration); } else { $retail_crm_api->integrationModulesEdit($configuration); From 4e244d9791966a3cc9d987458c4e538d1f6feedd Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Thu, 18 Oct 2018 12:07:10 +0300 Subject: [PATCH 4/6] Add send configuration method --- .../classes/general/RCrmActions.php | 129 ++++++++++++------ intaro.retailcrm/install/index.php | 56 +------- .../lang/ru/classes/general/RCrmActions.php | 2 + intaro.retailcrm/lang/ru/install/index.php | 1 - 4 files changed, 90 insertions(+), 98 deletions(-) create mode 100644 intaro.retailcrm/lang/ru/classes/general/RCrmActions.php diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index b4ac891c..fde89489 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -13,15 +13,15 @@ class RCrmActions $arSites = array(); $rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y')); while ($ar = $rsSites->Fetch()) { - $arSites[] = $ar; + $arSites[] = $ar; } - + return $arSites; } - + public static function OrderTypesList($arSites) { - $orderTypesList = array(); + $orderTypesList = array(); foreach ($arSites as $site) { $personTypes = \Bitrix\Sale\PersonType::load($site['LID']); $bitrixOrderTypesList = array(); @@ -33,10 +33,10 @@ class RCrmActions } $orderTypesList = $orderTypesList + $bitrixOrderTypesList; } - + return $orderTypesList; } - + public static function DeliveryList() { $bitrixDeliveryTypesList = array(); @@ -49,9 +49,9 @@ class RCrmActions } } foreach ($arDeliveryServiceAll as $arDeliveryService) { - if ((($arDeliveryService['PARENT_ID'] == '0' || $arDeliveryService['PARENT_ID'] == null) || - in_array($arDeliveryService['PARENT_ID'], $groups)) && - $arDeliveryService['ID'] != $noOrderId && + if ((($arDeliveryService['PARENT_ID'] == '0' || $arDeliveryService['PARENT_ID'] == null) || + in_array($arDeliveryService['PARENT_ID'], $groups)) && + $arDeliveryService['ID'] != $noOrderId && $arDeliveryService['CLASS_NAME'] != '\Bitrix\Sale\Delivery\Services\Group') { if (in_array($arDeliveryService['PARENT_ID'], $groups)) { $arDeliveryService['PARENT_ID'] = 0; @@ -62,7 +62,7 @@ class RCrmActions return $bitrixDeliveryTypesList; } - + public static function PaymentList() { $bitrixPaymentTypesList = array(); @@ -73,9 +73,9 @@ class RCrmActions while ($payment = $dbPaymentAll->fetch()) { $bitrixPaymentTypesList[] = $payment; } - + return $bitrixPaymentTypesList; - } + } public static function StatusesList() { @@ -90,7 +90,7 @@ class RCrmActions 'NAME' => $arStatus['NAME'], ); } - + return $bitrixPaymentStatusesList; } @@ -104,11 +104,11 @@ class RCrmActions while ($prop = $arPropsAll->Fetch()) { $bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop; } - + return $bitrixPropsList; - } - - public static function PricesExportList() + } + + public static function PricesExportList() { $priceId = COption::GetOptionString(self::$MODULE_ID, 'catalog_base_price', 0); $catalogExportPrices = array(); @@ -117,21 +117,21 @@ class RCrmActions { $catalogExportPrices[$arPriceType['ID']] = $arPriceType; } - + return $catalogExportPrices; - } - - public static function StoresExportList() + } + + public static function StoresExportList() { $catalogExportStores = array(); $dbStores = CCatalogStore::GetList(array(), array("ACTIVE" => "Y"), false, false, array('ID', 'TITLE')); while ($stores = $dbStores->Fetch()) { $catalogExportStores[] = $stores; } - + return $catalogExportStores; - } - + } + public static function IblocksExportList() { $catalogExportIblocks = array(); @@ -154,10 +154,10 @@ class RCrmActions } } } - + return $catalogExportIblocks; } - + /** * * w+ event in bitrix log @@ -208,7 +208,7 @@ class RCrmActions RetailCrmHistory::customerHistory(); RetailCrmHistory::orderHistory(); self::uploadOrdersAgent(); - + return 'RCrmActions::orderAgent();'; } @@ -295,7 +295,7 @@ class RCrmActions } else { $newFio = explode(" ", $fio, 3); } - + switch (count($newFio)) { default: case 0: @@ -322,31 +322,74 @@ class RCrmActions return $result; } + public static function sendConfiguration($api, $api_version, $active = true) + { + $scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; + $baseUrl = $scheme . $_SERVER['HTTP_HOST']; + $integrationCode = 'bitrix'; + $logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af47fe682bf2-1c-bitrix-logo.svg'; + $accountUrl = $baseUrl . '/bitrix/admin'; + + $clientId = COption::GetOptionString(self::$MODULE_ID, 'client_id', 0); + + if (!$clientId) { + $clientId = uniqid(); + COption::SetOptionString(self::$MODULE_ID, 'client_id', $clientId); + } + + $code = $integrationCode . '-' . $clientId; + + if ($api_version == 'v4') { + $configuration = array( + 'name' => GetMessage('API_MODULE_NAME'), + 'code' => $code, + 'logo' => $logo, + 'configurationUrl' => $accountUrl, + 'active' => $active + ); + + self::apiMethod($api, 'marketplaceSettingsEdit', __METHOD__, $configuration); + } else { + $configuration = array( + 'clientId' => $clientId, + 'code' => $code, + 'integrationCode' => $integrationCode, + 'active' => $active, + 'name' => GetMessage('API_MODULE_NAME'), + 'logo' => $logo, + 'baseUrl' => $baseUrl, + 'accountUrl' => $accountUrl + ); + + self::apiMethod($api, 'integrationModulesEdit', __METHOD__, $configuration); + } + } + public static function apiMethod($api, $methodApi, $method, $params, $site = null) { switch ($methodApi) { - case 'ordersPaymentDelete': + case 'ordersPaymentDelete': case 'ordersHistory': - case 'customerHistory': + case 'customerHistory': case 'ordersFixExternalIds': case 'customersFixExternalIds': return self::proxy($api, $methodApi, $method, array($params)); - + case 'orderGet': return self::proxy($api, 'ordersGet', $method, array($params, 'id', $site)); - + case 'ordersGet': case 'ordersEdit': case 'customersGet': case 'customersEdit': return self::proxy($api, $methodApi, $method, array($params, 'externalId', $site)); - + case 'paymentEditById': return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'id', $site)); - + case 'paymentEditByExternalId': return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'externalId', $site)); - + default: return self::proxy($api, $methodApi, $method, array($params, $site)); } @@ -403,12 +446,12 @@ class RCrmActions ); $log->write(array( 'api' => $version, - 'methodApi' => $methodApi, - 'errorMsg' => $e->getMessage(), - 'errors' => $e->getCode(), + 'methodApi' => $methodApi, + 'errorMsg' => $e->getMessage(), + 'errors' => $e->getCode(), 'params' => $params ), 'apiErrors'); - + if (function_exists('retailCrmApiResult')) { retailCrmApiResult($methodApi, false, 'CurlException'); } @@ -421,12 +464,12 @@ class RCrmActions ); $log->write(array( 'api' => $version, - 'methodApi' => $methodApi, - 'errorMsg' => $e->getMessage(), - 'errors' => $e->getCode(), + 'methodApi' => $methodApi, + 'errorMsg' => $e->getMessage(), + 'errors' => $e->getCode(), 'params' => $params ), 'apiErrors'); - + if (function_exists('retailCrmApiResult')) { retailCrmApiResult($methodApi, false, 'ArgumentException'); } diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 0bca1b63..11ab0390 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -1046,46 +1046,8 @@ class intaro_retailcrm extends CModule $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); - $scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; - $baseUrl = $scheme . $_SERVER['HTTP_HOST']; - $code = 'bitrix'; - $logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af47fe682bf2-1c-bitrix-logo.svg'; - $accountUrl = $baseUrl . '/bitrix/admin/settings.php?mid=intaro.retailcrm'; - try { - if ($api_version == 'v4') { - $configuration = array( - 'name' => GetMessage('API_MODULE_NAME'), - 'code' => $code, - 'logo' => $logo, - 'configurationUrl' => $accountUrl, - 'active' => true - ); - - $this->RETAIL_CRM_API->marketplaceSettingsEdit($configuration); - } else { - $clientId = hash('md5', date('Y-m-d H:i:s')); - - $configuration = array( - 'clientId' => $clientId, - 'code' => $code, - 'integrationCode' => $code, - 'active' => true, - 'name' => GetMessage('API_MODULE_NAME'), - 'logo' => $logo, - 'baseUrl' => $baseUrl, - 'accountUrl' => $accountUrl - ); - - $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', - $e->getCode() . ': ' . $e->getMessage() - ); - } + RCrmActions::sendConfiguration($this->RETAIL_CRM_API, $api_version); $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step6.php' @@ -1100,7 +1062,6 @@ 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); - $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'); @@ -1119,13 +1080,6 @@ class intaro_retailcrm extends CModule $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); @@ -1196,13 +1150,7 @@ class intaro_retailcrm extends CModule } } - if ($api_version == 'v4') { - unset($configuration['integrationCode']); - unset($configuration['clientId']); - $retail_crm_api->marketplaceSettingsEdit($configuration); - } else { - $retail_crm_api->integrationModulesEdit($configuration); - } + RCrmActions::sendConfiguration($retail_crm_api, $api_version, false); $this->DeleteFiles(); diff --git a/intaro.retailcrm/lang/ru/classes/general/RCrmActions.php b/intaro.retailcrm/lang/ru/classes/general/RCrmActions.php new file mode 100644 index 00000000..5e605d10 --- /dev/null +++ b/intaro.retailcrm/lang/ru/classes/general/RCrmActions.php @@ -0,0 +1,2 @@ + Date: Thu, 25 Oct 2018 10:35:15 +0300 Subject: [PATCH 5/6] Fix catalog --- intaro.retailcrm/classes/general/icml/RetailCrmICML.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php index d55f3b89..a46be235 100644 --- a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php +++ b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php @@ -74,7 +74,7 @@ class RetailCrmICML $defaultSite = CSite::GetList($by = "def", $order = "desc", array('DEF' => 'Y'))->Fetch(); $this->encodingDefault = $defaultSite["CHARSET"]; - $url = 'https://' . $this->serverName; + $url = 'https://' . $this->defaultServerName; $curlHandler = curl_init(); curl_setopt($curlHandler, CURLOPT_URL, $url); $responseBody = curl_exec($curlHandler); From 3efbd85c16e13ea3b29d1818385d83b6de1088a7 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Thu, 25 Oct 2018 10:42:16 +0300 Subject: [PATCH 6/6] v2.3.13 --- CHANGELOG.md | 4 ++++ intaro.retailcrm/description.ru | 3 +-- intaro.retailcrm/install/version.php | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3127b7..20634551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2018-10-25 v.2.3.13 +* Добавлен функционал для активации модуля в маркетплейсе retailCRM +* Исправлен баг при генерации каталога с подстановкой схемы + ## 2018-10-17 v.2.3.12 * Исрпавлена некорректная выгрузка остатков по складам * Исправлена отправка габаритов товаров в заказах diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 566db60a..86ad509e 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1,2 +1 @@ -- Исправлена передача габаритов товаров в заказе -- Исправлена передача остатков по складам \ No newline at end of file +- Добавлен функционал для активации модуля в маркетплейсе retailCRM \ No newline at end of file diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index de4a7c69..13dfef96 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,5 +1,5 @@ "2.3.12", - "VERSION_DATE" => "2018-10-17 13:50:00" + "VERSION" => "2.3.13", + "VERSION_DATE" => "2018-10-25 10:40:00" );