GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID; $CRM_API_HOST_OPTION = 'api_host'; $CRM_API_KEY_OPTION = 'api_key'; $CRM_ORDER_TYPES_ARR = 'order_types_arr'; $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr'; $CRM_PAYMENT_TYPES = 'pay_types_arr'; $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; $CRM_PAYMENT = 'payment_arr'; //order payment Y/N $CRM_ORDER_LAST_ID = 'order_last_id'; $CRM_ORDER_SITES = 'sites_ids'; $CRM_ORDER_DISCHARGE = 'order_discharge'; $CRM_ORDER_PROPS = 'order_props'; $CRM_LEGAL_DETAILS = 'legal_details'; $CRM_CUSTOM_FIELDS = 'custom_fields'; $CRM_CONTRAGENT_TYPE = 'contragent_type'; $CRM_SITES_LIST= 'sites_list'; $CRM_ORDER_NUMBERS = 'order_numbers'; $CRM_CANSEL_ORDER = 'cansel_order'; $CRM_INVENTORIES_UPLOAD = 'inventories_upload'; $CRM_STORES = 'stores'; $CRM_SHOPS = 'shops'; $CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories'; $CRM_PRICES_UPLOAD = 'prices_upload'; $CRM_PRICES = 'prices'; $CRM_PRICE_SHOPS = 'price_shops'; $CRM_IBLOCKS_PRICES = 'iblock_prices'; $CRM_COLLECTOR = 'collector'; $CRM_COLL_KEY = 'coll_key'; $CRM_UA = 'ua'; $CRM_UA_KEYS = 'ua_keys'; $CRM_DISCOUNT_ROUND = 'discount_round'; $CRM_CC = 'cc'; $CRM_CORP_SHOPS = 'shops-corporate'; $CRM_CORP_NAME = 'nickName-corporate'; $CRM_CORP_ADRES = 'adres-corporate'; $CRM_API_VERSION = 'api_version'; $CRM_CURRENCY = 'currency'; $CRM_ADDRESS_OPTIONS = 'address_options'; $CRM_DIMENSIONS = 'order_dimensions'; $PROTOCOL = 'protocol'; $CRM_PURCHASE_PRICE_NULL = 'purchasePrice_null'; if(!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog')) return; $_GET['errc'] = htmlspecialchars(trim($_GET['errc'])); $_GET['ok'] = htmlspecialchars(trim($_GET['ok'])); if($_GET['errc']) echo CAdminMessage::ShowMessage(GetMessage($_GET['errc'])); if($_GET['ok'] && $_GET['ok'] == 'Y') echo CAdminMessage::ShowNote(GetMessage('ICRM_OPTIONS_OK')); $arResult = array(); if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml')) { $options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml'); foreach($options->contragents->contragent as $contragent) { $type["NAME"] = $APPLICATION->ConvertCharset((string)$contragent, 'utf-8', SITE_CHARSET); $type["ID"] = (string)$contragent["id"]; $arResult['contragentType'][] = $type; unset ($type); } foreach($options->fields->field as $field) { $type["NAME"] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET); $type["ID"] = (string)$field["id"]; if ($field["group"] == 'custom') { $arResult['customFields'][] = $type; } elseif (!$field["group"]) { $arResult['orderProps'][] = $type; } else { $groups = explode(",", (string)$field["group"]); foreach ($groups as $group) { $type["GROUP"][] = trim($group); } $arResult['legalDetails'][] = $type; } unset($type); } } $arResult['arSites'] = RCrmActions::SitesList(); //ajax update deliveryServices if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0); $api = new RetailCrm\ApiClient($api_host, $api_key); try { $api->paymentStatusesList(); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException', $e->getCode() . ': ' . $e->getMessage() ); $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode(array('success' => false, 'errMsg' => $e->getCode()))); } $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList(); foreach ($optionsDelivTypes as $key => $deliveryType) { foreach ($arDeliveryServiceAll as $deliveryService) { if ($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] == $key) { $srv = explode(':', $deliveryService['CODE']); if (count($srv) == 2) { try { $api->deliveryServicesEdit(RCrmActions::clearArr(array( 'code' => $srv[1], 'name' => RCrmActions::toJSON($deliveryService['NAME']), 'deliveryType' => $deliveryType ))); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException', $e->getCode() . ': ' . $e->getMessage() ); } } } } } $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode(array('success' => true))); } //upload orders after install module if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && $_POST['ajax'] == 2) { $step = $_POST['step']; $orders = $_POST['orders']; $countStep = 50; // 50 orders on step if ($orders) { $ordersArr = explode(',', $orders); $orders = array(); foreach ($ordersArr as $_ordersArr) { $ordersList = explode('-', trim($_ordersArr)); if (count($ordersList) > 1) { for ($i = (int)trim($ordersList[0]); $i <= (int)trim($ordersList[count($ordersList) - 1]); $i++) { $orders[] = $i; } } else{ $orders[] = (int)$ordersList[0]; } } $splitedOrders = array_chunk($orders, $countStep); $stepOrders = $splitedOrders[$step]; RetailCrmOrder::uploadOrders($countStep, false, $stepOrders); $percent = round((($step * $countStep + count($stepOrders)) * 100 / count($orders)), 1); $step++; if (!$splitedOrders[$step]) { $step = 'end'; } $res = array("step" => $step, "percent" => $percent, 'stepOrders' => $stepOrders); } else { $orders = array(); for($i = 1; $i <= $countStep; $i++){ $orders[] = $i + $step * $countStep; } RetailCrmOrder::uploadOrders($countStep, false, $orders); $step++; $countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $step * $countStep), array()); $countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array()); $percent = round(100 - ($countLeft * 100 / $countAll), 1); if ($countLeft == 0) { $step = 'end'; } $res = array("step" => $step, "percent" => $percent, 'stepOrders' => $orders); } $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode($res)); } //update connection settings if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $api_host = htmlspecialchars(trim($_POST['api_host'])); $api_key = htmlspecialchars(trim($_POST['api_key'])); //bitrix site list $siteListArr = array(); foreach ($arResult['arSites'] as $arSites) { if (count($arResult['arSites']) > 1) { if ($_POST['sites-id-' . $arSites['LID']]) { $siteListArr[$arSites['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $arSites['LID']])); } else { $siteListArr[$arSites['LID']] = null; } } } if ($api_host && $api_key) { $api = new RetailCrm\ApiClient($api_host, $api_key); try { $api->paymentStatusesList(); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException', $e->getCode() . ': ' . $e->getMessage() ); $uri .= '&errc=ERR_' . $e->getCode(); LocalRedirect($uri); } COption::SetOptionString($mid, 'api_host', $api_host); COption::SetOptionString($mid, 'api_key', $api_key); } //form order types ids arr $orderTypesList = RCrmActions::OrderTypesList($arResult['arSites']); $orderTypesArr = array(); foreach ($orderTypesList as $orderType) { $orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']])); } //form delivery types ids arr $arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList(); $deliveryTypesArr = array(); foreach ($arResult['bitrixDeliveryTypesList'] as $delivery) { $deliveryTypesArr[$delivery['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $delivery['ID']])); } //form payment types ids arr $arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList(); $paymentTypesArr = array(); foreach ($arResult['bitrixPaymentTypesList'] as $payment) { $paymentTypesArr[$payment['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $payment['ID']])); } //form payment statuses ids arr $arResult['bitrixStatusesList'] = RCrmActions::StatusesList(); $paymentStatusesArr = array(); $canselOrderArr = array(); //$paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY'])); foreach ($arResult['bitrixStatusesList'] as $status) { $paymentStatusesArr[$status['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $status['ID']])); if (trim($_POST['order-cansel-' . $status['ID']]) == 'Y') { $canselOrderArr[] = $status['ID']; } } //form payment ids arr $paymentArr = array(); $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); $previousDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); //order discharge mode // 0 - agent // 1 - event $orderDischarge = 0; $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { // remove depenedencies UnRegisterModuleDependences("sale", \Bitrix\sale\EventActions::EVENT_ON_ORDER_SAVED, $mid, "RetailCrmEvent", "orderSave"); UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); UnRegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete"); } elseif (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { // event dependencies RegisterModuleDependences("sale", \Bitrix\sale\EventActions::EVENT_ON_ORDER_SAVED, $mid, "RetailCrmEvent", "orderSave"); RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnSaleOrderDeleted", $mid, "RetailCrmEvent", "orderDelete"); } $orderPropsArr = array(); foreach ($orderTypesList as $orderType) { $propsCount = 0; $_orderPropsArr = array(); foreach ($arResult['orderProps'] as $orderProp) { if (isset($_POST['address-detail-' . $orderType['ID']])) { $addressDatailOptions[$orderType['ID']] = $_POST['address-detail-' . $orderType['ID']]; } if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4) { break; } $_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']])); $propsCount++; } $orderPropsArr[$orderType['ID']] = $_orderPropsArr; } //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']])); } //order numbers $orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ? htmlspecialchars(trim($_POST['order-numbers'])) : 'N'; $orderDimensions = htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) ? htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) : 'N'; //stores $bitrixStoresArr = array(); $bitrixShopsArr = array(); $bitrixIblocksInventories = array(); if(htmlspecialchars(trim($_POST['inventories-upload'])) == 'Y'){ $inventoriesUpload = 'Y'; $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; $dateAgent->add($intAgent); CAgent::AddAgent( "RetailCrmInventories::inventoriesUpload();", $mid, "N", 3600, // interval - 1 ��� $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 ); $arResult['bitrixStoresExportList'] = RCrmActions::StoresExportList(); foreach($arResult['bitrixStoresExportList'] as $bitrixStores){ $bitrixStoresArr[$bitrixStores['ID']] = htmlspecialchars(trim($_POST['stores-export-' . $bitrixStores['ID']])); } function maskInv($var){ return preg_match("/^shops-exoprt/", $var); } $bitrixShopsArr = str_replace('shops-exoprt-', '', array_filter(array_keys($_POST), 'maskInv')); $arResult['bitrixIblocksExportList'] = RCrmActions::IblocksExportList(); foreach($arResult['bitrixIblocksExportList'] as $bitrixIblocks){ if(htmlspecialchars(trim($_POST['iblocks-stores-' . $bitrixIblocks['ID']])) === 'Y'){ $bitrixIblocksInventories[] = $bitrixIblocks['ID']; } } } else { $inventoriesUpload = 'N'; CAgent::RemoveAgent("RetailCrmInventories::inventoriesUpload();", $mid); } //prices $bitrixPricesArr = array(); $bitrixIblocksPrices = array(); $bitrixPriceShopsArr = array(); if(htmlspecialchars(trim($_POST['prices-upload'])) == 'Y'){ $pricesUpload = 'Y'; $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; $dateAgent->add($intAgent); CAgent::AddAgent( "RetailCrmPrices::pricesUpload();", $mid, "N", 86400, // interval - 24 ���� $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 ); $arResult['bitrixPricesExportList'] = RCrmActions::PricesExportList(); foreach($arResult['bitrixPricesExportList'] as $bitrixPrices){ $bitrixPricesArr[$bitrixPrices['ID']] = htmlspecialchars(trim($_POST['price-type-export-' . $bitrixPrices['ID']])); } function maskPrice($var){ return preg_match("/^shops-price/", $var); } $bitrixPriceShopsArr = str_replace('shops-price-', '', array_filter(array_keys($_POST), 'maskPrice')); $arResult['bitrixIblocksExportList'] = RCrmActions::IblocksExportList(); foreach($arResult['bitrixIblocksExportList'] as $bitrixIblocks){ if(htmlspecialchars(trim($_POST['iblocks-prices-' . $bitrixIblocks['ID']])) === 'Y'){ $bitrixIblocksPrices[] = $bitrixIblocks['ID']; } } } else { $pricesUpload = 'N'; CAgent::RemoveAgent("RetailCrmPrices::pricesUpload();", $mid); } //demon $collectorKeys = array(); if (htmlspecialchars(trim($_POST['collector'])) == 'Y') { $collector = 'Y'; foreach ($arResult['arSites'] as $site) { $collectorKeys[$site['LID']] = trim($_POST['collector-id-' . $site['LID']]); } RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmCollector", "add"); } else { $collector = 'N'; UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmCollector", "add"); } //UA $uaKeys = array(); if (htmlspecialchars(trim($_POST['ua-integration'])) == 'Y') { $ua = 'Y'; foreach ($arResult['arSites'] as $site) { $uaKeys[$site['LID']]['ID'] = trim($_POST['ua-id-' . $site['LID']]); $uaKeys[$site['LID']]['INDEX'] = trim($_POST['ua-index-' . $site['LID']]); } RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmUa", "add"); } else { $ua = 'N'; UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmUa", "add"); } //discount_round if (htmlspecialchars(trim($_POST['discount_round'])) == 'Y') { $discount_round = 'Y'; RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmDc", "add"); } else { $discount_round = 'N'; UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmDc", "add"); } //corporate-cliente if (htmlspecialchars(trim($_POST['corp-client'])) == 'Y') { $cc = 'Y'; $bitrixCorpName = htmlspecialchars(trim($_POST['nickName-corporate'])); $bitrixCorpAdres = htmlspecialchars(trim($_POST['adres-corporate'])); function maskCorp($var) { return preg_match("/^shops-corporate/", $var); } $bitrixCorpShopsArr = str_replace('shops-corporate-', '', array_filter(array_keys($_POST), 'maskCorp')); RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmCc", "add"); } else { $cc = 'N'; UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmCc", "add"); } //purchasePrice_null if (htmlspecialchars(trim($_POST['purchasePrice_null'])) == 'Y') { $purchasePrice_null = 'Y'; RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmPricePrchase", "add"); } else { $purchasePrice_null = 'N'; UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmPricePrchase", "add"); } //version $version = COption::GetOptionString($mid, $CRM_API_VERSION); if (htmlspecialchars(trim($_POST['api_version'])) != $version) { if (htmlspecialchars(trim($_POST['api_version'])) == 'v4') { $version = 'v4'; } elseif (htmlspecialchars(trim($_POST['api_version'])) == 'v5') { $version = 'v5'; } else { LocalRedirect($uri); echo CAdminMessage::ShowMessage(GetMessage('API_NOT_FOUND')); } //������ � ��� � $version $crmUrl = htmlspecialchars(trim($_POST['api_host'])); $apiKey = htmlspecialchars(trim($_POST['api_key'])); if ('/' !== $crmUrl[strlen($crmUrl) - 1]) { $crmUrl .= '/'; } $crmUrl = $crmUrl . 'api/' . $version; $client = new RetailCrm\Http\Client($crmUrl, array('apiKey' => $apiKey)); $result = $client->makeRequest( '/reference/payment-statuses', 'GET' ); if ($result->getStatusCode() == 200) { COption::SetOptionString($mid, $CRM_API_VERSION, $version); } else { LocalRedirect($uri); echo CAdminMessage::ShowMessage(GetMessage('API_NOT_WORK')); } } if ($_POST[$CRM_CURRENCY]) { COption::SetOptionString($mid, $CRM_CURRENCY, $_POST['currency']); } COption::SetOptionString($mid, $CRM_ADDRESS_OPTIONS, serialize($addressDatailOptions)); COption::SetOptionString($mid, $CRM_SITES_LIST, serialize($siteListArr)); COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr))); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr))); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr))); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr))); COption::SetOptionString($mid, $CRM_PAYMENT, serialize(RCrmActions::clearArr($paymentArr))); COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge); COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr))); COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr))); COption::SetOptionString($mid, $CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr))); COption::SetOptionString($mid, $CRM_CUSTOM_FIELDS, serialize(RCrmActions::clearArr($customFieldsArr))); COption::SetOptionString($mid, $CRM_ORDER_NUMBERS, $orderNumbers); COption::SetOptionString($mid, $CRM_CANSEL_ORDER, serialize(RCrmActions::clearArr($canselOrderArr))); COption::SetOptionString($mid, $CRM_INVENTORIES_UPLOAD, $inventoriesUpload); COption::SetOptionString($mid, $CRM_STORES, serialize(RCrmActions::clearArr($bitrixStoresArr))); COption::SetOptionString($mid, $CRM_SHOPS, serialize(RCrmActions::clearArr($bitrixShopsArr))); COption::SetOptionString($mid, $CRM_IBLOCKS_INVENTORIES, serialize(RCrmActions::clearArr($bitrixIblocksInventories))); COption::SetOptionString($mid, $CRM_PRICES_UPLOAD, $pricesUpload); COption::SetOptionString($mid, $CRM_PRICES, serialize(RCrmActions::clearArr($bitrixPricesArr))); COption::SetOptionString($mid, $CRM_PRICE_SHOPS, serialize(RCrmActions::clearArr($bitrixPriceShopsArr))); COption::SetOptionString($mid, $CRM_IBLOCKS_PRICES, serialize(RCrmActions::clearArr($bitrixIblocksPrices))); COption::SetOptionString($mid, $CRM_COLLECTOR, $collector); COption::SetOptionString($mid, $CRM_COLL_KEY, serialize(RCrmActions::clearArr($collectorKeys))); COption::SetOptionString($mid, $CRM_UA, $ua); COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys))); COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions); COption::SetOptionString($mid, $CRM_DISCOUNT_ROUND, $discount_round); COption::SetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, $purchasePrice_null); COption::SetOptionString($mid, $CRM_CC, $cc); COption::SetOptionString($mid, $CRM_CORP_SHOPS, serialize(RCrmActions::clearArr($bitrixCorpShopsArr))); COption::SetOptionString($mid, $CRM_CORP_NAME, serialize(RCrmActions::clearArr($bitrixCorpName))); COption::SetOptionString($mid, $CRM_CORP_ADRES, serialize(RCrmActions::clearArr($bitrixCorpAdres))); $request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest(); if ($request->isHttps() === true) { COption::SetOptionString($mid, $PROTOCOL, 'https://'); } else { COption::SetOptionString($mid, $PROTOCOL, 'http://'); } $uri .= '&ok=Y'; LocalRedirect($uri); } else { $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0); $api = new RetailCrm\ApiClient($api_host, $api_key); //prepare crm lists try { $arResult['orderTypesList'] = $api->orderTypesList()->orderTypes; $arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes; $arResult['deliveryServicesList'] = $api->deliveryServicesList()->deliveryServices; $arResult['paymentTypesList'] = $api->paymentTypesList()->paymentTypes; $arResult['paymentStatusesList'] = $api->paymentStatusesList()->paymentStatuses; // --statuses $arResult['paymentList'] = $api->statusesList()->statuses; $arResult['paymentGroupList'] = $api->statusGroupsList()->statusGroups; // -- statuses groups $arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($api->sitesList()->sites, 'utf-8', SITE_CHARSET); $arResult['inventoriesList'] = $APPLICATION->ConvertCharsetArray($api->storesList()->stores, 'utf-8', SITE_CHARSET); $arResult['priceTypeList'] = $APPLICATION->ConvertCharsetArray($api->pricesTypes()->priceTypes, 'utf-8', SITE_CHARSET); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException', $e->getCode() . ': ' . $e->getMessage() ); echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode())); } catch (InvalidArgumentException $e) { $badKey = true; echo CAdminMessage::ShowMessage(GetMessage('ERR_403')); } catch (\RetailCrm\Exception\InvalidJsonException $e) { $badJson = true; echo CAdminMessage::ShowMessage(GetMessage('ERR_JSON')); } $delivTypes = array(); foreach ($arResult['deliveryTypesList'] as $delivType) { if ($delivType['active'] === true) { $delivTypes[$delivType['code']] = $delivType; } } $arResult['deliveryTypesList'] = $delivTypes; //bitrix orderTypesList -- personTypes $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); //bitrix deliveryTypesList $arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList(); //bitrix paymentTypesList $arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList(); //bitrix statusesList $arResult['bitrixPaymentStatusesList'] = RCrmActions::StatusesList(); //bitrix pyament Y/N $arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y'); $arResult['bitrixPaymentList'][0]['ID'] = 'Y'; $arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N'); $arResult['bitrixPaymentList'][1]['ID'] = 'N'; //bitrix orderPropsList $arResult['arProp'] = RCrmActions::OrderPropsList(); $arResult['bitrixIblocksExportList'] = RCrmActions::IblocksExportList(); $arResult['bitrixStoresExportList'] = RCrmActions::StoresExportList(); $arResult['bitrixPricesExportList'] = RCrmActions::PricesExportList(); //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0)); $optionsSitesList = unserialize(COption::GetOptionString($mid, $CRM_SITES_LIST, 0)); $optionsDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); $optionsOrderProps = unserialize(COption::GetOptionString($mid, $CRM_ORDER_PROPS, 0)); $optionsContragentType = unserialize(COption::GetOptionString($mid, $CRM_CONTRAGENT_TYPE, 0)); $optionsLegalDetails = unserialize(COption::GetOptionString($mid, $CRM_LEGAL_DETAILS, 0)); $optionsCustomFields = unserialize(COption::GetOptionString($mid, $CRM_CUSTOM_FIELDS, 0)); $optionsOrderNumbers = COption::GetOptionString($mid, $CRM_ORDER_NUMBERS, 0); $canselOrderArr = unserialize(COption::GetOptionString($mid, $CRM_CANSEL_ORDER, 0)); $optionInventotiesUpload = COption::GetOptionString($mid, $CRM_INVENTORIES_UPLOAD, 0); $optionStores = unserialize(COption::GetOptionString($mid, $CRM_STORES, 0)); $optionShops = unserialize(COption::GetOptionString($mid, $CRM_SHOPS, 0)); $optionIblocksInventories = unserialize(COption::GetOptionString($mid, $CRM_IBLOCKS_INVENTORIES, 0)); $optionShopsCorporate = unserialize(COption::GetOptionString($mid, $CRM_SHOPS, 0)); $optionPricesUpload = COption::GetOptionString($mid, $CRM_PRICES_UPLOAD, 0); $optionPrices = unserialize(COption::GetOptionString($mid, $CRM_PRICES, 0)); $optionPriceShops = unserialize(COption::GetOptionString($mid, $CRM_PRICE_SHOPS, 0)); $optionIblocksPrices = unserialize(COption::GetOptionString($mid, $CRM_IBLOCKS_PRICES, 0)); $optionCollector = COption::GetOptionString($mid, $CRM_COLLECTOR, 0); $optionCollectorKeys = unserialize(COption::GetOptionString($mid, $CRM_COLL_KEY)); $optionUa = COption::GetOptionString($mid, $CRM_UA, 0); $optionUaKeys = unserialize(COption::GetOptionString($mid, $CRM_UA_KEYS)); $optionDiscRound = COption::GetOptionString($mid, $CRM_DISCOUNT_ROUND, 0); $optionPricePrchaseNull = COption::GetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, 0); //corporate-cliente $optionCorpClient = COption::GetOptionString($mid, $CRM_CC, 0); $optionCorpShops = unserialize(COption::GetOptionString($mid, $CRM_CORP_SHOPS, 0)); $optionsCorpComName = unserialize(COption::GetOptionString($mid, $CRM_CORP_NAME, 0)); $optionsCorpAdres = unserialize(COption::GetOptionString($mid, $CRM_CORP_ADRES, 0)); $version = COption::GetOptionString($mid, $CRM_API_VERSION, 0); //currency $baseCurrency = \Bitrix\Currency\CurrencyManager::getBaseCurrency(); $currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ? COption::GetOptionString($mid, $CRM_CURRENCY, 0) : $baseCurrency; $currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList(); $optionsOrderDimensions = COption::GetOptionString($mid, $CRM_DIMENSIONS, 'N'); $addressOptions = unserialize(COption::GetOptionString($mid, $CRM_ADDRESS_OPTIONS, 0)); $aTabs = array( array( "DIV" => "edit1", "TAB" => GetMessage('ICRM_OPTIONS_GENERAL_TAB'), "ICON" => "", "TITLE" => GetMessage('ICRM_OPTIONS_GENERAL_CAPTION') ), array( "DIV" => "edit2", "TAB" => GetMessage('ICRM_OPTIONS_CATALOG_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION') ), array( "DIV" => "edit3", "TAB" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_CAPTION') ), array( "DIV" => "edit4", "TAB" => GetMessage('OTHER_OPTIONS'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION') ) ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> AddHeadString(''); ?>