2013-10-30 17:01:34 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module Install/Uninstall script
|
2016-09-15 16:42:10 +03:00
|
|
|
* Module name: intaro.retailcrm
|
|
|
|
* Class name: intaro_retailcrm
|
2013-10-30 17:01:34 +04:00
|
|
|
*/
|
|
|
|
global $MESS;
|
2021-09-08 10:05:09 +03:00
|
|
|
|
|
|
|
use Bitrix\Highloadblock\HighloadBlockTable;
|
2022-03-02 15:40:53 +03:00
|
|
|
use Bitrix\Main\Application;
|
|
|
|
use Bitrix\Main\Loader;
|
|
|
|
use Bitrix\Sale\Delivery\Services\Manager;
|
2021-09-08 10:05:09 +03:00
|
|
|
use Bitrix\Sale\EventActions;
|
2022-03-02 15:40:53 +03:00
|
|
|
use Bitrix\Sale\Internals\OrderTable;
|
|
|
|
use Intaro\RetailCrm\Component\ConfigProvider;
|
2023-12-21 17:24:46 +03:00
|
|
|
use Intaro\RetailCrm\Component\Constants;
|
2023-08-22 13:09:20 +03:00
|
|
|
use Intaro\RetailCrm\Component\Installer\InstallerTrait;
|
2023-12-12 16:51:15 +03:00
|
|
|
use Intaro\RetailCrm\Service\CurrencyService;
|
2022-03-02 15:40:53 +03:00
|
|
|
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
|
2021-09-08 10:05:09 +03:00
|
|
|
use RetailCrm\ApiClient;
|
2021-05-31 16:33:02 +03:00
|
|
|
use RetailCrm\Exception\CurlException;
|
2022-03-02 15:40:53 +03:00
|
|
|
use RetailCrm\Http\Client;
|
2023-04-26 17:18:38 +03:00
|
|
|
use RetailCrm\Response\ApiResponse;
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
Loader::IncludeModule('highloadblock');
|
2021-05-31 16:33:02 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
IncludeModuleLangFile(__FILE__);
|
2022-03-02 15:40:53 +03:00
|
|
|
if (class_exists('intaro_retailcrm')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-22 13:09:20 +03:00
|
|
|
include (__DIR__ . '/../lib/component/installer/installertrait.php');
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2018-10-04 16:28:14 +03:00
|
|
|
class intaro_retailcrm extends CModule
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2023-08-22 13:09:20 +03:00
|
|
|
use InstallerTrait;
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
public const V5 = 'v5';
|
2021-05-31 16:33:02 +03:00
|
|
|
public $MODULE_ID = 'intaro.retailcrm';
|
|
|
|
public $OLD_MODULE_ID = 'intaro.intarocrm';
|
|
|
|
public $MODULE_VERSION;
|
|
|
|
public $MODULE_VERSION_DATE;
|
|
|
|
public $MODULE_NAME;
|
|
|
|
public $MODULE_DESCRIPTION;
|
|
|
|
public $PARTNER_NAME;
|
|
|
|
public $PARTNER_URI;
|
|
|
|
public $RETAIL_CRM_API;
|
|
|
|
public $RETAIL_CRM_EXPORT = 'retailcrm';
|
|
|
|
public $CRM_API_HOST_OPTION = 'api_host';
|
|
|
|
public $CRM_API_KEY_OPTION = 'api_key';
|
|
|
|
public $CRM_SITES_LIST = 'sites_list';
|
|
|
|
public $CRM_ORDER_TYPES_ARR = 'order_types_arr';
|
|
|
|
public $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
|
|
|
public $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
|
2022-06-28 17:35:54 +03:00
|
|
|
public $CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
2021-05-31 16:33:02 +03:00
|
|
|
public $CRM_PAYMENT_TYPES = 'pay_types_arr';
|
|
|
|
public $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
2022-03-02 15:40:53 +03:00
|
|
|
public $CRM_PAYMENT = 'payment_arr';
|
2022-06-28 17:35:54 +03:00
|
|
|
public $CRM_INTEGRATION_PAYMENT = 'integration_payment';
|
2021-05-31 16:33:02 +03:00
|
|
|
public $CRM_ORDER_LAST_ID = 'order_last_id';
|
|
|
|
public $CRM_ORDER_PROPS = 'order_props';
|
|
|
|
public $CRM_LEGAL_DETAILS = 'legal_details';
|
|
|
|
public $CRM_CONTRAGENT_TYPE = 'contragent_type';
|
|
|
|
public $CRM_ORDER_DISCHARGE = 'order_discharge';
|
|
|
|
public $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
|
|
|
public $CRM_ORDER_HISTORY = 'order_history';
|
|
|
|
public $CRM_CUSTOMER_HISTORY = 'customer_history';
|
|
|
|
public $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
|
|
|
|
public $CRM_ORDER_NUMBERS = 'order_numbers';
|
|
|
|
public $CRM_CANSEL_ORDER = 'cansel_order';
|
|
|
|
public $CRM_CURRENCY = 'currency';
|
|
|
|
public $CRM_ADDRESS_OPTIONS = 'address_options';
|
|
|
|
public $CRM_INVENTORIES_UPLOAD = 'inventories_upload';
|
|
|
|
public $CRM_STORES = 'stores';
|
|
|
|
public $CRM_SHOPS = 'shops';
|
|
|
|
public $CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories';
|
|
|
|
public $CRM_PRICES_UPLOAD = 'prices_upload';
|
|
|
|
public $CRM_PRICES = 'prices';
|
|
|
|
public $CRM_PRICE_SHOPS = 'price_shops';
|
|
|
|
public $CRM_IBLOCKS_PRICES = 'iblock_prices';
|
|
|
|
public $CRM_COLLECTOR = 'collector';
|
|
|
|
public $CRM_COLL_KEY = 'coll_key';
|
|
|
|
public $CRM_UA = 'ua';
|
|
|
|
public $CRM_UA_KEYS = 'ua_keys';
|
|
|
|
public $CRM_API_VERSION = 'api_version';
|
|
|
|
public $HISTORY_TIME = 'history_time';
|
|
|
|
public $CLIENT_ID = 'client_id';
|
|
|
|
public $PROTOCOL = 'protocol';
|
|
|
|
public $INSTALL_PATH;
|
2024-01-15 12:27:40 +03:00
|
|
|
public $SITES_AVAILABLE = 'sites_available';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2023-03-15 11:55:04 +03:00
|
|
|
public function __construct()
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2022-03-02 15:40:53 +03:00
|
|
|
$arModuleVersion = [];
|
|
|
|
$path = str_replace("\\", '/', __FILE__);
|
|
|
|
$path = substr($path, 0, strlen($path) - strlen('/index.php'));
|
2013-10-30 17:01:34 +04:00
|
|
|
$this->INSTALL_PATH = $path;
|
2022-03-02 15:40:53 +03:00
|
|
|
include($path . '/version.php');
|
|
|
|
$this->MODULE_VERSION = $arModuleVersion['VERSION'];
|
|
|
|
$this->MODULE_VERSION_DATE = $arModuleVersion['VERSION_DATE'];
|
2016-09-15 16:42:10 +03:00
|
|
|
$this->MODULE_NAME = GetMessage('RETAIL_MODULE_NAME');
|
2013-10-30 17:01:34 +04:00
|
|
|
$this->MODULE_DESCRIPTION = GetMessage('MODULE_DESCRIPTION');
|
|
|
|
$this->PARTNER_NAME = GetMessage('MODULE_PARTNER_NAME');
|
|
|
|
$this->PARTNER_URI = GetMessage('MODULE_PARTNER_URI');
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
public function loadDeps()
|
2020-04-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
if (!class_exists('RetailcrmConstants')) {
|
2022-03-02 15:40:53 +03:00
|
|
|
require_once __DIR__ . '/../classes/general/RetailcrmConstants.php';
|
2020-04-24 13:18:18 +03:00
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2020-04-24 13:18:18 +03:00
|
|
|
if (!class_exists('RetailcrmConfigProvider')) {
|
2022-03-02 15:40:53 +03:00
|
|
|
require_once __DIR__ . '/../classes/general/RetailcrmConfigProvider.php';
|
2020-04-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('RetailcrmDependencyLoader')) {
|
2022-03-02 15:40:53 +03:00
|
|
|
require_once __DIR__ . '/../classes/general/RetailcrmDependencyLoader.php';
|
2020-04-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
/**
|
|
|
|
* Functions DoInstall and DoUninstall are
|
|
|
|
* All other functions are optional
|
|
|
|
*/
|
2016-10-04 17:57:39 +03:00
|
|
|
function DoInstall()
|
|
|
|
{
|
2013-10-30 17:01:34 +04:00
|
|
|
global $APPLICATION, $step, $arResult;
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!in_array('curl', get_loaded_extensions(), true)) {
|
|
|
|
$APPLICATION->ThrowException(GetMessage('RETAILCRM_CURL_ERR'));
|
2016-09-15 16:42:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
$infoSale = CModule::CreateModuleObject('sale')->MODULE_VERSION;
|
|
|
|
if (version_compare($infoSale, '16', '<=')) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$APPLICATION->ThrowException(GetMessage('SALE_VERSION_ERR'));
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!Loader::includeModule('sale')) {
|
|
|
|
return false;
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!date_default_timezone_get() && !ini_get('date.timezone')) {
|
|
|
|
$APPLICATION->ThrowException(GetMessage('DATE_TIMEZONE_ERR'));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/traits/baseclienttrait.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/traits/customerstrait.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/traits/customerscorporatetrait.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/traits/loyaltytrait.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/traits/ordertrait.php');
|
2023-04-11 11:57:06 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/traits/carttrait.php');
|
2016-09-15 16:42:10 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/Http/Client.php');
|
2015-03-03 16:37:34 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/Response/ApiResponse.php');
|
2016-09-15 16:42:10 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/RCrmActions.php');
|
|
|
|
include($this->INSTALL_PATH . '/../classes/general/user/RetailCrmUser.php');
|
|
|
|
include($this->INSTALL_PATH . '/../classes/general/events/RetailCrmEvent.php');
|
2022-03-02 15:40:53 +03:00
|
|
|
require_once $this->INSTALL_PATH . '/../classes/general/RetailcrmConfigProvider.php';
|
2021-05-31 16:33:02 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/offerparam.php');
|
2021-09-08 10:05:09 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/settingsservice.php');
|
2021-05-31 16:33:02 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/component/agent.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/selectparams.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/unit.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlcategory.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmldata.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmloffer.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlsetup.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlsetupprops.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlsetuppropscategories.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/icmldirector.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/icmlwriter.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/queryparamsmolder.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/xmlcategorydirector.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/xmlcategoryfactory.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/xmlofferdirector.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/xmlofferbuilder.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/icml/utils/icmlutils.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/catalogrepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/filerepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/hlrepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/measurerepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/siterepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/service/hl.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/orm/catalogiblockinfo.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/orm/iblockcatalog.php');
|
2015-03-03 16:37:34 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/Exception/InvalidJsonException.php');
|
2014-05-06 11:58:29 +04:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/Exception/CurlException.php');
|
2015-03-03 16:37:34 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/RestNormalizer.php');
|
2016-09-15 16:42:10 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/Logger.php');
|
2020-08-26 11:21:56 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/services/RetailCrmService.php');
|
2017-09-04 11:36:04 +03:00
|
|
|
$version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0);
|
2022-03-02 15:40:53 +03:00
|
|
|
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');
|
2023-04-11 11:57:06 +03:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/cart/RetailCrmCart_v5.php');
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$step = (int) $_REQUEST['step'];
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
if (file_exists($this->INSTALL_PATH . '/../classes/general/config/options.xml')) {
|
2018-10-04 16:28:14 +03:00
|
|
|
$options = simplexml_load_file($this->INSTALL_PATH . '/../classes/general/config/options.xml');
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($options->contragents->contragent as $contragent) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$type['NAME'] = $APPLICATION->ConvertCharset((string)$contragent, 'utf-8', SITE_CHARSET);
|
|
|
|
$type['ID'] = (string)$contragent['id'];
|
2015-03-03 16:37:34 +03:00
|
|
|
$arResult['contragentType'][] = $type;
|
|
|
|
unset ($type);
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach($options->fields->field as $field) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$type['NAME'] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET);
|
|
|
|
$type['ID'] = (string)$field['id'];
|
2015-03-03 16:37:34 +03:00
|
|
|
|
2024-03-18 14:00:13 +03:00
|
|
|
if (!$field['group']) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$arResult['orderProps'][] = $type;
|
2016-10-04 17:57:39 +03:00
|
|
|
} else {
|
2022-03-02 15:40:53 +03:00
|
|
|
$groups = explode(',', (string) $field['group']);
|
2018-10-04 16:28:14 +03:00
|
|
|
foreach ($groups as $group) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$type['GROUP'][] = trim($group);
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
|
|
|
$arResult['legalDetails'][] = $type;
|
|
|
|
}
|
|
|
|
unset($type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/abstractmodelproxy.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/orderprops.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/tomodule.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/abstractrepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/orderpropsrepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/persontyperepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/tomodulerepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/orm/tomodule.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/model/bitrix/agreement.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/constants.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/repository/agreementrepository.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/service/orderloyaltydataservice.php');
|
2023-12-12 16:51:15 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/service/currencyservice.php');
|
2022-03-02 15:40:53 +03:00
|
|
|
include($this->INSTALL_PATH . '/../lib/component/factory/clientfactory.php');
|
|
|
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/clientadapter.php');
|
|
|
|
|
|
|
|
$this->CopyFiles();
|
2023-08-22 13:09:20 +03:00
|
|
|
$this->addEvents();
|
2022-03-02 15:40:53 +03:00
|
|
|
$this->addAgreement();
|
2023-08-22 13:09:20 +03:00
|
|
|
$this->addUserFields();
|
2024-01-18 11:48:35 +03:00
|
|
|
$this->createCustomPropertyFile();
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
OrderLoyaltyDataService::createLoyaltyHlBlock();
|
|
|
|
|
|
|
|
$service = new OrderLoyaltyDataService();
|
|
|
|
$service->addCustomersLoyaltyFields();
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($step == 11) {
|
2021-09-08 10:19:29 +03:00
|
|
|
$arResult['arSites'] = RCrmActions::getSitesList();
|
2016-10-04 17:57:39 +03:00
|
|
|
if (count($arResult['arSites']) < 2) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$step = 2;
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
if ($step <= 1) {
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('iblock')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('catalog')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($api_host = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_API_HOST_OPTION, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['API_HOST'] = $api_host;
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($api_key = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_API_KEY_OPTION, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['API_KEY'] = $api_key;
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
} elseif ($step == 11) {
|
2015-03-03 16:37:34 +03:00
|
|
|
//new page
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('iblock')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('catalog')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($arResult['errCode']) && $arResult['errCode']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
$api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
|
|
|
|
$api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
|
|
|
|
|
|
|
|
// form correct url
|
|
|
|
$api_host = parse_url($api_host);
|
2023-12-12 16:51:15 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if ($api_host['scheme'] !== 'https') {
|
2018-10-04 16:28:14 +03:00
|
|
|
$api_host['scheme'] = 'https';
|
2016-10-04 17:57:39 +03:00
|
|
|
}
|
2023-12-12 16:51:15 +03:00
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
$api_host = $api_host['scheme'] . '://' . $api_host['host'];
|
|
|
|
|
|
|
|
if (!$api_host || !$api_key) {
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2022-03-02 15:40:53 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$shopResponse = $this->getReferenceShops($api_host, $api_key);
|
|
|
|
|
|
|
|
if (isset($shopResponse['sitesList'])) {
|
|
|
|
$arResult['sitesList'] = $shopResponse['sitesList'];
|
|
|
|
} elseif (isset($shopResponse['errCode'])) {
|
|
|
|
$arResult['errCode'] = $shopResponse['errCode'];
|
2015-03-03 16:37:34 +03:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($sites_list = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_SITES_LIST, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['SITES_LIST'] = unserialize($sites_list);
|
|
|
|
}
|
2015-03-03 16:37:34 +03:00
|
|
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step11.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2022-03-02 15:40:53 +03:00
|
|
|
} elseif ($step == 2) {
|
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('iblock')) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('catalog')) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($arResult['errCode']) && $arResult['errCode']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2022-03-02 15:40:53 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2021-09-08 10:19:29 +03:00
|
|
|
$arResult['arSites'] = RCrmActions::getSitesList();
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if (count($arResult['arSites']) > 1) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$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);
|
2024-01-15 12:27:40 +03:00
|
|
|
$isEmptySites = true;
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arResult['arSites'] as $site) {
|
2023-12-12 16:51:15 +03:00
|
|
|
$siteCode[$site['LID']] = null;
|
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
if ($_POST['sites-id-' . $site['LID']] && !empty($_POST['sites-id-' . $site['LID']])) {
|
|
|
|
$siteCode[$site['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $site['LID']]));
|
2024-01-15 12:27:40 +03:00
|
|
|
$isEmptySites = false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
|
|
|
}
|
2023-08-30 14:11:04 +03:00
|
|
|
|
2024-01-15 12:27:40 +03:00
|
|
|
if ($isEmptySites) {
|
|
|
|
$arResult['errCode'] = 'ERR_EMPTY_SITES_LIST';
|
|
|
|
}
|
|
|
|
|
2023-08-30 14:11:04 +03:00
|
|
|
$arResult['arCurrencySites'] = RCrmActions::getCurrencySites();
|
|
|
|
$result = $this->getReferenceShops($api_host, $api_key);
|
|
|
|
|
|
|
|
if (isset($result['errCode'])) {
|
|
|
|
$arResult['errCode'] = $result['errCode'];
|
|
|
|
} else {
|
|
|
|
$arResult['sitesList'] = $result['sitesList'];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($arResult['arSites'] as $bitrixSite) {
|
2023-12-12 16:51:15 +03:00
|
|
|
$LID = $bitrixSite['LID'] ?? null;
|
|
|
|
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
2023-08-30 14:11:04 +03:00
|
|
|
|
2024-01-15 12:27:40 +03:00
|
|
|
if (isset($arResult['sitesList'][$siteCode[$LID]])) {
|
|
|
|
$crmCurrency = $arResult['sitesList'][$siteCode[$LID]]['currency'] ?? null;
|
|
|
|
$arResult['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
|
|
|
}
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
if (count($arResult['arSites']) != count($siteCode)) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
if (!empty($arResult['errCode'])) {
|
2015-03-03 16:37:34 +03:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step11.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2021-09-08 10:05:09 +03:00
|
|
|
$this->RETAIL_CRM_API = new ApiClient($api_host, $api_key);
|
2015-03-03 16:37:34 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_SITES_LIST, serialize($siteCode));
|
2017-09-04 11:36:04 +03:00
|
|
|
} else {
|
2015-03-03 16:37:34 +03:00
|
|
|
$api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
|
|
|
|
$api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
|
|
|
|
|
|
|
|
// form correct url
|
|
|
|
$api_host = parse_url($api_host);
|
2022-03-02 15:40:53 +03:00
|
|
|
if ($api_host['scheme'] != 'https') {
|
2016-10-04 17:57:39 +03:00
|
|
|
$api_host['scheme'] = 'https';
|
|
|
|
}
|
2015-03-03 16:37:34 +03:00
|
|
|
$api_host = $api_host['scheme'] . '://' . $api_host['host'];
|
|
|
|
|
|
|
|
if (!$api_host || !$api_key) {
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2017-09-04 11:36:04 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$shopResponse = $this->getReferenceShops($api_host, $api_key);
|
|
|
|
|
|
|
|
if (isset($shopResponse['sitesList'])) {
|
|
|
|
$arResult['sitesList'] = $shopResponse['sitesList'];
|
|
|
|
} elseif (isset($shopResponse['errCode'])) {
|
|
|
|
$arResult['errCode'] = $shopResponse['errCode'];
|
2015-03-03 16:37:34 +03:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2015-03-03 16:37:34 +03:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2021-09-08 10:05:09 +03:00
|
|
|
$this->RETAIL_CRM_API = new ApiClient($api_host, $api_key);
|
2015-03-03 16:37:34 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
|
2022-03-02 15:40:53 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_SITES_LIST, serialize([]));
|
2024-01-15 12:27:40 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
$credentials = $this->RETAIL_CRM_API->getCredentials();
|
|
|
|
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->SITES_AVAILABLE,
|
|
|
|
$credentials->sitesAvailable[0] ?? ''
|
|
|
|
);
|
|
|
|
} catch (ArgumentOutOfRangeException | CurlException $exception) {
|
|
|
|
$arResult['errCode'] = 'ERR_GET_SITE_CRM';
|
|
|
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
|
|
|
try {
|
2024-03-18 14:00:13 +03:00
|
|
|
$credentials = $this->RETAIL_CRM_API->getCredentials()->getResponseBody();
|
|
|
|
$residualRight = array_diff(Constants::REQUIRED_API_SCOPES, $credentials['scopes']);
|
|
|
|
|
|
|
|
if (count($residualRight) !== 0) {
|
|
|
|
throw new \InvalidArgumentException(sprintf(GetMessage('ERR_403'), implode(', ', $residualRight)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['orderTypesList'] = $this->RETAIL_CRM_API->orderTypesList()->orderTypes;
|
|
|
|
$arResult['deliveryTypesList'] = $this->RETAIL_CRM_API->deliveryTypesList()->deliveryTypes;
|
|
|
|
$arResult['deliveryServicesList'] = $this->RETAIL_CRM_API->deliveryServicesList()->deliveryServices;
|
|
|
|
$arResult['paymentTypesList'] = $this->RETAIL_CRM_API->paymentTypesList()->paymentTypes;
|
|
|
|
$arResult['paymentStatusesList'] = $this->RETAIL_CRM_API->paymentStatusesList()->paymentStatuses;
|
|
|
|
$arResult['paymentList'] = $this->RETAIL_CRM_API->statusesList()->statuses;
|
|
|
|
$arResult['paymentGroupList'] = $this->RETAIL_CRM_API->statusGroupsList()->statusGroups;
|
2021-05-31 16:33:02 +03:00
|
|
|
} catch (CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::*List::CurlException',
|
2014-03-22 14:52:17 +04:00
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
2017-12-04 17:44:30 +03:00
|
|
|
} catch (\InvalidArgumentException $e) {
|
2024-03-18 14:00:13 +03:00
|
|
|
$arResult['errCode'] = $e->getMessage();
|
|
|
|
|
2017-12-04 17:44:30 +03:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2014-03-22 14:52:17 +04:00
|
|
|
}
|
2017-12-04 17:44:30 +03:00
|
|
|
|
2023-06-07 14:39:34 +03:00
|
|
|
$this->loadDeps();
|
|
|
|
|
|
|
|
$availableSites = RetailcrmConfigProvider::getSitesList();
|
|
|
|
|
|
|
|
if (!empty($availableSites)) {
|
|
|
|
$availableSites = array_flip($availableSites);
|
|
|
|
} else {
|
|
|
|
$site = RetailcrmConfigProvider::getSitesAvailable();
|
|
|
|
$availableSites[$site] = $site;
|
2016-10-31 17:56:11 +03:00
|
|
|
}
|
2021-04-19 15:38:09 +03:00
|
|
|
|
2023-06-07 14:39:34 +03:00
|
|
|
$arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes(
|
|
|
|
$availableSites,
|
|
|
|
$arResult['deliveryTypesList']
|
|
|
|
);
|
|
|
|
$arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes(
|
|
|
|
$availableSites,
|
|
|
|
$arResult['paymentTypesList']
|
|
|
|
);
|
2021-04-19 15:38:09 +03:00
|
|
|
|
|
|
|
RetailcrmConfigProvider::setIntegrationDelivery(
|
|
|
|
RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList'])
|
|
|
|
);
|
|
|
|
|
|
|
|
RetailcrmConfigProvider::setIntegrationPaymentTypes(
|
|
|
|
RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList'])
|
|
|
|
);
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix personTypes
|
|
|
|
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix deliveryList
|
|
|
|
$arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix paymentList
|
|
|
|
$arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList();
|
2014-01-23 17:50:58 +04:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix statusesList --statuses
|
|
|
|
$arResult['bitrixStatusesList'] = RCrmActions::StatusesList();
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($order_types = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_ORDER_TYPES_ARR, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['ORDER_TYPES'] = array_flip(unserialize($order_types));
|
2014-01-23 17:50:58 +04:00
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($delivery_types = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['DELIVERY_TYPES'] = array_flip(unserialize($delivery_types));
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($payment_types = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_PAYMENT_TYPES, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['PAYMENT_TYPES'] = array_flip(unserialize($payment_types));
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($payment_statuses = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_PAYMENT_STATUSES, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['PAYMENT_STATUSES'] = array_flip(unserialize($payment_statuses));
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($payment = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_PAYMENT, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['PAYMENT'] = array_flip(unserialize($payment));
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2022-03-02 15:40:53 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step2.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2017-09-04 15:51:40 +03:00
|
|
|
} elseif ($step == 3) {
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2016-10-04 17:57:39 +03:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_POST['back']) && $_POST['back']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2022-03-02 15:40:53 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// api load
|
|
|
|
$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);
|
2021-09-08 10:05:09 +03:00
|
|
|
$this->RETAIL_CRM_API = new ApiClient($api_host, $api_key);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2023-12-21 17:24:46 +03:00
|
|
|
$useCrmOrderMethods = htmlspecialchars(trim($_POST['use_crm_order_methods'])) === 'Y' ? 'Y' : 'N';
|
|
|
|
$crmOrderMethod = [];
|
|
|
|
|
|
|
|
if ($useCrmOrderMethods === 'Y') {
|
|
|
|
$crmOrderMethod = $_POST['crm_order_methods'];
|
|
|
|
}
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
Constants::USE_CRM_ORDER_METHODS,
|
|
|
|
$useCrmOrderMethods
|
|
|
|
);
|
|
|
|
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
Constants::CRM_ORDER_METHODS,
|
|
|
|
serialize(RCrmActions::clearArr(is_array($crmOrderMethod) ? $crmOrderMethod : []))
|
|
|
|
);
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix orderTypesList
|
2021-09-08 10:19:29 +03:00
|
|
|
$arResult['arSites'] = RCrmActions::getSitesList();
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$orderTypesArr = [];
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arResult['bitrixOrderTypesList'] as $orderType) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']]));
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//bitrix deliveryTypesList
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList();
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2017-09-04 15:51:40 +03:00
|
|
|
if (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'false') {
|
2022-03-02 15:40:53 +03:00
|
|
|
$deliveryTypesArr = [];
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arResult['bitrixDeliveryTypesList'] as $delivery) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$deliveryTypesArr[$delivery['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $delivery['ID']]));
|
2014-01-23 17:50:58 +04:00
|
|
|
}
|
2017-09-04 15:51:40 +03:00
|
|
|
} elseif (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'true') {
|
2014-01-23 17:50:58 +04:00
|
|
|
// send to intaro crm and save delivery types!
|
2022-03-02 15:40:53 +03:00
|
|
|
$arDeliveryServiceAll = Manager::getActiveList();
|
2016-10-06 17:34:35 +03:00
|
|
|
foreach ($arResult['bitrixDeliveryTypesList'] as $deliveryType) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$load = true;
|
|
|
|
try {
|
2022-03-02 15:40:53 +03:00
|
|
|
$this->RETAIL_CRM_API->deliveryTypesEdit(RCrmActions::clearArr([
|
|
|
|
'code' => $deliveryType['ID'],
|
|
|
|
'name' => RCrmActions::toJSON($deliveryType['NAME']),
|
|
|
|
'defaultCost' => $deliveryType['CONFIG']['MAIN']['PRICE'],
|
|
|
|
'description' => RCrmActions::toJSON($deliveryType['DESCRIPTION']),
|
|
|
|
'paymentTypes' => '',
|
|
|
|
]));
|
2021-05-31 16:33:02 +03:00
|
|
|
} catch (CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$load = false;
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.crm/install/index.php', 'RetailCrm\ApiClient::deliveryTypeEdit::CurlException',
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($load) {
|
2016-10-06 17:34:35 +03:00
|
|
|
$deliveryTypesArr[$deliveryType['ID']] = $deliveryType['ID'];
|
|
|
|
foreach ($arDeliveryServiceAll as $deliveryService) {
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] == $deliveryType['ID']) {
|
2022-06-28 17:35:54 +03:00
|
|
|
try {
|
|
|
|
$this->RETAIL_CRM_API->deliveryServicesEdit(RCrmActions::clearArr([
|
|
|
|
'code' => 'bitrix-' . $deliveryService['ID'],
|
|
|
|
'name' => RCrmActions::toJSON($deliveryService['NAME']),
|
|
|
|
'deliveryType' => $deliveryType['ID'],
|
|
|
|
]));
|
|
|
|
} catch (CurlException $e) {
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.crm/install/index.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException',
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
}
|
2014-01-23 17:50:58 +04:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2014-01-23 17:50:58 +04:00
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//bitrix paymentTypesList
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList();
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$paymentTypesArr = [];
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arResult['bitrixPaymentTypesList'] as $payment) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$paymentTypesArr[$payment['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $payment['ID']]));
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix statusesList
|
|
|
|
$arResult['bitrixStatusesList'] = RCrmActions::StatusesList();
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$paymentStatusesArr = [];
|
|
|
|
$canselOrderArr = [];
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arResult['bitrixStatusesList'] as $status) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$paymentStatusesArr[$status['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $status['ID']]));
|
2016-10-04 17:57:39 +03:00
|
|
|
if (trim($_POST['order-cansel-' . $status['ID']]) == 'Y') {
|
2016-09-15 16:42:10 +03:00
|
|
|
$canselOrderArr[] = $status['ID'];
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//form payment ids arr
|
2022-03-02 15:40:53 +03:00
|
|
|
$paymentArr = [];
|
2013-10-30 17:01:34 +04:00
|
|
|
$paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
|
|
|
|
$paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//new page
|
2018-10-04 16:28:14 +03:00
|
|
|
//form orderProps
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['arProp'] = RCrmActions::OrderPropsList();
|
2024-01-09 10:44:17 +03:00
|
|
|
$arResult['locationProp'] = RCrmActions::getLocationProps();
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$request = Application::getInstance()->getContext()->getRequest();
|
2018-11-02 16:51:13 +03:00
|
|
|
|
|
|
|
if ($request->isHttps() === true) {
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->PROTOCOL, 'https://');
|
|
|
|
} else {
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->PROTOCOL, 'http://');
|
|
|
|
}
|
|
|
|
|
2023-03-15 11:55:04 +03:00
|
|
|
// Set order types
|
|
|
|
if (!empty($orderTypesArr)) {
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_ORDER_TYPES_ARR,
|
|
|
|
serialize(RCrmActions::clearArr($orderTypesArr)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set delivery types
|
|
|
|
if (!empty($deliveryTypesArr)) {
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_DELIVERY_TYPES_ARR,
|
|
|
|
serialize(RCrmActions::clearArr($deliveryTypesArr)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set payment types
|
|
|
|
if (!empty($paymentTypesArr)) {
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_PAYMENT_TYPES,
|
|
|
|
serialize(RCrmActions::clearArr($paymentTypesArr)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set payment statuses
|
|
|
|
if (!empty($paymentStatusesArr)) {
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_PAYMENT_STATUSES,
|
|
|
|
serialize(RCrmActions::clearArr($paymentStatusesArr)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set payments
|
|
|
|
if (!empty($paymentArr)) {
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_PAYMENT,
|
|
|
|
serialize(RCrmActions::clearArr($paymentArr)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
|
2013-11-28 15:08:07 +04:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE, 1);
|
2022-03-02 15:40:53 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS, serialize([]));
|
2023-03-15 11:55:04 +03:00
|
|
|
|
|
|
|
// Set cansel order
|
|
|
|
if (!empty($canselOrderArr)) {
|
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_CANSEL_ORDER,
|
|
|
|
serialize(RCrmActions::clearArr($canselOrderArr)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($orderProps = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_ORDER_PROPS, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['ORDER_PROPS'] = unserialize($orderProps);
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($legalDetails = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_LEGAL_DETAILS, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['LEGAL_DETAILS'] = unserialize($legalDetails);
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($contragentType = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_CONTRAGENT_TYPE, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$arResult['CONTRAGENT_TYPES'] = unserialize($contragentType);
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-03-22 16:11:04 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step3.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2017-09-04 15:51:40 +03:00
|
|
|
} elseif ($step == 4) {
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2016-10-04 17:57:39 +03:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
2014-01-23 17:50:58 +04:00
|
|
|
if (isset($_POST['back']) && $_POST['back']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step2.php'
|
2014-01-23 17:50:58 +04:00
|
|
|
);
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//order upload
|
2018-03-22 16:11:04 +03:00
|
|
|
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
|
2022-03-02 15:40:53 +03:00
|
|
|
&& (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
|
2018-03-22 16:11:04 +03:00
|
|
|
&& isset($_POST['ajax'])
|
|
|
|
&& $_POST['ajax'] == 1
|
|
|
|
) {
|
2016-09-16 11:46:44 +03:00
|
|
|
$historyTime = Date('');
|
2022-03-02 15:40:53 +03:00
|
|
|
$this->loadDeps();
|
2016-09-15 16:42:10 +03:00
|
|
|
RetailCrmOrder::uploadOrders(); // each 50
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
$lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
|
2022-03-02 15:40:53 +03:00
|
|
|
$countLeft = (int) OrderTable::getCount(['>ID' => $lastUpOrderId]);
|
|
|
|
$countAll = (int) OrderTable::getCount();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if (!isset($_POST['finish'])) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$finish = 0;
|
2016-10-04 17:57:39 +03:00
|
|
|
} else {
|
2022-03-02 15:40:53 +03:00
|
|
|
$finish = (int) $_POST['finish'];
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2020-09-02 14:37:16 +03:00
|
|
|
|
|
|
|
if (!$countAll) {
|
|
|
|
$percent = 100;
|
|
|
|
} else {
|
|
|
|
$percent = round(100 - ($countLeft * 100 / $countAll), 1);
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if (!$countLeft) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$finish = 1;
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$APPLICATION->RestartBuffer();
|
|
|
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
2022-03-02 15:40:53 +03:00
|
|
|
die(json_encode(['finish' => $finish, 'percent' => $percent]));
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
if (isset($_POST['back']) && $_POST['back']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-03-22 16:11:04 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step2.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
//bitrix orderTypesList
|
2021-09-08 10:19:29 +03:00
|
|
|
$orderTypesList = RCrmActions::OrderTypesList(RCrmActions::getSitesList());
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$orderTypesArr = [];
|
2024-01-09 10:44:17 +03:00
|
|
|
$addressDetailOptions = [];
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($orderTypesList as $orderType) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']]));
|
2024-01-09 10:44:17 +03:00
|
|
|
$addressDetailOptions[$orderType['ID']] = $_POST['address-detail-' . $orderType['ID']];
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$orderPropsArr = [];
|
2013-10-30 17:01:34 +04:00
|
|
|
foreach ($orderTypesList as $orderType) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$propsCount = 0;
|
|
|
|
$_orderPropsArr = [];
|
2013-10-30 17:01:34 +04:00
|
|
|
foreach ($arResult['orderProps'] as $orderProp) {
|
2016-10-04 17:57:39 +03:00
|
|
|
if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4){
|
2013-10-30 17:01:34 +04:00
|
|
|
break;
|
2016-10-04 17:57:39 +03:00
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
$_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']]));
|
|
|
|
$propsCount++;
|
|
|
|
}
|
|
|
|
$orderPropsArr[$orderType['ID']] = $_orderPropsArr;
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
//legal details props
|
2022-03-02 15:40:53 +03:00
|
|
|
$legalDetailsArr = [];
|
2015-03-03 16:37:34 +03:00
|
|
|
foreach ($orderTypesList as $orderType) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$_legalDetailsArr = [];
|
2015-03-03 16:37:34 +03:00
|
|
|
foreach ($arResult['legalDetails'] as $legalDetails) {
|
|
|
|
$_legalDetailsArr[$legalDetails['ID']] = htmlspecialchars(trim($_POST['legal-detail-' . $legalDetails['ID'] . '-' . $orderType['ID']]));
|
|
|
|
}
|
|
|
|
$legalDetailsArr[$orderType['ID']] = $_legalDetailsArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//contragents type list
|
2022-03-02 15:40:53 +03:00
|
|
|
$contragentTypeArr = [];
|
2015-03-03 16:37:34 +03:00
|
|
|
foreach ($orderTypesList as $orderType) {
|
|
|
|
$contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
|
|
|
|
}
|
|
|
|
|
2024-01-09 10:44:17 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ADDRESS_OPTIONS, serialize($addressDetailOptions));
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr)));
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr)));
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-03-22 16:11:04 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step4.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
|
|
|
|
2017-09-04 15:51:40 +03:00
|
|
|
} elseif ($step == 5) {
|
2018-03-22 16:11:04 +03:00
|
|
|
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
|
2022-03-02 15:40:53 +03:00
|
|
|
&& (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
|
2018-03-22 16:11:04 +03:00
|
|
|
&& isset($_POST['ajax'])
|
|
|
|
&& $_POST['ajax'] == 1
|
|
|
|
) {
|
|
|
|
CModule::IncludeModule('highloadblock');
|
2022-03-02 15:40:53 +03:00
|
|
|
$rsData = HighloadBlockTable::getList(['filter' => ['TABLE_NAME' => $_POST['table']]]);
|
|
|
|
$hlblockArr = $rsData->Fetch();
|
|
|
|
$hlblock = HighloadBlockTable::getById($hlblockArr['ID'])->fetch();
|
|
|
|
$entity = HighloadBlockTable::compileEntity($hlblock);
|
|
|
|
$hbFields = $entity->getFields();
|
|
|
|
$hlblockList['table'] = $hlblockArr['TABLE_NAME'];
|
2018-03-22 16:11:04 +03:00
|
|
|
|
|
|
|
foreach ($hbFields as $hbFieldCode => $hbField) {
|
|
|
|
$hlblockList['fields'][] = $hbFieldCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
$APPLICATION->RestartBuffer();
|
|
|
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
|
|
|
die(json_encode($hlblockList));
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('iblock')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('catalog')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2017-09-05 13:52:49 +03:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
$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);
|
2021-09-08 10:05:09 +03:00
|
|
|
$api = new ApiClient($api_host, $api_key);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$customerH = $this->historyLoad($api, 'customersHistory');
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CUSTOMER_HISTORY, $customerH);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
//new data
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($historyDate = COption::GetOptionString($this->OLD_MODULE_ID, 'order_history_date', 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
try {
|
2022-03-02 15:40:53 +03:00
|
|
|
$history = $api->ordersHistory(['startDate' => $historyDate]);
|
2021-05-31 16:33:02 +03:00
|
|
|
} catch (CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\RestApi::ordersHistory::CurlException',
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\RestApi::ordersHistory::InvalidArgumentException',
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if (isset($history['history'])) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$hIs = (int) $history['history'][0]['id'] - 1;
|
2016-09-15 16:42:10 +03:00
|
|
|
$orderH = $hIs;
|
2016-10-04 17:57:39 +03:00
|
|
|
} else {
|
2022-03-02 15:40:53 +03:00
|
|
|
$orderH = $this->historyLoad($api, 'ordersHistory');
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
} else {
|
2022-03-02 15:40:53 +03:00
|
|
|
$orderH = $this->historyLoad($api, 'ordersHistory');
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2017-09-04 11:36:04 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY, $orderH);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($orderLastId = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_ORDER_LAST_ID, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, $orderLastId);
|
2017-09-04 11:36:04 +03:00
|
|
|
} else {
|
2022-03-02 15:40:53 +03:00
|
|
|
$dbOrder = OrderTable::GetList([
|
|
|
|
'order' => ['ID' => 'DESC'],
|
|
|
|
'limit' => 1,
|
|
|
|
'select' => ['ID'],
|
|
|
|
]);
|
2017-09-04 11:36:04 +03:00
|
|
|
$arOrder = $dbOrder->fetch();
|
|
|
|
if (!empty($arOrder['ID'])) {
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, $arOrder['ID']);
|
|
|
|
} else {
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
if ($orderFailedIds = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_ORDER_FAILED_IDS, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS, $orderFailedIds);
|
|
|
|
}
|
2014-06-20 16:03:46 +04:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$arResult['PRICE_TYPES'] = [];
|
2014-06-20 16:03:46 +04:00
|
|
|
|
|
|
|
$dbPriceType = CCatalogGroup::GetList(
|
2022-03-02 15:40:53 +03:00
|
|
|
['SORT' => 'ASC'], [], [], [], ['ID', 'NAME', 'BASE']
|
2014-06-20 16:03:46 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
while ($arPriceType = $dbPriceType->Fetch()) {
|
|
|
|
$arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:18:18 +03:00
|
|
|
if (isset($_POST['back']) && $_POST['back']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step3.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-03-22 16:11:04 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step5.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2017-09-04 15:51:40 +03:00
|
|
|
} elseif ($step == 6) {
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('iblock')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('catalog')) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
if (!CModule::IncludeModule('sale')) {
|
2017-09-05 13:52:49 +03:00
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
if (isset($arResult['errCode']) && $arResult['errCode']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-03-22 16:11:04 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step5.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_POST['back']) && $_POST['back']) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2020-04-24 13:18:18 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step4.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
$hlblockModule = false;
|
2023-06-01 13:33:41 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if (CModule::IncludeModule('highloadblock')) {
|
|
|
|
$hlblockModule = true;
|
2022-03-02 15:40:53 +03:00
|
|
|
$hlblockList = [];
|
2021-09-08 10:05:09 +03:00
|
|
|
$hlblockListDb = HighloadBlockTable::getList();
|
2018-05-23 12:19:59 +03:00
|
|
|
|
|
|
|
while ($hlblockArr = $hlblockListDb->Fetch()) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$hlblock = HighloadBlockTable::getById($hlblockArr['ID'])->fetch();
|
2021-09-08 10:05:09 +03:00
|
|
|
$entity = HighloadBlockTable::compileEntity($hlblock);
|
2018-05-23 12:19:59 +03:00
|
|
|
$hbFields = $entity->getFields();
|
2022-03-02 15:40:53 +03:00
|
|
|
$hlblockList[$hlblockArr['TABLE_NAME']]['LABEL'] = $hlblockArr['NAME'];
|
2018-05-23 12:19:59 +03:00
|
|
|
|
|
|
|
foreach ($hbFields as $hbFieldCode => $hbField) {
|
2022-03-02 15:40:53 +03:00
|
|
|
$hlblockList[$hlblockArr['TABLE_NAME']]['FIELDS'][] = $hbFieldCode;
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$iblockProperties = [
|
|
|
|
'article' => 'article',
|
|
|
|
'manufacturer' => 'manufacturer',
|
|
|
|
'color' => 'color',
|
|
|
|
'weight' => 'weight',
|
|
|
|
'size' => 'size',
|
|
|
|
'length' => 'length',
|
|
|
|
'width' => 'width',
|
|
|
|
'height' => 'height',
|
|
|
|
'picture' => 'picture',
|
|
|
|
];
|
|
|
|
|
|
|
|
$propertiesSKU = [];
|
2021-09-08 10:05:09 +03:00
|
|
|
$propertiesUnitSKU = [];
|
2022-03-02 15:40:53 +03:00
|
|
|
$propertiesHbSKU = [];
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
foreach ($iblockProperties as $prop) {
|
2021-09-08 10:05:09 +03:00
|
|
|
foreach ($_POST['iblockPropertySku'. '_' . $prop] as $iblock => $val) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$propertiesSKU[$iblock][$prop] = $val;
|
|
|
|
}
|
2021-09-08 10:05:09 +03:00
|
|
|
foreach ($_POST['iblockPropertyUnitSku'. '_' . $prop] as $iblock => $val) {
|
2014-01-23 16:55:04 +04:00
|
|
|
$propertiesUnitSKU[$iblock][$prop] = $val;
|
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if ($hlblockModule === true && $prop !== 'picture') {
|
2018-05-23 12:19:59 +03:00
|
|
|
foreach ($hlblockList as $tableName => $hb) {
|
|
|
|
foreach ($_POST['highloadblock' . $tableName . '_' . $prop] as $iblock => $val) {
|
|
|
|
$propertiesHbSKU[$tableName][$iblock][$prop] = $val;
|
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
}
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2021-09-08 10:05:09 +03:00
|
|
|
$propertiesProduct = [];
|
|
|
|
$propertiesUnitProduct = [];
|
|
|
|
$propertiesHbProduct = [];
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
foreach ($iblockProperties as $prop) {
|
2021-09-08 10:05:09 +03:00
|
|
|
foreach ($_POST['iblockPropertyProduct'. '_' . $prop] as $iblock => $val) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$propertiesProduct[$iblock][$prop] = $val;
|
|
|
|
}
|
2021-09-08 10:05:09 +03:00
|
|
|
foreach ($_POST['iblockPropertyUnitProduct'. '_' . $prop] as $iblock => $val) {
|
2014-01-23 16:55:04 +04:00
|
|
|
$propertiesUnitProduct[$iblock][$prop] = $val;
|
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
if ($hlblockModule === true && $prop !== 'picture') {
|
2018-05-23 12:19:59 +03:00
|
|
|
foreach ($hlblockList as $tableName => $hb) {
|
|
|
|
foreach ($_POST['highloadblock_product' . $tableName . '_' . $prop] as $iblock => $val) {
|
|
|
|
$propertiesHbProduct[$tableName][$iblock][$prop] = $val;
|
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
}
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
$iblocks = $_POST['iblockExport'] ?? null;
|
|
|
|
$filename = $_POST['SETUP_FILE_NAME'] ?? null;
|
|
|
|
$maxOffers = $_POST['maxOffersValue'] ?? null;
|
|
|
|
$profileName = $_POST['SETUP_PROFILE_NAME'] ?? null;
|
|
|
|
$loadPurchasePrice = $_POST['loadPurchasePrice'] ?? null;
|
|
|
|
$loadInactiveProduct = $_POST['loadNonActivity'] ?? null;
|
2018-12-26 11:41:06 +03:00
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
if ($iblocks === null) {
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_IBLOCK';
|
2016-10-04 17:57:39 +03:00
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
if ($profileName === null) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_PROFILE';
|
2016-10-04 17:57:39 +03:00
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
if ($filename === null) {
|
2013-10-30 17:01:34 +04:00
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_FILE';
|
2016-10-04 17:57:39 +03:00
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
if (isset($arResult['errCode']) && $arResult['errCode']) {
|
2021-09-08 10:05:09 +03:00
|
|
|
$arOldValues = [
|
|
|
|
'iblockExport' => $iblocks,
|
|
|
|
'iblockPropertySku' => $propertiesSKU,
|
|
|
|
'iblockPropertyUnitSku' => $propertiesUnitSKU,
|
|
|
|
'iblockPropertyProduct' => $propertiesProduct,
|
|
|
|
'iblockPropertyUnitProduct' => $propertiesUnitProduct,
|
2013-10-30 17:01:34 +04:00
|
|
|
'SETUP_FILE_NAME' => $filename,
|
2018-12-26 11:41:06 +03:00
|
|
|
'SETUP_PROFILE_NAME' => $profileName,
|
2021-09-08 10:05:09 +03:00
|
|
|
'maxOffersValue' => $maxOffers,
|
2023-06-01 13:33:41 +03:00
|
|
|
'loadPurchasePrice' => $loadPurchasePrice,
|
|
|
|
'loadNonActivity' => $loadInactiveProduct,
|
2021-09-08 10:05:09 +03:00
|
|
|
];
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
global $oldValues;
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$oldValues = $arOldValues;
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step5.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return false;
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RegisterModule($this->MODULE_ID);
|
2022-03-02 15:40:53 +03:00
|
|
|
RegisterModuleDependences('sale', 'OnOrderUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'onUpdateOrder');
|
|
|
|
RegisterModuleDependences('main', 'OnAfterUserUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserUpdate');
|
|
|
|
RegisterModuleDependences('sale', 'OnSaleOrderDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'orderDelete');
|
|
|
|
RegisterModuleDependences('sale', 'OnSalePaymentEntitySaved', $this->MODULE_ID, 'RetailCrmEvent', 'paymentSave');
|
|
|
|
RegisterModuleDependences('sale', 'OnSalePaymentEntityDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'paymentDelete');
|
2023-08-22 13:09:20 +03:00
|
|
|
RegisterModuleDependences('main', 'OnAfterUserRegister', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserRegister');
|
|
|
|
RegisterModuleDependences('main', 'OnAfterUserAdd', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserAdd');
|
|
|
|
|
2017-10-24 11:41:11 +03:00
|
|
|
|
2018-10-04 16:28:14 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types'])));
|
2017-09-04 11:36:04 +03:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_INVENTORIES_UPLOAD, 'N');
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PRICES_UPLOAD, 'N');
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_COLLECTOR, 'N');
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_UA, 'N');
|
2014-06-20 16:03:46 +04:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
//agent
|
|
|
|
$dateAgent = new DateTime();
|
|
|
|
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
|
|
|
|
$dateAgent->add($intAgent);
|
|
|
|
|
|
|
|
CAgent::AddAgent(
|
2023-06-22 15:46:25 +03:00
|
|
|
'RCrmActions::orderAgent();',
|
|
|
|
$this->MODULE_ID,
|
|
|
|
'N',
|
2023-10-24 12:53:02 +03:00
|
|
|
600, // interval - 10 min
|
2018-05-23 12:19:59 +03:00
|
|
|
$dateAgent->format('d.m.Y H:i:s'), // date of first check
|
2022-03-02 15:40:53 +03:00
|
|
|
'Y', // agent is active
|
2018-05-23 12:19:59 +03:00
|
|
|
$dateAgent->format('d.m.Y H:i:s'), // date of first start
|
|
|
|
30
|
|
|
|
);
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$this->CopyFiles();
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2019-01-16 10:28:11 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if (
|
2022-03-02 15:40:53 +03:00
|
|
|
file_exists($_SERVER['DOCUMENT_ROOT']
|
|
|
|
. '/bitrix/php_interface/include/catalog_export/'
|
|
|
|
. $this->RETAIL_CRM_EXPORT
|
|
|
|
. '_run.php')
|
2021-05-31 16:33:02 +03:00
|
|
|
) {
|
|
|
|
$dbProfile = CCatalogExport::GetList([], ['FILE_NAME' => $this->RETAIL_CRM_EXPORT]);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if ($dbProfile instanceof CDBResult) {
|
|
|
|
$this->removeExportProfiles($dbProfile);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
2021-05-31 16:33:02 +03:00
|
|
|
}
|
2021-09-08 10:05:09 +03:00
|
|
|
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$setupVars = $this->getProfileSetupVars(
|
|
|
|
$iblocks,
|
2021-09-08 10:05:09 +03:00
|
|
|
[
|
|
|
|
'iblockPropertySku' => $propertiesSKU,
|
|
|
|
'iblockPropertyUnitSku' => $propertiesUnitSKU,
|
|
|
|
'iblockPropertyProduct' => $propertiesProduct,
|
|
|
|
'iblockPropertyUnitProduct' => $propertiesUnitProduct,
|
|
|
|
],
|
2021-05-31 16:33:02 +03:00
|
|
|
$propertiesHbSKU,
|
|
|
|
$propertiesHbProduct,
|
|
|
|
$filename,
|
2023-06-01 13:33:41 +03:00
|
|
|
$maxOffers,
|
|
|
|
$loadPurchasePrice,
|
|
|
|
$loadInactiveProduct
|
2021-05-31 16:33:02 +03:00
|
|
|
);
|
2023-06-01 13:33:41 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$profileId = CCatalogExport::Add([
|
2022-03-02 15:40:53 +03:00
|
|
|
'LAST_USE' => false,
|
|
|
|
'FILE_NAME' => $this->RETAIL_CRM_EXPORT,
|
|
|
|
'NAME' => $profileName,
|
|
|
|
'DEFAULT_PROFILE' => 'N',
|
|
|
|
'IN_MENU' => 'N',
|
|
|
|
'IN_AGENT' => 'N',
|
|
|
|
'IN_CRON' => 'N',
|
|
|
|
'NEED_EDIT' => 'N',
|
|
|
|
'SETUP_VARS' => $setupVars,
|
2021-05-31 16:33:02 +03:00
|
|
|
]);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if ((int) $profileId <= 0) {
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
return false;
|
2021-05-31 16:33:02 +03:00
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
COption::SetOptionString(
|
|
|
|
$this->MODULE_ID,
|
|
|
|
$this->CRM_CATALOG_BASE_PRICE . '_' . $profileId,
|
|
|
|
htmlspecialchars(trim($_POST['price-types']))
|
|
|
|
);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$agentId = null;
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2022-12-07 11:23:57 +03:00
|
|
|
if (isset($_POST['NEED_CATALOG_AGENT'])) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$agentId = CAgent::AddAgent(
|
|
|
|
'CCatalogExport::PreGenerateExport(' . $profileId . ');',
|
|
|
|
'catalog',
|
2023-06-09 13:34:02 +03:00
|
|
|
'N'
|
2018-03-22 16:11:04 +03:00
|
|
|
);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
CCatalogExport::Update($profileId, [
|
2022-03-02 15:40:53 +03:00
|
|
|
'IN_AGENT' => 'Y',
|
2021-05-31 16:33:02 +03:00
|
|
|
]);
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
if (isset($_POST['LOAD_NOW']) && $agentId === null) {
|
|
|
|
CCatalogExport::PreGenerateExport($profileId);
|
2021-05-31 16:33:02 +03:00
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$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);
|
2021-09-08 10:05:09 +03:00
|
|
|
$this->RETAIL_CRM_API = new ApiClient($api_host, $api_key);
|
2018-08-31 11:18:42 +03:00
|
|
|
|
2023-10-24 12:53:02 +03:00
|
|
|
RCrmActions::sendConfiguration($this->RETAIL_CRM_API);
|
2014-01-28 17:44:21 +04:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-05-23 12:19:59 +03:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step6.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
public function DoUninstall()
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2013-10-30 17:01:34 +04:00
|
|
|
global $APPLICATION;
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$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);
|
2018-08-31 11:18:42 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/Http/Client.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/Response/ApiResponse.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/Exception/InvalidJsonException.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/Exception/CurlException.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/RCrmActions.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/Logger.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/ApiClient_v5.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v5.php');
|
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v5.php');
|
2022-06-28 17:35:54 +03:00
|
|
|
require_once($this->INSTALL_PATH . '/../lib/component/constants.php');
|
2023-04-11 11:57:06 +03:00
|
|
|
require_once($this->INSTALL_PATH . '/../classes/general/cart/RetailCrmCart_v5.php');
|
2023-10-24 12:53:02 +03:00
|
|
|
|
|
|
|
RCrmActions::sendConfiguration(new ApiClient($api_host, $api_key), false);
|
2018-08-31 11:18:42 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
CAgent::RemoveAgent('RCrmActions::orderAgent();', $this->MODULE_ID);
|
|
|
|
CAgent::RemoveAgent('RetailCrmInventories::inventoriesUpload();', $this->MODULE_ID);
|
|
|
|
CAgent::RemoveAgent('RetailCrmPrices::pricesUpload();', $this->MODULE_ID);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR);
|
2022-06-28 17:35:54 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_INTEGRATION_DELIVERY);
|
2013-10-30 17:01:34 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_TYPES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT);
|
2022-06-28 17:35:54 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_INTEGRATION_PAYMENT);
|
2013-10-30 17:01:34 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_PROPS);
|
2022-06-28 17:35:54 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR);
|
2015-03-03 16:37:34 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_LEGAL_DETAILS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_SITES_LIST);
|
2013-10-30 17:01:34 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS);
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CUSTOMER_HISTORY);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_HISTORY);
|
2014-06-20 16:03:46 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE);
|
2017-12-04 17:44:30 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CURRENCY);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ADDRESS_OPTIONS);
|
2016-09-15 16:42:10 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_NUMBERS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CANSEL_ORDER);
|
2017-09-04 11:36:04 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_INVENTORIES_UPLOAD);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_STORES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_SHOPS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_IBLOCKS_INVENTORIES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PRICES_UPLOAD);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PRICES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PRICE_SHOPS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_IBLOCKS_PRICES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_COLLECTOR);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_COLL_KEY);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_UA);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_UA_KEYS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_VERSION);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->HISTORY_TIME);
|
2018-08-31 11:18:42 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID);
|
2018-11-02 16:51:13 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->PROTOCOL);
|
2023-12-21 17:24:46 +03:00
|
|
|
COption::RemoveOption($this->MODULE_ID, Constants::MATCHED_CUSTOM_PROPS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, Constants::MATCHED_CUSTOM_USER_FIELDS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, Constants::CRM_ORDER_METHODS);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, Constants::USE_CRM_ORDER_METHODS);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2018-10-31 16:25:53 +03:00
|
|
|
if (CModule::IncludeModule('sale')) {
|
|
|
|
UnRegisterModuleDependences(
|
2022-03-02 15:40:53 +03:00
|
|
|
'sale',
|
2021-09-08 10:05:09 +03:00
|
|
|
EventActions::EVENT_ON_ORDER_SAVED,
|
2018-11-02 12:27:29 +03:00
|
|
|
$this->MODULE_ID,
|
2022-03-02 15:40:53 +03:00
|
|
|
'RetailCrmEvent',
|
|
|
|
'orderSave'
|
2018-11-02 12:27:29 +03:00
|
|
|
);
|
2018-10-31 16:25:53 +03:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
UnRegisterModuleDependences('sale', 'OnOrderUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'onUpdateOrder');
|
|
|
|
UnRegisterModuleDependences('main', 'OnAfterUserUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserUpdate');
|
|
|
|
UnRegisterModuleDependences('sale', 'OnSaleOrderDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'orderDelete');
|
|
|
|
UnRegisterModuleDependences('main', 'OnBeforeProlog', $this->MODULE_ID, 'RetailCrmCollector', 'add');
|
|
|
|
UnRegisterModuleDependences('main', 'OnBeforeProlog', $this->MODULE_ID, 'RetailCrmUa', 'add');
|
|
|
|
UnRegisterModuleDependences('sale', 'OnSalePaymentEntitySaved', $this->MODULE_ID, 'RetailCrmEvent', 'paymentSave');
|
|
|
|
UnRegisterModuleDependences('sale', 'OnSalePaymentEntityDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'paymentDelete');
|
2023-08-22 13:09:20 +03:00
|
|
|
UnRegisterModuleDependences('main', 'OnAfterUserRegister', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserRegister');
|
|
|
|
UnRegisterModuleDependences('main', 'OnAfterUserAdd', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserAdd');
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if (
|
|
|
|
CModule::IncludeModule('catalog')
|
|
|
|
&& file_exists($_SERVER['DOCUMENT_ROOT']
|
|
|
|
. '/bitrix/php_interface/include/catalog_export/'
|
|
|
|
. $this->RETAIL_CRM_EXPORT
|
|
|
|
. '_run.php')
|
|
|
|
) {
|
|
|
|
$dbProfile = CCatalogExport::GetList([], ['FILE_NAME' => $this->RETAIL_CRM_EXPORT]);
|
|
|
|
|
|
|
|
if ($dbProfile instanceof CDBResult) {
|
|
|
|
$this->removeExportProfiles($dbProfile);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
$this->deleteFiles();
|
|
|
|
$this->deleteLPEvents();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
UnRegisterModule($this->MODULE_ID);
|
|
|
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2018-08-31 11:18:42 +03:00
|
|
|
GetMessage('MODULE_UNINSTALL_TITLE'), $this->INSTALL_PATH . '/unstep1.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
);
|
2018-10-04 16:28:14 +03:00
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
public function deleteFiles(): void
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2022-03-02 15:40:53 +03:00
|
|
|
$defaultSite = CSite::GetList($by, $sort, ['DEF' => 'Y'])->Fetch();
|
2014-11-27 18:37:59 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/retailcrm_run.php');
|
|
|
|
unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/retailcrm_setup.php');
|
2014-11-27 18:37:59 +03:00
|
|
|
unlink($defaultSite['ABS_DOC_ROOT'] . '/retailcrm/agent.php');
|
|
|
|
rmdir($defaultSite['ABS_DOC_ROOT'] . '/retailcrm/');
|
2022-03-02 15:40:53 +03:00
|
|
|
DeleteDirFilesEx(
|
|
|
|
$_SERVER['DOCUMENT_ROOT']
|
|
|
|
. COption::GetOptionString('sale', 'path2user_ps_files')
|
|
|
|
. 'retailcrmbonus'
|
|
|
|
);
|
2013-10-30 17:01:34 +04:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
public function GetProfileSetupVars(
|
2018-03-22 16:11:04 +03:00
|
|
|
$iblocks,
|
2021-09-08 10:05:09 +03:00
|
|
|
$simpleProps,
|
2018-03-22 16:11:04 +03:00
|
|
|
$propertiesHbSKU,
|
|
|
|
$propertiesHbProduct,
|
2018-12-26 11:41:06 +03:00
|
|
|
$filename,
|
2023-06-01 13:33:41 +03:00
|
|
|
$maxOffers,
|
|
|
|
$loadPurchasePrice,
|
|
|
|
$loadInactiveProduct
|
2021-09-08 10:05:09 +03:00
|
|
|
): string {
|
|
|
|
$strVars = '';
|
|
|
|
|
|
|
|
foreach ($iblocks as $key => $val) {
|
|
|
|
$strVars .= 'iblockExport[' . $key . ']=' . $val . '&';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($simpleProps as $propType => $props) {
|
|
|
|
$strVars = $this->addToStrVars($strVars, $propType, $props);
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if ($propertiesHbSKU) {
|
2021-09-08 10:05:09 +03:00
|
|
|
foreach ($propertiesHbSKU as $table => $arr) {
|
|
|
|
$strVars = $this->addToStrVars($strVars, 'highloadblock' . $table, $arr);
|
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|
2021-09-08 10:05:09 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if ($propertiesHbProduct) {
|
2021-09-08 10:05:09 +03:00
|
|
|
foreach ($propertiesHbProduct as $table => $arr) {
|
|
|
|
$strVars = $this->addToStrVars($strVars, 'highloadblock_product' . $table, $arr);
|
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
$additionalProperties = sprintf(
|
|
|
|
'SETUP_FILE_NAME=%s&maxOffersValue=%s&loadPurchasePrice=%s&loadNonActivity=%s',
|
|
|
|
$filename,
|
|
|
|
$maxOffers,
|
|
|
|
$loadPurchasePrice,
|
|
|
|
$loadInactiveProduct
|
|
|
|
);
|
2021-09-08 10:05:09 +03:00
|
|
|
|
2023-06-01 13:33:41 +03:00
|
|
|
return $strVars . $additionalProperties;
|
2021-09-08 10:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $strVars
|
|
|
|
* @param string $propType
|
|
|
|
* @param array $props
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function addToStrVars(string $strVars, string $propType, array $props): string
|
|
|
|
{
|
|
|
|
foreach ($props as $iblock => $arr) {
|
|
|
|
foreach ($arr as $id => $val) {
|
|
|
|
$strVars .= $propType . '_' . $id . '[' . $iblock . ']=' . $val . '&';
|
|
|
|
}
|
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
return $strVars;
|
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
public function historyLoad($api, $method)
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2023-04-26 17:18:38 +03:00
|
|
|
$lastSinceId = 0;
|
|
|
|
$startDate = new DateTime('-1 days');
|
2017-09-04 11:36:04 +03:00
|
|
|
|
|
|
|
try {
|
2023-04-26 17:18:38 +03:00
|
|
|
$historyResponse = $api->$method(['startDate' => $startDate->format('Y-m-d H:i:s')]);
|
2021-05-31 16:33:02 +03:00
|
|
|
} catch (CurlException $e) {
|
2017-09-04 11:36:04 +03:00
|
|
|
RCrmActions::eventLog(
|
2023-04-26 17:18:38 +03:00
|
|
|
'RetailCrmHistory::m' . $method, 'RetailCrm\RestApi::' . $method . '::CurlException',
|
2017-09-04 11:36:04 +03:00
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
return $lastSinceId;
|
2017-09-04 11:36:04 +03:00
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'RetailCrmHistory::' . $method, 'RetailCrm\RestApi::' . $method . '::InvalidArgumentException',
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
return $lastSinceId;
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
if (
|
|
|
|
!$historyResponse instanceof ApiResponse
|
|
|
|
|| !$historyResponse->isSuccessful()
|
|
|
|
|| empty($historyResponse['history'])
|
|
|
|
|| empty($historyResponse['pagination'])
|
|
|
|
) {
|
|
|
|
return $lastSinceId;
|
|
|
|
}
|
2017-09-04 11:36:04 +03:00
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
$startPage = $historyResponse['pagination']['currentPage'];
|
|
|
|
$lastPage = $historyResponse['pagination']['totalPageCount'];
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
for ($startPage; $startPage <= $lastPage; ++$startPage) {
|
|
|
|
if ($historyResponse instanceof ApiResponse && !empty($historyResponse['history'])) {
|
|
|
|
$history = $historyResponse['history'];
|
|
|
|
$lastSinceId = end($history)['id'];
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
$historyResponse = $api->$method(['sinceId' => $lastSinceId]);
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-26 17:18:38 +03:00
|
|
|
return $lastSinceId;
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
/**
|
|
|
|
* Returns all sites connected to the current API key
|
|
|
|
*
|
|
|
|
* @param string $api_host
|
|
|
|
* @param string $api_key
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getReferenceShops(string $api_host, string $api_key): array
|
2017-09-04 11:36:04 +03:00
|
|
|
{
|
|
|
|
global $APPLICATION;
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2024-03-18 14:00:13 +03:00
|
|
|
$client = new Client($api_host . '/api', ['apiKey' => $api_key]);
|
2023-12-12 16:51:15 +03:00
|
|
|
$result = [];
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
try {
|
2024-03-18 14:00:13 +03:00
|
|
|
$credentials = $client->makeRequest('/credentials', 'GET')->getResponseBody();
|
|
|
|
$residualRight = array_diff(Constants::REQUIRED_API_SCOPES, $credentials['scopes']);
|
|
|
|
|
|
|
|
$siteResponse = $client->makeRequest('/v5/reference/sites', 'GET');
|
2023-08-30 14:11:04 +03:00
|
|
|
$bitrixSites = RCrmActions::getSitesList();
|
|
|
|
$currencySites = RCrmActions::getCurrencySites();
|
2022-03-02 15:40:53 +03:00
|
|
|
} catch (CurlException $e) {
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::sitesList',
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
);
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
$result['errCode'] = 'ERR_' . $e->getCode();
|
2023-08-30 14:11:04 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
return $result;
|
2022-03-02 15:40:53 +03:00
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
// Проверка, что был получен корректный ответ
|
2024-03-18 14:00:13 +03:00
|
|
|
if (isset($siteResponse) && $siteResponse->getStatusCode() === 200 && count($residualRight) === 0) {
|
2023-12-12 16:51:15 +03:00
|
|
|
$sites = $siteResponse->sites ?? null;
|
|
|
|
|
|
|
|
if ($sites === null) {
|
|
|
|
$result['errCode'] = 'UNKNOWN_ERROR';
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
//Проверка количества магазинов, доступных по API
|
|
|
|
if (count($bitrixSites) === 1 && count($sites) > 1) {
|
|
|
|
$result['errCode'] = 'ERR_COUNT_SITES';
|
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
if (!isset($result['errCode']) && count($bitrixSites) === 1 ) {
|
|
|
|
$LID = $bitrixSites[0]['LID'] ?? null;
|
|
|
|
$cmsCurrency = $currencySites[$LID] ?? null;
|
2023-08-30 14:11:04 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
$crmSiteData = reset($sites);
|
|
|
|
$crmCurrency = $crmSiteData['currency'] ?? null;
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
$result['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
if (empty($result['errCode'])) {
|
2023-08-30 14:11:04 +03:00
|
|
|
ConfigProvider::setApiVersion(self::V5);
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
$result['sitesList'] = $APPLICATION->ConvertCharsetArray($sites, 'utf-8', SITE_CHARSET);
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
|
|
|
} else {
|
2024-03-18 14:00:13 +03:00
|
|
|
$result['errCode'] = sprintf(GetMessage('ERR_403'), implode(', ', $residualRight));
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
return $result;
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
/**
|
2022-03-02 15:40:53 +03:00
|
|
|
* Remove ICML export profiles and the agent which ran that export.
|
2021-05-31 16:33:02 +03:00
|
|
|
*
|
|
|
|
* @param \CDBResult $dbProfile
|
|
|
|
*/
|
|
|
|
private function removeExportProfiles(CDBResult $dbProfile): void
|
|
|
|
{
|
|
|
|
while ($arProfile = $dbProfile->Fetch()) {
|
|
|
|
if ($arProfile['DEFAULT_PROFILE'] !== 'Y') {
|
|
|
|
CAgent::RemoveAgent('CCatalogExport::PreGenerateExport(' . $arProfile['ID'] . ');', 'catalog');
|
|
|
|
CCatalogExport::Delete($arProfile['ID']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|