Add send configuration method
This commit is contained in:
parent
5f80630806
commit
4e244d9791
@ -13,15 +13,15 @@ class RCrmActions
|
|||||||
$arSites = array();
|
$arSites = array();
|
||||||
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
|
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
|
||||||
while ($ar = $rsSites->Fetch()) {
|
while ($ar = $rsSites->Fetch()) {
|
||||||
$arSites[] = $ar;
|
$arSites[] = $ar;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arSites;
|
return $arSites;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function OrderTypesList($arSites)
|
public static function OrderTypesList($arSites)
|
||||||
{
|
{
|
||||||
$orderTypesList = array();
|
$orderTypesList = array();
|
||||||
foreach ($arSites as $site) {
|
foreach ($arSites as $site) {
|
||||||
$personTypes = \Bitrix\Sale\PersonType::load($site['LID']);
|
$personTypes = \Bitrix\Sale\PersonType::load($site['LID']);
|
||||||
$bitrixOrderTypesList = array();
|
$bitrixOrderTypesList = array();
|
||||||
@ -33,10 +33,10 @@ class RCrmActions
|
|||||||
}
|
}
|
||||||
$orderTypesList = $orderTypesList + $bitrixOrderTypesList;
|
$orderTypesList = $orderTypesList + $bitrixOrderTypesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $orderTypesList;
|
return $orderTypesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function DeliveryList()
|
public static function DeliveryList()
|
||||||
{
|
{
|
||||||
$bitrixDeliveryTypesList = array();
|
$bitrixDeliveryTypesList = array();
|
||||||
@ -49,9 +49,9 @@ class RCrmActions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($arDeliveryServiceAll as $arDeliveryService) {
|
foreach ($arDeliveryServiceAll as $arDeliveryService) {
|
||||||
if ((($arDeliveryService['PARENT_ID'] == '0' || $arDeliveryService['PARENT_ID'] == null) ||
|
if ((($arDeliveryService['PARENT_ID'] == '0' || $arDeliveryService['PARENT_ID'] == null) ||
|
||||||
in_array($arDeliveryService['PARENT_ID'], $groups)) &&
|
in_array($arDeliveryService['PARENT_ID'], $groups)) &&
|
||||||
$arDeliveryService['ID'] != $noOrderId &&
|
$arDeliveryService['ID'] != $noOrderId &&
|
||||||
$arDeliveryService['CLASS_NAME'] != '\Bitrix\Sale\Delivery\Services\Group') {
|
$arDeliveryService['CLASS_NAME'] != '\Bitrix\Sale\Delivery\Services\Group') {
|
||||||
if (in_array($arDeliveryService['PARENT_ID'], $groups)) {
|
if (in_array($arDeliveryService['PARENT_ID'], $groups)) {
|
||||||
$arDeliveryService['PARENT_ID'] = 0;
|
$arDeliveryService['PARENT_ID'] = 0;
|
||||||
@ -62,7 +62,7 @@ class RCrmActions
|
|||||||
|
|
||||||
return $bitrixDeliveryTypesList;
|
return $bitrixDeliveryTypesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function PaymentList()
|
public static function PaymentList()
|
||||||
{
|
{
|
||||||
$bitrixPaymentTypesList = array();
|
$bitrixPaymentTypesList = array();
|
||||||
@ -73,9 +73,9 @@ class RCrmActions
|
|||||||
while ($payment = $dbPaymentAll->fetch()) {
|
while ($payment = $dbPaymentAll->fetch()) {
|
||||||
$bitrixPaymentTypesList[] = $payment;
|
$bitrixPaymentTypesList[] = $payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bitrixPaymentTypesList;
|
return $bitrixPaymentTypesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function StatusesList()
|
public static function StatusesList()
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ class RCrmActions
|
|||||||
'NAME' => $arStatus['NAME'],
|
'NAME' => $arStatus['NAME'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bitrixPaymentStatusesList;
|
return $bitrixPaymentStatusesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,11 +104,11 @@ class RCrmActions
|
|||||||
while ($prop = $arPropsAll->Fetch()) {
|
while ($prop = $arPropsAll->Fetch()) {
|
||||||
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
|
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bitrixPropsList;
|
return $bitrixPropsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function PricesExportList()
|
public static function PricesExportList()
|
||||||
{
|
{
|
||||||
$priceId = COption::GetOptionString(self::$MODULE_ID, 'catalog_base_price', 0);
|
$priceId = COption::GetOptionString(self::$MODULE_ID, 'catalog_base_price', 0);
|
||||||
$catalogExportPrices = array();
|
$catalogExportPrices = array();
|
||||||
@ -117,21 +117,21 @@ class RCrmActions
|
|||||||
{
|
{
|
||||||
$catalogExportPrices[$arPriceType['ID']] = $arPriceType;
|
$catalogExportPrices[$arPriceType['ID']] = $arPriceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $catalogExportPrices;
|
return $catalogExportPrices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function StoresExportList()
|
public static function StoresExportList()
|
||||||
{
|
{
|
||||||
$catalogExportStores = array();
|
$catalogExportStores = array();
|
||||||
$dbStores = CCatalogStore::GetList(array(), array("ACTIVE" => "Y"), false, false, array('ID', 'TITLE'));
|
$dbStores = CCatalogStore::GetList(array(), array("ACTIVE" => "Y"), false, false, array('ID', 'TITLE'));
|
||||||
while ($stores = $dbStores->Fetch()) {
|
while ($stores = $dbStores->Fetch()) {
|
||||||
$catalogExportStores[] = $stores;
|
$catalogExportStores[] = $stores;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $catalogExportStores;
|
return $catalogExportStores;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function IblocksExportList()
|
public static function IblocksExportList()
|
||||||
{
|
{
|
||||||
$catalogExportIblocks = array();
|
$catalogExportIblocks = array();
|
||||||
@ -154,10 +154,10 @@ class RCrmActions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $catalogExportIblocks;
|
return $catalogExportIblocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* w+ event in bitrix log
|
* w+ event in bitrix log
|
||||||
@ -208,7 +208,7 @@ class RCrmActions
|
|||||||
RetailCrmHistory::customerHistory();
|
RetailCrmHistory::customerHistory();
|
||||||
RetailCrmHistory::orderHistory();
|
RetailCrmHistory::orderHistory();
|
||||||
self::uploadOrdersAgent();
|
self::uploadOrdersAgent();
|
||||||
|
|
||||||
return 'RCrmActions::orderAgent();';
|
return 'RCrmActions::orderAgent();';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ class RCrmActions
|
|||||||
} else {
|
} else {
|
||||||
$newFio = explode(" ", $fio, 3);
|
$newFio = explode(" ", $fio, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (count($newFio)) {
|
switch (count($newFio)) {
|
||||||
default:
|
default:
|
||||||
case 0:
|
case 0:
|
||||||
@ -322,31 +322,74 @@ class RCrmActions
|
|||||||
return $result;
|
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)
|
public static function apiMethod($api, $methodApi, $method, $params, $site = null)
|
||||||
{
|
{
|
||||||
switch ($methodApi) {
|
switch ($methodApi) {
|
||||||
case 'ordersPaymentDelete':
|
case 'ordersPaymentDelete':
|
||||||
case 'ordersHistory':
|
case 'ordersHistory':
|
||||||
case 'customerHistory':
|
case 'customerHistory':
|
||||||
case 'ordersFixExternalIds':
|
case 'ordersFixExternalIds':
|
||||||
case 'customersFixExternalIds':
|
case 'customersFixExternalIds':
|
||||||
return self::proxy($api, $methodApi, $method, array($params));
|
return self::proxy($api, $methodApi, $method, array($params));
|
||||||
|
|
||||||
case 'orderGet':
|
case 'orderGet':
|
||||||
return self::proxy($api, 'ordersGet', $method, array($params, 'id', $site));
|
return self::proxy($api, 'ordersGet', $method, array($params, 'id', $site));
|
||||||
|
|
||||||
case 'ordersGet':
|
case 'ordersGet':
|
||||||
case 'ordersEdit':
|
case 'ordersEdit':
|
||||||
case 'customersGet':
|
case 'customersGet':
|
||||||
case 'customersEdit':
|
case 'customersEdit':
|
||||||
return self::proxy($api, $methodApi, $method, array($params, 'externalId', $site));
|
return self::proxy($api, $methodApi, $method, array($params, 'externalId', $site));
|
||||||
|
|
||||||
case 'paymentEditById':
|
case 'paymentEditById':
|
||||||
return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'id', $site));
|
return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'id', $site));
|
||||||
|
|
||||||
case 'paymentEditByExternalId':
|
case 'paymentEditByExternalId':
|
||||||
return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'externalId', $site));
|
return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'externalId', $site));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return self::proxy($api, $methodApi, $method, array($params, $site));
|
return self::proxy($api, $methodApi, $method, array($params, $site));
|
||||||
}
|
}
|
||||||
@ -403,12 +446,12 @@ class RCrmActions
|
|||||||
);
|
);
|
||||||
$log->write(array(
|
$log->write(array(
|
||||||
'api' => $version,
|
'api' => $version,
|
||||||
'methodApi' => $methodApi,
|
'methodApi' => $methodApi,
|
||||||
'errorMsg' => $e->getMessage(),
|
'errorMsg' => $e->getMessage(),
|
||||||
'errors' => $e->getCode(),
|
'errors' => $e->getCode(),
|
||||||
'params' => $params
|
'params' => $params
|
||||||
), 'apiErrors');
|
), 'apiErrors');
|
||||||
|
|
||||||
if (function_exists('retailCrmApiResult')) {
|
if (function_exists('retailCrmApiResult')) {
|
||||||
retailCrmApiResult($methodApi, false, 'CurlException');
|
retailCrmApiResult($methodApi, false, 'CurlException');
|
||||||
}
|
}
|
||||||
@ -421,12 +464,12 @@ class RCrmActions
|
|||||||
);
|
);
|
||||||
$log->write(array(
|
$log->write(array(
|
||||||
'api' => $version,
|
'api' => $version,
|
||||||
'methodApi' => $methodApi,
|
'methodApi' => $methodApi,
|
||||||
'errorMsg' => $e->getMessage(),
|
'errorMsg' => $e->getMessage(),
|
||||||
'errors' => $e->getCode(),
|
'errors' => $e->getCode(),
|
||||||
'params' => $params
|
'params' => $params
|
||||||
), 'apiErrors');
|
), 'apiErrors');
|
||||||
|
|
||||||
if (function_exists('retailCrmApiResult')) {
|
if (function_exists('retailCrmApiResult')) {
|
||||||
retailCrmApiResult($methodApi, false, 'ArgumentException');
|
retailCrmApiResult($methodApi, false, 'ArgumentException');
|
||||||
}
|
}
|
||||||
|
@ -1046,46 +1046,8 @@ class intaro_retailcrm extends CModule
|
|||||||
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_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);
|
$api_version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0);
|
||||||
$this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key);
|
$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 {
|
RCrmActions::sendConfiguration($this->RETAIL_CRM_API, $api_version);
|
||||||
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()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$APPLICATION->IncludeAdminFile(
|
$APPLICATION->IncludeAdminFile(
|
||||||
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step6.php'
|
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_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_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
|
||||||
$api_version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 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/Http/Client.php');
|
||||||
include($this->INSTALL_PATH . '/../classes/general/Response/ApiResponse.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);
|
$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("RCrmActions::orderAgent();", $this->MODULE_ID);
|
||||||
CAgent::RemoveAgent("RetailCrmInventories::inventoriesUpload();", $this->MODULE_ID);
|
CAgent::RemoveAgent("RetailCrmInventories::inventoriesUpload();", $this->MODULE_ID);
|
||||||
CAgent::RemoveAgent("RetailCrmPrices::pricesUpload();", $this->MODULE_ID);
|
CAgent::RemoveAgent("RetailCrmPrices::pricesUpload();", $this->MODULE_ID);
|
||||||
@ -1196,13 +1150,7 @@ class intaro_retailcrm extends CModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($api_version == 'v4') {
|
RCrmActions::sendConfiguration($retail_crm_api, $api_version, false);
|
||||||
unset($configuration['integrationCode']);
|
|
||||||
unset($configuration['clientId']);
|
|
||||||
$retail_crm_api->marketplaceSettingsEdit($configuration);
|
|
||||||
} else {
|
|
||||||
$retail_crm_api->integrationModulesEdit($configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->DeleteFiles();
|
$this->DeleteFiles();
|
||||||
|
|
||||||
|
2
intaro.retailcrm/lang/ru/classes/general/RCrmActions.php
Normal file
2
intaro.retailcrm/lang/ru/classes/general/RCrmActions.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
$MESS ['API_MODULE_NAME'] = '1С-Битрикс';
|
@ -13,7 +13,6 @@ $MESS ['RETAILCRM_CURL_ERR'] = 'Для работы модуля интегра
|
|||||||
$MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы';
|
$MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы';
|
||||||
$MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.';
|
$MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.';
|
||||||
$MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.';
|
$MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.';
|
||||||
$MESS ['API_MODULE_NAME'] = '1С-Битрикс';
|
|
||||||
/*
|
/*
|
||||||
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа retailCRM свойствам заказа 1С-Битрикс';
|
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа retailCRM свойствам заказа 1С-Битрикс';
|
||||||
$MESS ['FIO'] = 'Ф.И.О.';
|
$MESS ['FIO'] = 'Ф.И.О.';
|
||||||
|
Loading…
Reference in New Issue
Block a user