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;
|
|
|
|
|
IncludeModuleLangFile(__FILE__);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
if (class_exists('intaro_retailcrm'))
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
class intaro_retailcrm extends CModule
|
|
|
|
|
{
|
2016-09-15 16:42:10 +03:00
|
|
|
|
var $MODULE_ID = 'intaro.retailcrm';
|
|
|
|
|
var $OLD_MODULE_ID = 'intaro.intarocrm';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $MODULE_VERSION;
|
|
|
|
|
var $MODULE_VERSION_DATE;
|
|
|
|
|
var $MODULE_NAME;
|
|
|
|
|
var $MODULE_DESCRIPTION;
|
|
|
|
|
var $MODULE_GROUP_RIGHTS = 'N';
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $PARTNER_NAME;
|
|
|
|
|
var $PARTNER_URI;
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
|
|
|
|
var $RETAIL_CRM_API;
|
|
|
|
|
var $RETAIL_CRM_EXPORT = 'retailcrm';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $CRM_API_HOST_OPTION = 'api_host';
|
|
|
|
|
var $CRM_API_KEY_OPTION = 'api_key';
|
2015-03-03 16:37:34 +03:00
|
|
|
|
var $CRM_SITES_LIST= 'sites_list';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $CRM_ORDER_TYPES_ARR = 'order_types_arr';
|
|
|
|
|
var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
2014-01-23 17:50:58 +04:00
|
|
|
|
var $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $CRM_PAYMENT_TYPES = 'pay_types_arr';
|
|
|
|
|
var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
|
|
|
|
var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
|
|
|
|
|
var $CRM_ORDER_LAST_ID = 'order_last_id';
|
|
|
|
|
var $CRM_ORDER_PROPS = 'order_props';
|
2015-03-03 16:37:34 +03:00
|
|
|
|
var $CRM_LEGAL_DETAILS = 'legal_details';
|
|
|
|
|
var $CRM_CUSTOM_FIELDS = 'custom_fields';
|
|
|
|
|
var $CRM_CONTRAGENT_TYPE = 'contragent_type';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $CRM_ORDER_DISCHARGE = 'order_discharge';
|
|
|
|
|
var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
2016-09-15 16:42:10 +03:00
|
|
|
|
var $CRM_ORDER_HISTORY = 'order_history';
|
|
|
|
|
var $CRM_CUSTOMER_HISTORY = 'customer_history';
|
2014-06-20 16:03:46 +04:00
|
|
|
|
var $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
|
2015-11-09 17:46:32 +03:00
|
|
|
|
var $CRM_CATALOG_IBLOCKS = 'catalog_base_iblocks';
|
2016-09-15 16:42:10 +03:00
|
|
|
|
var $CRM_ORDER_NUMBERS = 'order_numbers';
|
|
|
|
|
var $CRM_CANSEL_ORDER = 'cansel_order';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
var $INSTALL_PATH;
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
function intaro_retailcrm()
|
|
|
|
|
{
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$arModuleVersion = array();
|
|
|
|
|
$path = str_replace("\\", "/", __FILE__);
|
|
|
|
|
$path = substr($path, 0, strlen($path) - strlen("/index.php"));
|
|
|
|
|
$this->INSTALL_PATH = $path;
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
if (!in_array('curl', get_loaded_extensions())) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$APPLICATION->ThrowException(GetMessage("RETAILCRM_CURL_ERR"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$infoSale = CModule::CreateModuleObject('sale')->MODULE_VERSION;
|
|
|
|
|
if (version_compare($infoSale, '16', '<=')) {
|
|
|
|
|
$APPLICATION->ThrowException(GetMessage("SALE_VERSION_ERR"));
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!date_default_timezone_get()) {
|
|
|
|
|
if (!ini_get('date.timezone')) {
|
|
|
|
|
$APPLICATION->ThrowException(GetMessage("DATE_TIMEZONE_ERR"));
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
include($this->INSTALL_PATH . '/../classes/general/ApiClient.php');
|
|
|
|
|
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/order/RetailCrmOrder.php');
|
|
|
|
|
include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory.php');
|
|
|
|
|
include($this->INSTALL_PATH . '/../classes/general/events/RetailCrmEvent.php');
|
|
|
|
|
include($this->INSTALL_PATH . '/../classes/general/icml/RetailCrmICML.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');
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
$step = intval($_REQUEST['step']);
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
if (file_exists($this->INSTALL_PATH . '/../classes/general/config/options.xml')) {
|
|
|
|
|
$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) {
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$type["NAME"] = $APPLICATION->ConvertCharset((string)$contragent, 'utf-8', SITE_CHARSET);
|
|
|
|
|
$type["ID"] = (string)$contragent["id"];
|
|
|
|
|
$arResult['contragentType'][] = $type;
|
|
|
|
|
unset ($type);
|
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
|
foreach($options->fields->field as $field) {
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$type["NAME"] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET);
|
|
|
|
|
$type["ID"] = (string)$field["id"];
|
|
|
|
|
|
|
|
|
|
if ($field["group"] == 'custom') {
|
|
|
|
|
$arResult['customFields'][] = $type;
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} elseif (!$field["group"]) {
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$arResult['orderProps'][] = $type;
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$groups = explode(",", (string)$field["group"]);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
foreach ($groups as $group) {
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$type["GROUP"][] = trim($group);
|
|
|
|
|
}
|
|
|
|
|
$arResult['legalDetails'][] = $type;
|
|
|
|
|
}
|
|
|
|
|
unset($type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if ($step == 11) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$arResult['arSites'] = RCrmActions::SitesList();
|
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) {
|
|
|
|
|
if (!CModule::IncludeModule("sale")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CModule::IncludeModule("iblock")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CModule::IncludeModule("catalog")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
|
}
|
2016-09-15 16:42:10 +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;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if (!CModule::IncludeModule("sale")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CModule::IncludeModule("iblock")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CModule::IncludeModule("catalog")) {
|
|
|
|
|
$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
|
|
|
|
);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
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);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if ($api_host['scheme'] != 'https') {
|
|
|
|
|
$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(
|
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
|
|
|
|
);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API = new RetailCrm\ApiClient($api_host, $api_key);
|
2015-03-03 16:37:34 +03:00
|
|
|
|
//api key ok and sites list
|
|
|
|
|
try {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($this->RETAIL_CRM_API->sitesList()->sites, 'utf-8', SITE_CHARSET);
|
2015-03-03 16:37:34 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::sitesList',
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$arResult['errCode'] = 'ERR_' . $e->getCode();
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
|
2016-09-15 16:42:10 +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
|
|
|
|
);
|
|
|
|
|
} else if ($step == 2) {//доставки, оплаты, типы заказов
|
|
|
|
|
if (!CModule::IncludeModule("sale")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_SALE';
|
|
|
|
|
}
|
|
|
|
|
if (!CModule::IncludeModule("iblock")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
|
}
|
|
|
|
|
if (!CModule::IncludeModule("catalog")) {
|
|
|
|
|
$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'
|
2015-03-03 16:37:34 +03:00
|
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$arResult['arSites'] = RCrmActions::SitesList();
|
|
|
|
|
/*
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
|
|
|
|
|
|
|
|
|
|
$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);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
//prepare crm lists
|
2014-03-22 14:52:17 +04:00
|
|
|
|
try {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$arResult['orderTypesList'] = $this->RETAIL_CRM_API->orderTypesList()->orderTypes;
|
2015-03-03 16:37:34 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::orderTypesList::CurlException',
|
2014-03-22 14:52:17 +04:00
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
|
);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
$APPLICATION->RestartBuffer();
|
|
|
|
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
|
|
|
|
die(json_encode(array("success" => false)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 14:52:17 +04:00
|
|
|
|
try {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$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; // --statuses
|
|
|
|
|
$arResult['paymentList'] = $this->RETAIL_CRM_API->orderStatusesList()->statuses;
|
|
|
|
|
$arResult['paymentGroupList'] = $this->RETAIL_CRM_API->orderStatusGroupsList()->statusGroups; // -- statuses groups
|
2015-03-03 16:37:34 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\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()
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
//bitrix orderTypesList -- personTypes
|
|
|
|
|
$dbOrderTypesList = CSalePersonType::GetList(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
array(
|
|
|
|
|
"SORT" => "ASC",
|
|
|
|
|
"NAME" => "ASC"
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
"ACTIVE" => "Y",
|
|
|
|
|
),
|
|
|
|
|
false, false, array()
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//form order types ids arr
|
|
|
|
|
$orderTypesArr = array();
|
|
|
|
|
if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
|
|
|
|
|
do {
|
|
|
|
|
$arResult['bitrixOrderTypesList'][] = $arOrderTypesList;
|
|
|
|
|
$orderTypesArr[$arOrderTypesList['ID']] = htmlspecialchars(trim($_POST['order-type-' . $arOrderTypesList['ID']]));
|
|
|
|
|
} while ($arOrderTypesList = $dbOrderTypesList->Fetch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//bitrix deliveryTypesList
|
|
|
|
|
$dbDeliveryTypesList = CSaleDelivery::GetList(
|
|
|
|
|
array(
|
|
|
|
|
"SORT" => "ASC",
|
|
|
|
|
"NAME" => "ASC"
|
|
|
|
|
), array(
|
|
|
|
|
"ACTIVE" => "Y",
|
|
|
|
|
), false, false, array()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//form delivery types ids arr
|
|
|
|
|
$deliveryTypesArr = array();
|
|
|
|
|
if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) {
|
|
|
|
|
do {
|
|
|
|
|
$arResult['bitrixDeliveryTypesList'][] = $arDeliveryTypesList;
|
|
|
|
|
$deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']]));
|
|
|
|
|
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 17:50:58 +04:00
|
|
|
|
//bitrix deliveryServicesList
|
|
|
|
|
$dbDeliveryServicesList = CSaleDeliveryHandler::GetList(
|
|
|
|
|
array(
|
|
|
|
|
'SORT' => 'ASC',
|
|
|
|
|
'NAME' => 'ASC'
|
|
|
|
|
),
|
|
|
|
|
array(
|
2015-03-03 16:37:34 +03:00
|
|
|
|
'ACTIVE' => 'Y',
|
|
|
|
|
'SITE_ID' => $arResult['arSites'][0]['LID']
|
2014-01-23 17:50:58 +04:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//form delivery services ids arr
|
|
|
|
|
if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) {
|
|
|
|
|
do {
|
|
|
|
|
//auto delivery types
|
|
|
|
|
$deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']]));
|
|
|
|
|
} while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch());
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
//bitrix paymentTypesList
|
|
|
|
|
$dbPaymentTypesList = CSalePaySystem::GetList(
|
|
|
|
|
array(
|
|
|
|
|
"SORT" => "ASC",
|
|
|
|
|
"NAME" => "ASC"
|
|
|
|
|
), array(
|
|
|
|
|
"ACTIVE" => "Y"
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//form payment types ids arr
|
|
|
|
|
$paymentTypesArr = array();
|
|
|
|
|
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
|
|
|
|
|
do {
|
|
|
|
|
$arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList;
|
|
|
|
|
$paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']]));
|
|
|
|
|
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//bitrix paymentStatusesList
|
|
|
|
|
$dbPaymentStatusesList = CSaleStatus::GetList(
|
|
|
|
|
array(
|
|
|
|
|
"SORT" => "ASC",
|
|
|
|
|
"NAME" => "ASC"
|
|
|
|
|
), array(
|
|
|
|
|
"LID" => "ru", //ru
|
|
|
|
|
"ACTIVE" => "Y"
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//form payment statuses ids arr
|
|
|
|
|
$paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY']));
|
|
|
|
|
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
|
|
|
|
|
do {
|
2015-11-09 17:46:32 +03:00
|
|
|
|
$arResult['bitrixPaymentStatusesList'][$arPaymentStatusesList['ID']] = $arPaymentStatusesList;
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
|
|
|
|
|
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arResult['bitrixPaymentStatusesList'][] = array(
|
|
|
|
|
'ID' => 'YY',
|
|
|
|
|
'NAME' => GetMessage('CANCELED')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//form payment ids arr
|
|
|
|
|
$paymentArr = array();
|
|
|
|
|
$paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
|
|
|
|
|
$paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize(RCrmActions::clearArr($paymentArr)));
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
// generate updated select inputs
|
|
|
|
|
$input = array();
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['bitrixDeliveryTypesList'] as $bitrixDeliveryType) {
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] =
|
|
|
|
|
'<select name="delivery-type-' . $bitrixDeliveryType['ID'] . '" class="typeselect">';
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] .= '<option value=""></option>';
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['deliveryTypesList'] as $deliveryType) {
|
|
|
|
|
if ($deliveryTypesArr[$bitrixDeliveryType['ID']] == $deliveryType['code']) {
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] .=
|
|
|
|
|
'<option value="' . $deliveryType['code'] . '" selected>';
|
|
|
|
|
} else {
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] .=
|
|
|
|
|
'<option value="' . $deliveryType['code'] . '">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] .=
|
|
|
|
|
$APPLICATION->ConvertCharset($deliveryType['name'], 'utf-8', SITE_CHARSET);
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] .= '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['delivery-type-' . $bitrixDeliveryType['ID']] .= '</select>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType) {
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] =
|
|
|
|
|
'<select name="payment-type-' . $bitrixPaymentType['ID'] . '" class="typeselect">';
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] .= '<option value=""></option>';
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['paymentTypesList'] as $paymentType) {
|
|
|
|
|
if ($paymentTypesArr[$bitrixPaymentType['ID']] == $paymentType['code']) {
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] .=
|
|
|
|
|
'<option value="' . $paymentType['code'] . '" selected>';
|
|
|
|
|
} else {
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] .=
|
|
|
|
|
'<option value="' . $paymentType['code'] . '">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] .=
|
|
|
|
|
$APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET);
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] .= '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-type-' . $bitrixPaymentType['ID']] .= '</select>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus) {
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] =
|
|
|
|
|
'<select name="payment-status-' . $bitrixPaymentStatus['ID'] . '" class="typeselect">';
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '<option value=""></option>';
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['paymentGroupList'] as $orderStatusGroup) {
|
|
|
|
|
if (empty($orderStatusGroup['statuses']))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']].=
|
|
|
|
|
'<optgroup label="' . $orderStatusGroup['name'] . '">';
|
|
|
|
|
|
|
|
|
|
foreach ($orderStatusGroup['statuses'] as $payment) {
|
2014-01-31 20:20:37 +04:00
|
|
|
|
if(!isset($arResult['paymentList'][$payment])) continue;
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if ($paymentStatusesArr[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) {
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .=
|
|
|
|
|
'<option value="' . $arResult['paymentList'][$payment]['code'] . '" selected>';
|
|
|
|
|
} else {
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .=
|
|
|
|
|
'<option value="' . $arResult['paymentList'][$payment]['code'] . '">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .=
|
|
|
|
|
$APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET);
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '</optgroup>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '</select>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['bitrixPaymentList'] as $bitrixPayment) {
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] =
|
|
|
|
|
'<select name="payment-' . $bitrixPayment['ID'] . '" class="typeselect">';
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] .= '<option value=""></option>';
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['paymentStatusesList'] as $paymentStatus) {
|
|
|
|
|
if ($paymentArr[$bitrixPayment['ID']] == $paymentStatus['code']) {
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] .=
|
|
|
|
|
'<option value="' . $paymentStatus['code'] . '" selected>';
|
|
|
|
|
} else {
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] .=
|
|
|
|
|
'<option value="' . $paymentStatus['code'] . '">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] .=
|
|
|
|
|
$APPLICATION->ConvertCharset($paymentStatus['name'], 'utf-8', SITE_CHARSET);
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] .= '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['payment-' . $bitrixPayment['ID']] .= '</select>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['bitrixOrderTypesList'] as $bitrixOrderType) {
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] =
|
|
|
|
|
'<select name="order-type-' . $bitrixOrderType['ID'] . '" class="typeselect">';
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] .= '<option value=""></option>';
|
|
|
|
|
|
|
|
|
|
foreach ($arResult['orderTypesList'] as $orderType) {
|
|
|
|
|
if ($orderTypesArr[$bitrixOrderType['ID']] == $orderType['code']) {
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] .=
|
|
|
|
|
'<option value="' . $orderType['code'] . '" selected>';
|
|
|
|
|
} else {
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] .=
|
|
|
|
|
'<option value="' . $orderType['code'] . '">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] .=
|
|
|
|
|
$APPLICATION->ConvertCharset($orderType['name'], 'utf-8', SITE_CHARSET);
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] .= '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input['order-type-' . $bitrixOrderType['ID']] .= '</select>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-24 17:57:49 +04:00
|
|
|
|
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$APPLICATION->RestartBuffer();
|
|
|
|
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
|
|
|
|
die(json_encode(array("success" => true, "result" => $input)));
|
2016-09-15 16:42:10 +03:00
|
|
|
|
}*/
|
2015-03-03 16:37:34 +03:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (count($arResult['arSites']) > 1) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
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);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
foreach ($arResult['arSites'] as $site) {
|
|
|
|
|
if ($_POST['sites-id-'.$site['LID']] && !empty($_POST['sites-id-'.$site['LID']])) {
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$siteCode[$site['LID']] = htmlspecialchars(trim($_POST['sites-id-'.$site['LID']]));
|
|
|
|
|
}
|
|
|
|
|
}
|
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';
|
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key);
|
2015-03-03 16:37:34 +03:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_SITES_LIST, serialize($siteCode));
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {//если 1 сайт
|
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);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if($api_host['scheme'] != 'https') {
|
|
|
|
|
$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(
|
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
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
|
try {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API->paymentStatusesList()->paymentStatuses;
|
2015-03-03 16:37:34 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException',
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
|
);
|
2014-03-22 14:52:17 +04:00
|
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
|
$arResult['errCode'] = 'ERR_' . $e->getCode();
|
2014-03-22 14:52:17 +04:00
|
|
|
|
|
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
|
|
|
|
);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
}
|
2015-03-03 16:37:34 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
//prepare crm lists
|
2015-03-03 16:37:34 +03:00
|
|
|
|
try {
|
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;
|
2015-03-03 16:37:34 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\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()
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
|
|
|
|
//bitrix personTypes
|
|
|
|
|
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
|
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(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step2.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} elseif ($step == 3) {//сопостовление свойств заказа
|
2013-10-30 17:01:34 +04: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(
|
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
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
//bitrix orderTypesList
|
|
|
|
|
$arResult['arSites'] = RCrmActions::SitesList();
|
|
|
|
|
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$orderTypesArr = array();
|
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();
|
2015-03-03 16:37:34 +03:00
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
if (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'false') {//сами настраиваем доставки
|
|
|
|
|
$deliveryTypesArr = array();
|
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
|
|
|
|
}
|
2016-10-04 17:57:39 +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!
|
2016-10-04 17:57:39 +03:00
|
|
|
|
foreach ($optionsDelivTypes as $deliveryType) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$load = true;
|
|
|
|
|
try {
|
|
|
|
|
$this->RETAIL_CRM_API->deliveryTypesEdit(RCrmActions::clearArr(array(
|
|
|
|
|
'code' => $deliveryType['ID'],
|
|
|
|
|
'name' => RCrmActions::toJSON($deliveryType['NAME']),
|
|
|
|
|
'defaultCost' => $deliveryType['CONFIG']['MAIN']['PRICE'],
|
|
|
|
|
'description' => RCrmActions::toJSON($deliveryType['DESCRIPTION']),
|
|
|
|
|
'paymentTypes' => ''
|
|
|
|
|
)));
|
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
|
|
|
|
$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) {
|
|
|
|
|
foreach ($optionsDelivTypes as $deliveryService) {
|
|
|
|
|
if ($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] == $deliveryType['ID']) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$srv = explode(':', $deliveryService['CODE']);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (count($srv) == 2) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
try {
|
|
|
|
|
$this->RETAIL_CRM_API->deliveryServicesEdit(RCrmActions::clearArr(array(
|
|
|
|
|
'code' => $srv[1],
|
|
|
|
|
'name' => RCrmActions::toJSON($deliveryService['NAME']),
|
|
|
|
|
'deliveryType' => $deliveryType['ID']
|
|
|
|
|
)));
|
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'intaro.retailcrm/options.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();
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$paymentTypesArr = array();
|
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();
|
|
|
|
|
|
|
|
|
|
$paymentStatusesArr = array();
|
|
|
|
|
$canselOrderArr = array();
|
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
|
|
|
|
|
$paymentArr = array();
|
|
|
|
|
$paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
|
|
|
|
|
$paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
//new page
|
|
|
|
|
//form orderProps
|
|
|
|
|
$arResult['arProp'] = RCrmActions::OrderPropsList();
|
|
|
|
|
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr)));
|
|
|
|
|
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);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS, serialize(array()));
|
2016-09-15 16:42:10 +03:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CANSEL_ORDER, serialize(RCrmActions::clearArr($canselOrderArr)));
|
|
|
|
|
|
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 ($customFields = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_CUSTOM_FIELDS, 0)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$arResult['CUSTOM_FIELDS'] = unserialize($customFields);
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
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 . '/step3.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} elseif ($step == 4) {//выгрузка старых заказов
|
2013-10-30 17:01:34 +04: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
|
|
|
|
);
|
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
|
//order upload
|
2015-03-03 16:37:34 +03:00
|
|
|
|
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
|
2016-09-16 11:46:44 +03:00
|
|
|
|
$historyTime = Date('');
|
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);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$countLeft = (int) \Bitrix\Sale\Internals\OrderTable::getCount(array('>ID' => $lastUpOrderId));
|
|
|
|
|
$countAll = (int) \Bitrix\Sale\Internals\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 {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$finish = (int) $_POST['finish'];
|
2016-09-15 16:42:10 +03:00
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$percent = round(100 - ($countLeft * 100 / $countAll), 1);
|
|
|
|
|
|
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
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$APPLICATION->RestartBuffer();
|
|
|
|
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
|
|
|
|
die(json_encode(array("finish" => $finish, "percent" => $percent)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
//bitrix orderTypesList
|
|
|
|
|
$orderTypesList = RCrmActions::OrderTypesList(RCrmActions::SitesList());
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$orderTypesArr = array();
|
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']]));
|
2013-10-30 17:01:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$orderPropsArr = array();
|
|
|
|
|
foreach ($orderTypesList as $orderType) {
|
|
|
|
|
$propsCount = 0;
|
|
|
|
|
$_orderPropsArr = array();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-03 16:37:34 +03:00
|
|
|
|
//legal details props
|
|
|
|
|
$legalDetailsArr = array();
|
|
|
|
|
foreach ($orderTypesList as $orderType) {
|
|
|
|
|
$_legalDetailsArr = array();
|
|
|
|
|
foreach ($arResult['legalDetails'] as $legalDetails) {
|
|
|
|
|
$_legalDetailsArr[$legalDetails['ID']] = htmlspecialchars(trim($_POST['legal-detail-' . $legalDetails['ID'] . '-' . $orderType['ID']]));
|
|
|
|
|
}
|
|
|
|
|
$legalDetailsArr[$orderType['ID']] = $_legalDetailsArr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$customFieldsArr = array();
|
|
|
|
|
foreach ($orderTypesList as $orderType) {
|
|
|
|
|
$_customFieldsArr = array();
|
|
|
|
|
foreach ($arResult['customFields'] as $custom) {
|
|
|
|
|
$_customFieldsArr[$custom['ID']] = htmlspecialchars(trim($_POST['custom-fields-' . $custom['ID'] . '-' . $orderType['ID']]));
|
|
|
|
|
}
|
|
|
|
|
$customFieldsArr[$orderType['ID']] = $_customFieldsArr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//contragents type list
|
|
|
|
|
$contragentTypeArr = array();//сделать проверки
|
|
|
|
|
foreach ($orderTypesList as $orderType) {
|
|
|
|
|
$contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
|
|
|
|
|
}
|
|
|
|
|
|
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_CUSTOM_FIELDS, serialize(RCrmActions::clearArr($customFieldsArr)));
|
|
|
|
|
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)));
|
2015-03-03 16:37:34 +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 . '/step4.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} elseif ($step == 5) {//экспорт каталога
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if (!CModule::IncludeModule("iblock")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
|
}
|
|
|
|
|
if (!CModule::IncludeModule("catalog")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_CATALOG';
|
|
|
|
|
}
|
2016-10-04 17:57:39 +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);
|
|
|
|
|
$api = new \RetailCrm\ApiClient($api_host, $api_key);
|
|
|
|
|
|
|
|
|
|
$customerH = self::historyLoad($api, 'customersHistory');
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CUSTOMER_HISTORY, $customerH);
|
|
|
|
|
//если есть старое значение, переделываем его на новый лад, иначе вычисляем
|
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 {
|
|
|
|
|
$history = $api->ordersHistory(array('startDate' => $historyDate));
|
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
|
|
|
|
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()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (isset($history['history'])) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$hIs = (int)$history['history'][0]['id'] - 1;
|
|
|
|
|
$orderH = $hIs;
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$orderH = self::historyLoad($api, 'ordersHistory');
|
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$orderH = self::historyLoad($api, 'ordersHistory');
|
|
|
|
|
}
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY, $orderH);
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
$arResult['PRICE_TYPES'] = array();
|
|
|
|
|
|
|
|
|
|
$dbPriceType = CCatalogGroup::GetList(
|
|
|
|
|
array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
while ($arPriceType = $dbPriceType->Fetch()) {
|
|
|
|
|
$arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType;
|
|
|
|
|
}
|
|
|
|
|
|
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 . '/step5.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} elseif ($step == 6) {//регистрация модуля
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if (!CModule::IncludeModule("iblock")) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
|
|
|
|
}
|
|
|
|
|
if (!CModule::IncludeModule("catalog")) {
|
|
|
|
|
$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 . '/step5.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['back']) && $_POST['back']) {
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step3.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (!isset($_POST['IBLOCK_EXPORT'])) {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_IBLOCK';
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$iblocks = $_POST['IBLOCK_EXPORT'];
|
2016-10-04 17:57:39 +03:00
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
$iblockProperties = array(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
"article" => "article",
|
2013-10-30 17:01:34 +04:00
|
|
|
|
"manufacturer" => "manufacturer",
|
2016-09-15 16:42:10 +03:00
|
|
|
|
"color" => "color",
|
|
|
|
|
"weight" => "weight",
|
|
|
|
|
"size" => "size",
|
|
|
|
|
"length" => "length",
|
|
|
|
|
"width" => "width",
|
|
|
|
|
"height" => "height",
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$propertiesSKU = array();
|
2014-01-23 16:55:04 +04:00
|
|
|
|
$propertiesUnitSKU = array();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
foreach ($iblockProperties as $prop) {
|
|
|
|
|
foreach ($_POST['IBLOCK_PROPERTY_SKU'. '_' . $prop] as $iblock => $val) {
|
|
|
|
|
$propertiesSKU[$iblock][$prop] = $val;
|
|
|
|
|
}
|
2014-01-23 16:55:04 +04:00
|
|
|
|
foreach ($_POST['IBLOCK_PROPERTY_UNIT_SKU'. '_' . $prop] as $iblock => $val) {
|
|
|
|
|
$propertiesUnitSKU[$iblock][$prop] = $val;
|
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$propertiesProduct = array();
|
2014-01-23 16:55:04 +04:00
|
|
|
|
$propertiesUnitProduct = array();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
foreach ($iblockProperties as $prop) {
|
|
|
|
|
foreach ($_POST['IBLOCK_PROPERTY_PRODUCT'. '_' . $prop] as $iblock => $val) {
|
|
|
|
|
$propertiesProduct[$iblock][$prop] = $val;
|
|
|
|
|
}
|
2014-01-23 16:55:04 +04:00
|
|
|
|
foreach ($_POST['IBLOCK_PROPERTY_UNIT_PRODUCT'. '_' . $prop] as $iblock => $val) {
|
|
|
|
|
$propertiesUnitProduct[$iblock][$prop] = $val;
|
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (!isset($_POST['SETUP_FILE_NAME'])) {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_FILE';
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$filename = $_POST['SETUP_FILE_NAME'];
|
2016-10-04 17:57:39 +03:00
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (!isset($_POST['TYPE_LOADING'])) {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$typeLoading = 0;
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$typeLoading = $_POST['TYPE_LOADING'];
|
2016-10-04 17:57:39 +03:00
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (!isset($_POST['SETUP_PROFILE_NAME'])) {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$profileName = "";
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$profileName = $_POST['SETUP_PROFILE_NAME'];
|
2016-10-04 17:57:39 +03:00
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if ($typeLoading != 'none' && $profileName == "") {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_PROFILE';
|
2016-10-04 17:57:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($filename == "") {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_FILE';
|
2016-10-04 17:57:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if (isset($arResult['errCode']) && $arResult['errCode']) {
|
2016-10-04 17:57:39 +03:00
|
|
|
|
$arOldValues = array(
|
2013-10-30 17:01:34 +04:00
|
|
|
|
'IBLOCK_EXPORT' => $iblocks,
|
|
|
|
|
'IBLOCK_PROPERTY_SKU' => $propertiesSKU,
|
2014-01-23 16:55:04 +04:00
|
|
|
|
'IBLOCK_PROPERTY_UNIT_SKU' => $propertiesUnitSKU,
|
2013-10-30 17:01:34 +04:00
|
|
|
|
'IBLOCK_PROPERTY_PRODUCT' => $propertiesProduct,
|
2014-01-23 16:55:04 +04:00
|
|
|
|
'IBLOCK_PROPERTY_UNIT_PRODUCT' => $propertiesUnitProduct,
|
2013-10-30 17:01:34 +04:00
|
|
|
|
'SETUP_FILE_NAME' => $filename,
|
|
|
|
|
'SETUP_PROFILE_NAME' => $profileName
|
|
|
|
|
);
|
|
|
|
|
global $oldValues;
|
|
|
|
|
$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
|
|
|
|
);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegisterModule($this->MODULE_ID);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder");
|
|
|
|
|
RegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "RetailCrmEvent", "onBeforeOrderAdd");
|
|
|
|
|
RegisterModuleDependences("sale", "OnOrderSave", $this->MODULE_ID, "RetailCrmEvent", "OnOrderSave");
|
|
|
|
|
RegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate");
|
|
|
|
|
RegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "orderSave");
|
|
|
|
|
RegisterModuleDependences("sale", "OnSaleOrderEntityDelete", $this->MODULE_ID, "RetailCrmEvent", "orderDelete");
|
|
|
|
|
|
2014-06-20 16:03:46 +04:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types'])));
|
2015-11-09 17:46:32 +03:00
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_IBLOCKS, $iblocks);
|
2014-06-20 16:03:46 +04:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$this->CopyFiles();
|
2016-09-15 16:42:10 +03:00
|
|
|
|
if (isset($_POST['LOAD_NOW'])) {
|
|
|
|
|
$loader = new RetailCrmICML();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$loader->iblocks = $iblocks;
|
2014-01-23 16:55:04 +04:00
|
|
|
|
$loader->propertiesUnitProduct = $propertiesUnitProduct;
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$loader->propertiesProduct = $propertiesProduct;
|
2014-01-23 16:55:04 +04:00
|
|
|
|
$loader->propertiesUnitSKU = $propertiesUnitSKU;
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$loader->propertiesSKU = $propertiesSKU;
|
|
|
|
|
$loader->filename = $filename;
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$loader->serverName = \Bitrix\Main\Context::getCurrent()->getServer()->getHttpHost();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$loader->application = $APPLICATION;
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$loader->Load();
|
2013-10-30 17:01:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($typeLoading == 'agent' || $typeLoading == 'cron') {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->RETAIL_CRM_EXPORT . '_run.php')) {
|
|
|
|
|
$dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->RETAIL_CRM_EXPORT));
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
while ($arProfile = $dbProfile->Fetch()) {
|
|
|
|
|
if ($arProfile["DEFAULT_PROFILE"] != "Y") {
|
|
|
|
|
CAgent::RemoveAgent("CCatalogExport::PreGenerateExport(" . $arProfile['ID'] . ");", "catalog");
|
|
|
|
|
CCatalogExport::Delete($arProfile['ID']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-23 16:55:04 +04:00
|
|
|
|
$ar = $this->GetProfileSetupVars($iblocks, $propertiesProduct, $propertiesUnitProduct, $propertiesSKU, $propertiesUnitSKU, $filename);
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$PROFILE_ID = CCatalogExport::Add(array(
|
2016-09-15 16:42:10 +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" => $ar
|
2013-10-30 17:01:34 +04:00
|
|
|
|
));
|
|
|
|
|
if (intval($PROFILE_ID) <= 0) {
|
|
|
|
|
$arResult['errCode'] = 'ERR_IBLOCK';
|
2016-10-04 17:57:39 +03:00
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($typeLoading == 'agent') {
|
|
|
|
|
$dateAgent = new DateTime();
|
|
|
|
|
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
|
|
|
|
|
$dateAgent->add($intAgent);
|
|
|
|
|
CAgent::AddAgent(
|
|
|
|
|
"CCatalogExport::PreGenerateExport(" . $PROFILE_ID . ");", "catalog", "N", 86400, $dateAgent->format('d.m.Y H:i:s'), // date of first check
|
|
|
|
|
"Y", // agent is active
|
|
|
|
|
$dateAgent->format('d.m.Y H:i:s'), // date of first start
|
|
|
|
|
30
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CCatalogExport::Update($PROFILE_ID, array(
|
|
|
|
|
"IN_AGENT" => "Y"
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
$agent_period = 24;
|
|
|
|
|
$agent_php_path = "/usr/local/php/bin/php";
|
|
|
|
|
|
|
|
|
|
if (!file_exists($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php")) {
|
|
|
|
|
CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS);
|
|
|
|
|
$tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php");
|
|
|
|
|
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php", "rb");
|
|
|
|
|
$tmp_data = fread($fp, $tmp_file_size);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
$tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data);
|
|
|
|
|
$tmp_data = str_replace("#PHP_PATH#", $agent_php_path, $tmp_data);
|
|
|
|
|
|
|
|
|
|
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php", "ab");
|
|
|
|
|
fwrite($fp, $tmp_data);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cfg_data = "";
|
|
|
|
|
if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) {
|
|
|
|
|
$cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg");
|
|
|
|
|
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb");
|
|
|
|
|
$cfg_data = fread($fp, $cfg_file_size);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/");
|
|
|
|
|
|
|
|
|
|
if ($arProfile["IN_CRON"] == "Y") {
|
|
|
|
|
// remove
|
|
|
|
|
$cfg_data = preg_replace("#^.*?" . preg_quote(CATALOG_PATH2EXPORTS) . "cron_frame.php +" . $PROFILE_ID . " *>.*?$#im", "", $cfg_data);
|
|
|
|
|
} else {
|
|
|
|
|
$strTime = "0 */" . $agent_period . " * * * ";
|
|
|
|
|
if (strlen($cfg_data) > 0)
|
|
|
|
|
$cfg_data .= "\n";
|
|
|
|
|
|
|
|
|
|
$cfg_data .= $strTime . $agent_php_path . " -f " . $_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php " . $PROFILE_ID . " >" . $_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/" . $PROFILE_ID . ".txt\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCatalogExport::Update($PROFILE_ID, array(
|
|
|
|
|
"IN_CRON" => "Y"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/");
|
|
|
|
|
$cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data);
|
|
|
|
|
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb");
|
|
|
|
|
fwrite($fp, $cfg_data);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
$arRetval = array();
|
|
|
|
|
@exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//agent
|
|
|
|
|
$dateAgent = new DateTime();
|
|
|
|
|
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
|
|
|
|
|
$dateAgent->add($intAgent);
|
|
|
|
|
|
|
|
|
|
CAgent::AddAgent(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
"RCrmActions::orderAgent();", $this->MODULE_ID, "N", 600, // interval - 10 mins
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$dateAgent->format('d.m.Y H:i:s'), // date of first check
|
|
|
|
|
"Y", // agent is active
|
|
|
|
|
$dateAgent->format('d.m.Y H:i:s'), // date of first start
|
|
|
|
|
30
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$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);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key);
|
2014-03-22 14:52:17 +04:00
|
|
|
|
try {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$this->RETAIL_CRM_API->statisticUpdate();
|
2015-03-03 16:37:34 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::statisticUpdate::CurlException',
|
2014-03-22 14:52:17 +04:00
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-01-28 17:44:21 +04:00
|
|
|
|
// in fin order
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE, date('Y-m-d H:i:s'));
|
|
|
|
|
|
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 . '/step6.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
function DoUninstall()
|
|
|
|
|
{
|
2013-10-30 17:01:34 +04:00
|
|
|
|
global $APPLICATION;
|
|
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
|
CAgent::RemoveAgent("RCrmActions::orderAgent();", $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);
|
|
|
|
|
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);
|
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID);
|
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_SITES);
|
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_PROPS);
|
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_CUSTOM_FIELDS);
|
|
|
|
|
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);
|
2015-11-09 17:46:32 +03:00
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_IBLOCKS);
|
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);
|
|
|
|
|
|
|
|
|
|
UnRegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder");
|
|
|
|
|
UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "RetailCrmEvent", "onBeforeOrderAdd");
|
|
|
|
|
UnRegisterModuleDependences("sale", "OnOrderSave", $this->MODULE_ID, "RetailCrmEvent", "OnOrderSave");
|
|
|
|
|
UnRegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate");
|
|
|
|
|
UnRegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "orderSave");
|
|
|
|
|
UnRegisterModuleDependences("sale", "OnSaleOrderEntityDelete", $this->MODULE_ID, "RetailCrmEvent", "orderDelete");
|
|
|
|
|
|
2013-10-30 17:01:34 +04:00
|
|
|
|
if (CModule::IncludeModule("catalog")) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->RETAIL_CRM_EXPORT . '_run.php')) {
|
|
|
|
|
$dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->RETAIL_CRM_EXPORT));
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
while ($arProfile = $dbProfile->Fetch()) {
|
|
|
|
|
if ($arProfile["DEFAULT_PROFILE"] != "Y") {
|
|
|
|
|
CAgent::RemoveAgent("CCatalogExport::PreGenerateExport(" . $arProfile['ID'] . ");", "catalog");
|
|
|
|
|
CCatalogExport::Delete($arProfile['ID']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->DeleteFiles();
|
|
|
|
|
|
|
|
|
|
UnRegisterModule($this->MODULE_ID);
|
|
|
|
|
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
GetMessage('MODULE_UNINSTALL_TITLE'), $this->INSTALL_PATH . '/unstep1.php'
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
}
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
function CopyFiles()
|
|
|
|
|
{
|
2013-10-30 17:01:34 +04:00
|
|
|
|
CopyDirFiles(
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/export/', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/', true, true
|
2013-10-30 17:01:34 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
function DeleteFiles()
|
|
|
|
|
{
|
2014-11-27 18:37:59 +03:00
|
|
|
|
$rsSites = CSite::GetList($by, $sort, array('DEF' => 'Y'));
|
|
|
|
|
$defaultSite = array();
|
|
|
|
|
while ($ar = $rsSites->Fetch()) {
|
|
|
|
|
$defaultSite = $ar;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
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/');
|
2013-10-30 17:01:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 16:55:04 +04:00
|
|
|
|
function GetProfileSetupVars($iblocks, $propertiesProduct, $propertiesUnitProduct, $propertiesSKU, $propertiesUnitSKU, $filename) {
|
2013-10-30 17:01:34 +04:00
|
|
|
|
$strVars = "";
|
|
|
|
|
foreach ($iblocks as $key => $val)
|
|
|
|
|
$strVars .= 'IBLOCK_EXPORT[' . $key . ']=' . $val . '&';
|
|
|
|
|
foreach ($propertiesSKU as $iblock => $arr)
|
|
|
|
|
foreach ($arr as $id => $val)
|
|
|
|
|
$strVars .= 'IBLOCK_PROPERTY_SKU_' . $id . '[' . $iblock . ']=' . $val . '&';
|
2014-01-23 16:55:04 +04:00
|
|
|
|
foreach ($propertiesUnitSKU as $iblock => $arr)
|
|
|
|
|
foreach ($arr as $id => $val)
|
|
|
|
|
$strVars .= 'IBLOCK_PROPERTY_UNIT_SKU_' . $id . '[' . $iblock . ']=' . $val . '&';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
foreach ($propertiesProduct as $iblock => $arr)
|
|
|
|
|
foreach ($arr as $id => $val)
|
|
|
|
|
$strVars .= 'IBLOCK_PROPERTY_PRODUCT_' . $id . '[' . $iblock . ']=' . $val . '&';
|
2014-01-23 16:55:04 +04:00
|
|
|
|
foreach ($propertiesUnitProduct as $iblock => $arr)
|
|
|
|
|
foreach ($arr as $id => $val)
|
|
|
|
|
$strVars .= 'IBLOCK_PROPERTY_UNIT_PRODUCT_' . $id . '[' . $iblock . ']=' . $val . '&';
|
2013-10-30 17:01:34 +04:00
|
|
|
|
|
|
|
|
|
$strVars .= 'SETUP_FILE_NAME=' . urlencode($filename);
|
|
|
|
|
|
|
|
|
|
return $strVars;
|
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
function historyLoad($api, $method)
|
|
|
|
|
{
|
2016-09-16 11:46:44 +03:00
|
|
|
|
$page = null;
|
|
|
|
|
$i = 0;
|
2016-10-04 17:57:39 +03:00
|
|
|
|
while (true) {
|
2016-09-16 11:46:44 +03:00
|
|
|
|
$i++;
|
2016-09-15 16:42:10 +03:00
|
|
|
|
try {
|
2016-09-16 11:46:44 +03:00
|
|
|
|
$history = $api->$method(array(), $page);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
} catch (\RetailCrm\Exception\CurlException $e) {
|
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'RetailCrmHistory::' . $method, 'RetailCrm\RestApi::' . $method . '::CurlException',
|
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
|
);
|
|
|
|
|
$end['id'] = 0;
|
|
|
|
|
|
|
|
|
|
return $end['id'];
|
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
|
'RetailCrmHistory::' . $method, 'RetailCrm\RestApi::' . $method . '::InvalidArgumentException',
|
|
|
|
|
$e->getCode() . ': ' . $e->getMessage()
|
|
|
|
|
);
|
|
|
|
|
$end['id'] = 0;
|
|
|
|
|
|
|
|
|
|
return $end['id'];
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if (isset($history['history'])) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$end = array_pop($history['history']);
|
2016-10-04 17:57:39 +03:00
|
|
|
|
} else {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
$end['id'] = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
|
if ($history['pagination']['totalPageCount'] == $history['pagination']['currentPage']) {
|
2016-09-15 16:42:10 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 11:46:44 +03:00
|
|
|
|
$page = $history['pagination']['totalPageCount'];
|
2016-09-15 16:42:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $end['id'];
|
|
|
|
|
}
|
2013-08-14 12:12:09 +04:00
|
|
|
|
}
|