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'; $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_COUPON_FIELD = 'crm_coupon_field'; $CRM_CONTRAGENT_TYPE = 'contragent_type'; $CRM_SITES_LIST = 'sites_list'; $CRM_ORDER_NUMBERS = 'order_numbers'; $CRM_ORDER_VAT = 'order_vat'; $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'; $CRM_CART = 'cart'; $MODULE_DEACTIVATE = 'module_deactivate'; $AGENTS_DEACTIVATE = 'agents_deactivate'; $EVENTS_DEACTIVATE = 'events_deactivate'; 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 (RetailcrmConfigProvider::isPhoneRequired()) { echo ShowMessage(["TYPE" => "ERROR", "MESSAGE" => GetMessage('PHONE_REQUIRED')]); } if (array_key_exists('errc', $_GET) && is_string($_GET['errc']) && strlen($_GET['errc']) > 0) { echo CAdminMessage::ShowMessage(GetMessage($_GET['errc'])); } if (!empty($_GET['ok']) && $_GET['ok'] === 'Y') { echo CAdminMessage::ShowNote(GetMessage('ICRM_OPTIONS_OK')); } $arResult = []; 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::getSitesList(); $arResult['arCurrencySites'] = RCrmActions::getCurrencySites(); //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 (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(['success' => false, 'errMsg' => $e->getCode()])); } $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $arDeliveryServiceAll = Manager::getActiveList(); foreach ($optionsDelivTypes as $key => $deliveryType) { foreach ($arDeliveryServiceAll as $deliveryService) { if ($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] === $key) { try { $api->deliveryServicesEdit(RCrmActions::clearArr([ 'code' => 'bitrix-' . $deliveryService['ID'], 'name' => RCrmActions::toJSON($deliveryService['NAME']), 'deliveryType' => $deliveryType, ])); } catch (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(['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 = []; 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 = ["step" => $step, "percent" => $percent, 'stepOrders' => $stepOrders]; } else { $orders = []; for ($i = 1; $i <= $countStep; $i++) { $orders[] = $i + $step * $countStep; } RetailCrmOrder::uploadOrders($countStep, false, $orders); $step++; $countLeft = (int)CSaleOrder::GetList(["ID" => "ASC"], ['>ID' => $step * $countStep], []); $countAll = (int)CSaleOrder::GetList(["ID" => "ASC"], [], []); $percent = round(100 - ($countLeft * 100 / $countAll), 1); if ($countLeft === 0) { $step = 'end'; } $res = ["step" => $step, "percent" => $percent, 'stepOrders' => $orders]; } $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode($res)); } $availableSites = RetailcrmConfigProvider::getSitesList(); if (!empty($availableSites)) { $availableSites = array_flip($availableSites); } else { $site = RetailcrmConfigProvider::getSitesAvailable(); $availableSites[$site] = $site; } //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 = []; 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 ClientAdapter($api_host, $api_key); try { $credentials = $api->getCredentials(); if (!empty($credentials->errorMsg)) { $uri .= '&errc=ERR_' . $credentials->errorMsg; LocalRedirect($uri); } ConfigProvider::setSitesAvailable( count($credentials->sitesAvailable) > 0 ? $credentials->sitesAvailable[0] : '' ); } catch (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); } else { $uri .= '&errc=ERR_WRONG_CREDENTIALS'; LocalRedirect($uri); } //form order types ids arr $orderTypesList = RCrmActions::OrderTypesList($arResult['arSites']); $orderTypesArr = []; foreach ($orderTypesList as $orderType) { $orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']])); } //form delivery types ids arr $arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList(); $deliveryTypesArr = []; 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 = []; 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 = []; $canselOrderArr = []; 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 = []; $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 = (int) htmlspecialchars(trim($_POST['order-discharge'])); if (($orderDischarge != $previousDischarge) && ($orderDischarge === 0)) { // remove depenedencies UnRegisterModuleDependences('sale', 'OnOrderUpdate', $mid, 'RetailCrmEvent', "onUpdateOrder"); UnRegisterModuleDependences('sale', 'OnSaleOrderDeleted', $mid, 'RetailCrmEvent', "orderDelete"); } elseif (($orderDischarge != $previousDischarge) && ($orderDischarge === 1)) { // event dependencies RegisterModuleDependences('sale', 'OnOrderUpdate', $mid, 'RetailCrmEvent', "onUpdateOrder"); RegisterModuleDependences('sale', 'OnSaleOrderDeleted', $mid, 'RetailCrmEvent', "orderDelete"); } $optionCart = COption::GetOptionString($mid, $CRM_CART, 'N'); $cart = htmlspecialchars(trim($_POST['cart'])); if ($cart != $optionCart) { if ($cart === 'Y') { $optionCart = 'Y'; RegisterModuleDependences('sale', 'OnSaleBasketSaved', $mid, 'RetailCrmEvent', 'onChangeBasket'); } else { $optionCart = 'N'; UnRegisterModuleDependences('sale', 'OnSaleBasketSaved', $mid, 'RetailCrmEvent', 'onChangeBasket'); } } $orderPropsArr = []; foreach ($orderTypesList as $orderType) { $propsCount = 0; $_orderPropsArr = []; 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 = []; foreach ($orderTypesList as $orderType) { $_legalDetailsArr = []; foreach ($arResult['legalDetails'] as $legalDetails) { $_legalDetailsArr[$legalDetails['ID']] = htmlspecialchars(trim($_POST['legal-detail-' . $legalDetails['ID'] . '-' . $orderType['ID']])); } $legalDetailsArr[$orderType['ID']] = $_legalDetailsArr; } $customFieldsArr = []; foreach ($orderTypesList as $orderType) { $_customFieldsArr = []; 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 = []; foreach ($orderTypesList as $orderType) { $contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']])); } //stores $bitrixStoresArr = []; $bitrixShopsArr = []; $bitrixIblocksInventories = []; 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 hour $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 = array_values(array_filter($_POST, 'maskInv', ARRAY_FILTER_USE_KEY)); $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 = []; $bitrixIblocksPrices = []; $bitrixPriceShopsArr = []; 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 hours $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 = array_values(array_filter($_POST, 'maskPrice', ARRAY_FILTER_USE_KEY)); $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 = []; 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 = []; 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"); } //online_consultant if (htmlspecialchars(trim($_POST['online_consultant'] === 'Y'))) { $onlineConsultant = 'Y'; $onlineConsultantScript = trim($_POST['online_consultant_script']); RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmOnlineConsultant", "add"); } else { $onlineConsultant = 'N'; $onlineConsultantScript = RetailcrmConfigProvider::getOnlineConsultantScript(); UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmOnlineConsultant", "add"); } //discount_round if (htmlspecialchars(trim($_POST['discount_round'])) === 'Y') { $discount_round = 'Y'; } else { $discount_round = 'N'; } //shipment if (htmlspecialchars(trim($_POST['shipment_deducted'])) === 'Y') { $shipment_deducted = 'Y'; } else { $shipment_deducted = 'N'; } //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 = array_values(array_filter($_POST, 'maskCorp', ARRAY_FILTER_USE_KEY)); } else { $cc = 'N'; } //purchasePrice_null if (htmlspecialchars(trim($_POST['purchasePrice_null'])) === 'Y') { $purchasePrice_null = 'Y'; } else { $purchasePrice_null = 'N'; } //version $version = COption::GetOptionString($mid, $CRM_API_VERSION); if (htmlspecialchars(trim($_POST['api_version'])) != $version) { if (htmlspecialchars(trim($_POST['api_version'])) === 'v5') { $version = 'v5'; } else { LocalRedirect($uri); echo CAdminMessage::ShowMessage(GetMessage('API_NOT_FOUND')); } //api request with $version $crmUrl = htmlspecialchars(trim($_POST['api_host'])); $apiKey = htmlspecialchars(trim($_POST['api_key'])); if ('/' !== $crmUrl[strlen($crmUrl) - 1]) { $crmUrl .= '/'; } $crmUrl .= 'api/' . $version; $client = new RetailCrm\Http\Client($crmUrl, ['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']); } if (isset($_POST['loyalty_toggle']) && $_POST['loyalty_toggle'] === 'on') { try { $hlName = RetailcrmUtils::getHlClassByName(Constants::HL_LOYALTY_CODE); if (empty($hlName)) { OrderLoyaltyDataService::createLoyaltyHlBlock(); } } catch (LoaderException | SystemException $exception) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'OrderLoyaltyDataService::createLoyaltyHlBlock', $e->getCode() . ': ' . $exception->getMessage() ); } ConfigProvider::setLoyaltyProgramStatus('Y'); } else { ConfigProvider::setLoyaltyProgramStatus('N'); } try { $arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes( $availableSites, $api->paymentTypesList()->paymentTypes ); $arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes( $availableSites, $api->deliveryTypesList()->deliveryTypes ); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException', $e->getCode() . ': ' . $e->getMessage() ); CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode())); } $integrationPayments = RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList']); $integrationDeliveries = RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList']); RetailcrmConfigProvider::setIntegrationPaymentTypes($integrationPayments); RetailcrmConfigProvider::setIntegrationDelivery($integrationDeliveries); $moduleDeactivateParam = htmlspecialchars(trim($_POST['module-deactivate'])) ?? 'N'; if ('Y' === $moduleDeactivateParam) { global $DB; $agents = $DB->Query("SELECT * FROM `b_agent` WHERE `MODULE_ID` = 'intaro.retailcrm';"); $events = $DB->Query("SELECT * FROM `b_module_to_module` WHERE `TO_MODULE_ID` = 'intaro.retailcrm';"); $deactivateAgents = []; $deactivateEvents = []; // Fetch - If the last record is reached (or there are no records as a result), the method returns false while ($agent = $agents->Fetch()) { $deactivateAgents[] = $agent; CAgent::RemoveAgent($agent['NAME'], $agent['MODULE_ID'], $agent['USER_ID']); } // Fetch - If the last record is reached (or there are no records as a result), the method returns false while ($event = $events->Fetch()) { $deactivateEvents[] = $event; UnRegisterModuleDependences( $event['FROM_MODULE_ID'], $event['MESSAGE_ID'], $event['TO_MODULE_ID'], $event['TO_CLASS'], $event['TO_METHOD'] ); } if ($deactivateAgents !== []) { COption::SetOptionString($mid, $AGENTS_DEACTIVATE, serialize($deactivateAgents)); } if ($deactivateEvents !== []) { COption::SetOptionString($mid, $EVENTS_DEACTIVATE, serialize($deactivateEvents)); } RCrmActions::sendConfiguration($api, false); } else { $deactivateAgents = unserialize(COption::GetOptionString($mid, $AGENTS_DEACTIVATE, '')); $deactivateEvents = unserialize(COption::GetOptionString($mid, $EVENTS_DEACTIVATE, '')); if (!empty($deactivateAgents)) { $dateAgent = new DateTime(); // PT60S - 60 sec; $dateAgent->add(new DateInterval('PT60S')); foreach ($deactivateAgents as $agent) { CAgent::AddAgent( $agent['NAME'], $agent['MODULE_ID'], 'N', $agent['AGENT_INTERVAL'], $dateAgent->format('d.m.Y H:i:s'), $agent['ACTIVE'], $dateAgent->format('d.m.Y H:i:s') ); } COption::SetOptionString($mid, $AGENTS_DEACTIVATE, serialize([])); } if (!empty($deactivateEvents)) { $eventManager = EventManager::getInstance(); foreach ($deactivateEvents as $event) { if (strpos($event['TO_METHOD'], 'Handler') !== false) { $eventManager->registerEventHandler( $event['FROM_MODULE_ID'], $event['MESSAGE_ID'], $event['TO_MODULE_ID'], $event['TO_CLASS'], $event['TO_METHOD'] ); } else { RegisterModuleDependences( $event['FROM_MODULE_ID'], $event['MESSAGE_ID'], $event['TO_MODULE_ID'], $event['TO_CLASS'], $event['TO_METHOD'] ); } } COption::SetOptionString($mid, $EVENTS_DEACTIVATE, serialize([])); } RCrmActions::sendConfiguration($api); } COption::SetOptionString( $mid, $MODULE_DEACTIVATE, serialize($moduleDeactivateParam) ); 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(is_array($orderTypesArr) ? $orderTypesArr : [])) ); COption::SetOptionString( $mid, $CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr(is_array($deliveryTypesArr) ? $deliveryTypesArr : [])) ); COption::SetOptionString( $mid, $CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr(is_array($paymentTypesArr) ? $paymentTypesArr : [])) ); COption::SetOptionString( $mid, $CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr(is_array($paymentStatusesArr) ? $paymentStatusesArr : [])) ); COption::SetOptionString( $mid, $CRM_PAYMENT, serialize(RCrmActions::clearArr(is_array($paymentArr) ? $paymentArr : [])) ); COption::SetOptionString( $mid, $CRM_ORDER_DISCHARGE, $orderDischarge ); COption::SetOptionString( $mid, $CRM_ORDER_PROPS, serialize(RCrmActions::clearArr(is_array($orderPropsArr) ? $orderPropsArr : [])) ); COption::SetOptionString( $mid, $CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr(is_array($contragentTypeArr) ? $contragentTypeArr : [])) ); COption::SetOptionString( $mid, $CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr(is_array($legalDetailsArr) ? $legalDetailsArr : [])) ); COption::SetOptionString( $mid, $CRM_CUSTOM_FIELDS, serialize(RCrmActions::clearArr(is_array($customFieldsArr) ? $customFieldsArr : [])) ); COption::SetOptionString( $mid, $CRM_ORDER_NUMBERS, htmlspecialchars(trim($_POST['order-numbers'])) ?: 'N' ); COption::SetOptionString( $mid, $CRM_ORDER_VAT, htmlspecialchars(trim($_POST['order-vat'])) ?: 'N' ); COption::SetOptionString( $mid, $CRM_COUPON_FIELD, htmlspecialchars(trim($_POST['crm-coupon-field'])) ?: 'N' ); COption::SetOptionString( $mid, Constants::CRM_SEND_PICKUP_POINT_ADDRESS, htmlspecialchars(trim($_POST['send-pickup-point-address'])) ?: 'N' ); COption::SetOptionString( $mid, $CRM_CANSEL_ORDER, serialize(RCrmActions::clearArr(is_array($canselOrderArr) ? $canselOrderArr : [])) ); COption::SetOptionString( $mid, $CRM_INVENTORIES_UPLOAD, $inventoriesUpload ); COption::SetOptionString( $mid, $CRM_STORES, serialize(RCrmActions::clearArr(is_array($bitrixStoresArr) ? $bitrixStoresArr : [])) ); COption::SetOptionString( $mid, $CRM_SHOPS, serialize(RCrmActions::clearArr(is_array($bitrixShopsArr) ? $bitrixShopsArr : [])) ); COption::SetOptionString( $mid, $CRM_IBLOCKS_INVENTORIES, serialize(RCrmActions::clearArr(is_array($bitrixIblocksInventories) ? $bitrixIblocksInventories : [])) ); COption::SetOptionString( $mid, $CRM_PRICES_UPLOAD, $pricesUpload ); COption::SetOptionString( $mid, $CRM_PRICES, serialize(RCrmActions::clearArr(is_array($bitrixPricesArr) ? $bitrixPricesArr : [])) ); COption::SetOptionString( $mid, $CRM_PRICE_SHOPS, serialize(RCrmActions::clearArr(is_array($bitrixPriceShopsArr) ? $bitrixPriceShopsArr : [])) ); COption::SetOptionString( $mid, $CRM_IBLOCKS_PRICES, serialize(RCrmActions::clearArr(is_array($bitrixIblocksPrices) ? $bitrixIblocksPrices : [])) ); COption::SetOptionString( $mid, $CRM_COLLECTOR, $collector ); COption::SetOptionString( $mid, $CRM_COLL_KEY, serialize(RCrmActions::clearArr(is_array($collectorKeys) ? $collectorKeys : [])) ); RetailCrmConfigProvider::setOnlineConsultant($onlineConsultant); RetailCrmConfigProvider::setOnlineConsultantScript($onlineConsultantScript); COption::SetOptionString( $mid, $CRM_UA, $ua ); COption::SetOptionString( $mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr(is_array($uaKeys) ? $uaKeys : [])) ); COption::SetOptionString( $mid, $CRM_DIMENSIONS, htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) ?: 'N' ); RetailcrmConfigProvider::setSendPaymentAmount(htmlspecialchars(trim($_POST[Constants::SEND_PAYMENT_AMOUNT])) ?: 'N'); RetailCrmConfigProvider::setDiscountRound($discount_round); RetailcrmConfigProvider::setCart($optionCart); COption::SetOptionString( $mid, $CRM_PURCHASE_PRICE_NULL, $purchasePrice_null ); COption::SetOptionString( $mid, RetailcrmConstants::CRM_SHIPMENT_DEDUCTED, $shipment_deducted); COption::SetOptionString( $mid, $CRM_CC, $cc ); COption::SetOptionString( $mid, $CRM_CORP_SHOPS, serialize(RCrmActions::clearArr(is_array($bitrixCorpShopsArr) ? $bitrixCorpShopsArr : [])) ); COption::SetOptionString( $mid, $CRM_CORP_NAME, $bitrixCorpName ); COption::SetOptionString( $mid, $CRM_CORP_ADRES, $bitrixCorpAdres ); $request = 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')); } $arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes( $availableSites, $api->paymentTypesList()->paymentTypes ); $arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes( $availableSites, $api->deliveryTypesList()->deliveryTypes ); $integrationPayments = RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList']); $integrationDeliveries = RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList']); RetailcrmConfigProvider::setIntegrationPaymentTypes($integrationPayments); RetailcrmConfigProvider::setIntegrationDelivery($integrationDeliveries); //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 params $moduleDeactivate = unserialize(COption::GetOptionString($mid, $MODULE_DEACTIVATE, 'N')); $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 = (int) 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); $optionsOrderVat = COption::GetOptionString($mid, $CRM_ORDER_VAT, 0); $canselOrderArr = unserialize(COption::GetOptionString($mid, $CRM_CANSEL_ORDER, 0)); $sendPickupPointAddress = COption::GetOptionString($mid, Constants::CRM_SEND_PICKUP_POINT_ADDRESS, 'N'); $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)); $optionOnlineConsultant = RetailcrmConfigProvider::isOnlineConsultantEnabled(); $optionOnlineConsultantScript = RetailcrmConfigProvider::getOnlineConsultantScript(); $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); $optionShipmentDeducted = RetailcrmConfigProvider::getShipmentDeducted(); //corporate-cliente $optionCorpClient = COption::GetOptionString($mid, $CRM_CC, 0); $optionCorpShops = unserialize(COption::GetOptionString($mid, $CRM_CORP_SHOPS, 0)); $optionsCorpComName = COption::GetOptionString($mid, $CRM_CORP_NAME, 0); $optionsCorpAdres = 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) ?: $baseCurrency; $currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList(); $errorsText = []; if (preg_match('/&errc=ERR_(.*)/is', $APPLICATION->GetCurUri(), $matches)) { $errorsText[] = GetMessage(urldecode($matches[1])); } if (empty($errorsText)) { if (count($arResult['arSites']) === 1 && count($arResult['sitesList']) > 1) { $errorsText[] = GetMessage('ERR_COUNT_SITES'); } if (count($arResult['arSites']) > 1) { foreach ($optionsSitesList as $LID => $crmCode) { if (empty($crmCode)) { continue; } $currentCurrency = $baseCurrency; if (isset($arResult['arCurrencySites'][$LID])) { $currentCurrency = $arResult['arCurrencySites'][$LID]; } if ($currentCurrency !== $arResult['sitesList'][$crmCode]['currency']) { $errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $arResult['sitesList'][$crmCode]['name'] . ')'; } } } else { $currentCurrency = $baseCurrency; $LID = $arResult['arSites'][0]['LID']; if (isset($arResult['arCurrencySites'][$LID])) { $currentCurrency = $arResult['arCurrencySites'][$LID]; } $crmSite = reset($arResult['sitesList']); if ($currentCurrency !== $crmSite['currency']) { $errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $crmSite['name'] . ')'; } } } $customFields = [['code' => '__default_empty_value__', 'name' => GetMessage('SELECT_VALUE')]]; $crmCouponFieldOption = COption::GetOptionString($mid, $CRM_COUPON_FIELD, 0) ?: null; $page = 1; do { $getCustomFields = $api->customFieldsList(['entity' => 'order', 'type' => ['string', 'text']], 100, $page); if (!$getCustomFields->isSuccessful() && empty($getCustomFields['customFields'])) { break; } foreach ($getCustomFields['customFields'] as $customField) { $customFields[] = $customField; } $page++; } while($getCustomFields['pagination']['currentPage'] < $getCustomFields['pagination']['totalPageCount']); $optionsOrderDimensions = COption::GetOptionString($mid, $CRM_DIMENSIONS, 'N'); $addressOptions = unserialize(COption::GetOptionString($mid, $CRM_ADDRESS_OPTIONS, 0)); $optionCart = COption::GetOptionString($mid, $CRM_CART, 'N'); //loyalty program options $loyaltyProgramToggle = ConfigProvider::getLoyaltyProgramStatus(); $aTabs = [ [ "DIV" => "edit1", "TAB" => GetMessage('ICRM_OPTIONS_GENERAL_TAB'), "ICON" => "", "TITLE" => GetMessage('ICRM_OPTIONS_GENERAL_CAPTION'), ], [ "DIV" => "edit2", "TAB" => GetMessage('ICRM_OPTIONS_CATALOG_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION'), ], [ "DIV" => "edit3", "TAB" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_CAPTION'), ], [ "DIV" => "edit4", "TAB" => GetMessage('LOYALTY_PROGRAM_TITLE'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION'), ], [ "DIV" => "edit5", "TAB" => GetMessage('UPLOAD_ORDERS_OPTIONS'), "ICON" => '', "TITLE" => GetMessage('ORDER_UPLOAD'), ], [ "DIV" => "edit6", "TAB" => GetMessage('OTHER_OPTIONS'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION'), ] ]; $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> getCode() . ': ' . $exception->getMessage() ); } ?>
BeginNextTab(); ?>