1
0
mirror of synced 2024-11-23 13:56:08 +03:00
bitrix-module/intaro.retailcrm/export/export_setup.php

1037 lines
50 KiB
PHP
Raw Normal View History

2021-09-08 10:05:09 +03:00
<?php
use Intaro\RetailCrm\Icml\SettingsService;
CModule::IncludeModule('intaro.retailcrm');
/**
* Документация по шаблонам экспорта:
* @link https://dev.1c-bitrix.ru/api_help/catalog/templates.php
*
* Предопределенные переменные:
*
* Ранее сохраненные настройки экспорта из SETUP_VARS b_catalog_export
* @var $arOldSetupVars
*
* @var $APPLICATION
* @var $ACTION
*
* 1 - вывод настроек, 2 - сохранение формы с настройками
* @var $STEP
* @var $PROFILE_ID
* @var $SETUP_FILE_NAME
* @var $SETUP_PROFILE_NAME
*/
//TODO заменить вызов на сервис-локатор, когда он приедет
$settingsService = SettingsService::getInstance(
$arOldSetupVars ?? [],
2021-09-08 10:05:09 +03:00
$ACTION
);
$isSetupModulePage = $settingsService->isSetupModulePage();
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/export_setup.php')) {
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/export_setup.php');
return;
}
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
if (!check_bitrix_sessid()) {
return;
}
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
__IncludeLang(GetLangFileName(
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/intaro.retailcrm/lang/',
'/icml_export_setup.php')
);
$basePriceId = RetailcrmConfigProvider::getCrmBasePrice($_REQUEST['PROFILE_ID']);
$priceTypes = $settingsService->priceTypes;
$iblockFieldsName = $settingsService->getIblockFieldsNames();
$units = $settingsService->getUnitsNames();
$hintUnit = $settingsService->getHintUnit();
//highloadblock
if (CModule::IncludeModule('highloadblock')) {
$hlblockModule = true;
$hlBlockList = $settingsService->getHlBlockList();
}
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
if (($ACTION === 'EXPORT' || $ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_COPY') && $STEP === 1) {
2022-06-14 12:00:14 +03:00
$SETUP_FILE_NAME = $settingsService->setupFileName;
$SETUP_PROFILE_NAME = $settingsService->setupProfileName;
2021-09-08 10:05:09 +03:00
$loadPurchasePrice = $settingsService->loadPurchasePrice;
$iblockExport = $settingsService->iblockExport;
$loadNonActivity = $settingsService->loadNonActivity;
2013-09-13 16:15:54 +04:00
2021-09-08 10:05:09 +03:00
if ($iblockExport) {
$maxOffersValue = $settingsService->getSingleSetting('maxOffersValue');
2015-05-18 17:38:06 +03:00
}
2021-09-08 10:05:09 +03:00
$settingsService->setProps();
2018-05-23 12:19:59 +03:00
2021-09-08 10:05:09 +03:00
$iblockPropertySku = $settingsService->iblockPropertySku;
$iblockPropertyUnitSku = $settingsService->iblockPropertyUnitSku;
$iblockPropertyProduct = $settingsService->iblockPropertyProduct;
$iblockPropertyUnitProduct = $settingsService->iblockPropertyUnitProduct;
2018-05-23 12:19:59 +03:00
2021-09-08 10:05:09 +03:00
$boolAll = false;
$intCountChecked = 0;
$intCountAvailIBlock = 0;
}
2013-08-20 12:53:32 +04:00
2021-09-08 10:05:09 +03:00
if (!isset($iblockExport) || !is_array($iblockExport)) {
$iblockExport = [];
}
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
[$arIBlockList, $intCountChecked, $intCountAvailIBlock, $isExportIblock]
= $settingsService->getSettingsForIblocks();
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
if (count($iblockExport) !== 0) {
if ($intCountChecked === $intCountAvailIBlock) {
$boolAll = true;
2013-08-20 12:53:32 +04:00
}
2021-09-08 10:05:09 +03:00
} else {
$intCountChecked = $intCountAvailIBlock;
$boolAll = true;
}
2013-08-20 12:53:32 +04:00
2021-09-08 10:05:09 +03:00
//Проверка на ошибки
$STEP = $settingsService->returnIfErrors($STEP, $SETUP_FILE_NAME, $SETUP_PROFILE_NAME);
2013-08-20 12:53:32 +04:00
2021-09-08 10:05:09 +03:00
//Отображение формы
if ($STEP === 1) {
2015-05-18 17:38:06 +03:00
?>
2021-09-08 10:05:09 +03:00
<style>
2015-05-18 17:38:06 +03:00
.iblock-export-table-display-none {
display: none;
}
</style>
2013-09-13 16:15:54 +04:00
2024-11-06 19:30:00 +03:00
<form method="post" id="submit-form" action="<?=$APPLICATION->GetCurPage()?>">
2021-09-08 10:05:09 +03:00
<?php
if ($ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_COPY') {
2015-05-18 17:38:06 +03:00
?>
2021-09-08 10:05:09 +03:00
<input type="hidden" name="PROFILE_ID" value="<?=(int)$PROFILE_ID?>">
<?php
2015-05-18 17:38:06 +03:00
}
?>
2021-09-08 10:05:09 +03:00
<h3><?=GetMessage('SETTINGS_INFOBLOCK')?></h3>
<span class="text"><?=GetMessage('EXPORT_CATALOGS');?><br><br></span>
<span class="text" style="font-weight: bold;"><?=GetMessage('CHECK_ALL_INFOBLOCKS')?></span>
2015-05-18 17:38:06 +03:00
<input
style="vertical-align: middle;"
type="checkbox"
name="icml_export_all"
id="icml_export_all"
value="Y"
2021-09-08 10:05:09 +03:00
onclick="checkAll(this,<?=$intCountAvailIBlock?>);"
<?=($boolAll ? ' checked' : '')?>>
2015-05-18 17:38:06 +03:00
</br>
</br>
2013-09-13 16:15:54 +04:00
<div>
2021-09-08 10:05:09 +03:00
<?php
$checkBoxCounter = 0;
//Перебираем все торговые каталоги, формируя для каждого таблицу настроек
foreach ($arIBlockList as $arIBlock) {
?>
2015-05-18 17:38:06 +03:00
<div>
2021-09-08 10:05:09 +03:00
<div>
<span class="text" style="font-weight: bold;">
<?= htmlspecialcharsex('['
. $arIBlock['IBLOCK_TYPE_ID']
. '] '
. $arIBlock['NAME']
. ' '
. $arIBlock['SITE_LIST']) ?>
</span>
<input
type="checkbox"
name="iblockExport[<?=$arIBlock['ID']?>]"
id="iblockExport<?=++$checkBoxCounter?>"
value="<?=$arIBlock['ID']?>"
<?php
if ($arIBlock['iblockExport']) {
echo ' checked';
} ?>
onclick="checkOne(this,<?=$intCountAvailIBlock?>);"
>
</div>
<br>
<div id="iblockExportTable<?=$checkBoxCounter?>" class="iblockExportTable"
data-type="<?=$arIBlock['ID']?>">
<table class="adm-list-table" id="export_setup"
<?=($arIBlock['PROPERTIES_SKU'] === null ? 'style="width: 66%;"' : '')?>
>
<thead>
2015-05-18 17:38:06 +03:00
<tr class="adm-list-table-header">
2013-09-13 16:15:54 +04:00
<td class="adm-list-table-cell">
2021-09-08 10:05:09 +03:00
<div class="adm-list-table-cell-inner"><?=GetMessage('LOADED_PROPERTY');?></div>
2013-09-13 16:15:54 +04:00
</td>
2015-05-18 17:38:06 +03:00
<td class="adm-list-table-cell">
2021-09-08 10:05:09 +03:00
<div class="adm-list-table-cell-inner">
<?=GetMessage('PROPERTY_PRODUCT_HEADER_NAME')?>
</div>
2015-05-18 17:38:06 +03:00
</td>
2021-09-08 10:05:09 +03:00
<?php
if ($arIBlock['PROPERTIES_SKU'] !== null) {?>
2015-05-18 17:38:06 +03:00
<td class="adm-list-table-cell">
2021-09-08 10:05:09 +03:00
<div class="adm-list-table-cell-inner">
<?=GetMessage('PROPERTY_OFFER_HEADER_NAME');?>
</div>
2015-05-18 17:38:06 +03:00
</td>
2021-09-08 10:05:09 +03:00
<?php
} ?>
2015-05-18 17:38:06 +03:00
</tr>
2021-09-08 10:05:09 +03:00
</thead>
<tbody>
2014-04-15 20:31:11 +04:00
2021-09-08 10:05:09 +03:00
<?php
foreach ($settingsService->actrualPropList as $propertyKey => $property) {
2021-09-08 10:05:09 +03:00
$productSelected = false; ?>
2014-01-23 16:55:04 +04:00
2015-05-18 17:38:06 +03:00
<tr class="adm-list-table-row">
<td class="adm-list-table-cell">
2021-09-08 10:05:09 +03:00
<?=htmlspecialcharsex($property)?>
2015-05-18 17:38:06 +03:00
</td>
<td class="adm-list-table-cell">
2021-09-08 10:05:09 +03:00
<select
style="width: 200px;"
id="iblockPropertyProduct_<?=$propertyKey . $arIBlock['ID']?>"
name="iblockPropertyProduct_<?=$propertyKey?>[<?=$arIBlock['ID']?>]"
class="property-export"
data-type="<?=$propertyKey?>"
onchange="propertyChange(this);">
<option value=""></option>
<?php
if ($settingsService->isOptionHasPreset($propertyKey)) {
?>
<optgroup label="<?=GetMessage('SELECT_FIELD_NAME')?>">
<?php
foreach ($iblockFieldsName as $keyField => $field) {
if ($keyField === $propertyKey) { ?>
<option value="<?=$field['CODE']?>"
<?php
$productSelected = $settingsService->isOptionSelected(
$field,
$arIBlock['OLD_PROPERTY_PRODUCT_SELECT'],
$propertyKey
);
2015-05-18 17:38:06 +03:00
?>
2021-09-08 10:05:09 +03:00
<?= $productSelected ? ' selected' : ''?>
>
<?=$field['name']?>
2015-05-18 17:38:06 +03:00
</option>
2021-09-08 10:05:09 +03:00
<?php
}
} ?>
</optgroup>
<optgroup label="<?=GetMessage('SELECT_PROPERTY_NAME')?>">
<?php
}
$productHlTableName = '';
foreach ($arIBlock['PROPERTIES_PRODUCT'] as $prop) { ?>
<option value="<?=$prop['CODE']?>"
<?php
echo $settingsService->getOptionClass($prop, true);
$productSelected = $settingsService->isOptionSelected(
$prop,
$arIBlock['OLD_PROPERTY_PRODUCT_SELECT'],
$propertyKey
);
$productHlTableName
= $settingsService->getHlTableName($prop)
?? $productHlTableName;
echo $productSelected ? ' selected' : '';
?>
>
<?=$prop['NAME']?>
</option>
<?php
}
if ($settingsService->isOptionHasPreset($propertyKey)) {
?>
</optgroup>
<?php
} ?>
</select>
<?php
if ($settingsService->isHlSelected(
$propertyKey,
$arIBlock['ID'],
$productHlTableName,
'_product'
)
) {?>
<select name="highloadblock_product<?=$productHlTableName . '_' .
$propertyKey . '[' . $arIBlock['ID'] . ']' ?>" id="highloadblock"
style="width: 100px; margin-left: 50px;">
<?php
foreach ($hlBlockList[$productHlTableName]['FIELDS'] as $field) {
?>
<option value="<?=$field?>"
<?= $settingsService->getHlOptionStatus(
$productHlTableName,
$propertyKey,
$arIBlock['ID'],
(string) $field,
'highloadblock_product'
) ?>
>
<?=$field?>
</option>
<?php
} ?>
</select>
<?php
}
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
//Единицы измерения для товаров
if (array_key_exists($propertyKey, $iblockFieldsName)) :?>
<select
style="width: 100px; margin-left: 50px;"
id="iblockPropertyUnitProduct_<?=$propertyKey . $arIBlock['ID']?>"
name="iblockPropertyUnitProduct_<?=$propertyKey?>[<?=$arIBlock['ID']?>]"
>
<?php
foreach ($units as $unitTypeName => $unitType) { ?>
<?php
if ($unitTypeName == $iblockFieldsName[$propertyKey]['unit']): ?>
<?php
foreach ($unitType as $keyUnit => $unit): ?>
<option value="<?=$keyUnit?>"
<?=$settingsService->getUnitOptionStatus(
$arIBlock['OLD_PROPERTY_UNIT_PRODUCT_SELECT'],
$keyUnit,
$propertyKey,
(string) $unitTypeName
)
?>
>
<?=$unit?>
</option>
<?php
endforeach; ?>
<?php
endif; ?>
<?php
} ?>
2015-05-18 17:38:06 +03:00
</select>
2021-09-08 10:05:09 +03:00
<?php
endif; ?>
2015-05-18 17:38:06 +03:00
</td>
2021-09-08 10:05:09 +03:00
<?php
//Столбец со свойствами тороговых предложений
if ($arIBlock['PROPERTIES_SKU'] !== null) {?>
2015-05-18 17:38:06 +03:00
<td class="adm-list-table-cell">
<select
style="width: 200px;"
2021-09-08 10:05:09 +03:00
id="iblockPropertySku_<?=$propertyKey?><?=$arIBlock['ID']?>"
name="iblockPropertySku_<?=$propertyKey?>[<?=$arIBlock['ID']?>]"
2015-05-18 17:38:06 +03:00
class="property-export"
2021-09-08 10:05:09 +03:00
data-type="<?=$propertyKey?>"
2015-05-18 17:38:06 +03:00
onchange="propertyChange(this);">
2021-09-08 10:05:09 +03:00
<option value=""></option>
<?php
if ($settingsService->isOptionHasPreset($propertyKey)) {
?>
<optgroup label="<?=GetMessage('SELECT_FIELD_NAME');?>">
<?php
foreach ($iblockFieldsName as $keyField => $field) {
if ($keyField === $propertyKey) :?>
<option value="<?=$field['CODE']?>"
<?php
$isSelected = $settingsService->isOptionSelected(
$field,
$arIBlock['OLD_PROPERTY_SKU_SELECT'],
$propertyKey
);
echo $isSelected ? ' selected' : '';
?>
>
<?=$field['name']?>
</option>
<?php
endif;
} ?>
</optgroup>
<optgroup label="<?=GetMessage('SELECT_PROPERTY_NAME');?>">
<?php
}
$skuHlTableName = '';
foreach ($arIBlock['PROPERTIES_SKU'] as $prop) { ?>
<option value="<?=$prop['CODE']?>"
<?php
echo $settingsService->getOptionClass($prop, false);
2015-05-18 17:38:06 +03:00
if (!$productSelected) {
2021-09-08 10:05:09 +03:00
$isSelected = $settingsService->isOptionSelected(
$prop,
$arIBlock['OLD_PROPERTY_SKU_SELECT'],
$propertyKey
);
$skuHlTableName
= $settingsService->getHlTableName($prop)
?? $skuHlTableName;
echo $isSelected ? ' selected' : '';
2015-05-18 17:38:06 +03:00
}
?>
2021-09-08 10:05:09 +03:00
>
<?=$prop['NAME']?>
2015-05-18 17:38:06 +03:00
</option>
2021-09-08 10:05:09 +03:00
<?php
}
if ($settingsService->isOptionHasPreset($propertyKey)) {
?>
</optgroup>
<?php
} ?>
2014-01-23 16:55:04 +04:00
</select>
2021-09-08 10:05:09 +03:00
<?php
if (
$settingsService->isHlSelected(
$propertyKey,
$arIBlock['ID'],
$skuHlTableName
)
) { ?>
<select
name="highloadblock<?=$skuHlTableName . '_' . $propertyKey . '['
. $arIBlock['ID'] . ']'?>"
id="highloadblock"
style="width: 100px;
margin-left: 50px;"
>
<?php
foreach ($hlBlockList[$skuHlTableName]['FIELDS'] as $field)
: ?>
<option value="<?=$field?>"
<?=
$settingsService->getHlOptionStatus(
$skuHlTableName,
$propertyKey,
$arIBlock['ID'],
(string) $field,
'highloadblock'
)?>
>
<?=$field?>
</option>
<?php
endforeach; ?>
2018-03-22 16:11:04 +03:00
</select>
2021-09-08 10:05:09 +03:00
<?php
}
if (array_key_exists($propertyKey, $iblockFieldsName)) {?>
2015-05-18 17:38:06 +03:00
<select
style="width: 100px; margin-left: 50px;"
2021-09-08 10:05:09 +03:00
id="iblockPropertyUnitSku_<?=$propertyKey?><?=$arIBlock['ID']?>"
name="iblockPropertyUnitSku_<?=$propertyKey?>[<?=$arIBlock['ID']?>]"
>
<?php
foreach ($units as $unitTypeName => $unitType) {
if ($unitTypeName == $iblockFieldsName[$propertyKey]['unit']) {
foreach ($unitType as $keyUnit => $unit) { ?>
<option value="<?=$keyUnit?>"
<?php
echo $settingsService->getUnitOptionStatus(
$arIBlock['OLD_PROPERTY_UNIT_SKU_SELECT'],
$keyUnit,
$propertyKey,
$unitTypeName
);
2015-05-18 17:38:06 +03:00
?>
2021-09-08 10:05:09 +03:00
>
2015-05-18 17:38:06 +03:00
<?=$unit?>
</option>
2021-09-08 10:05:09 +03:00
<?php
}
}
} ?>
2015-05-18 17:38:06 +03:00
</select>
2021-09-08 10:05:09 +03:00
<?php
} ?>
2015-05-18 17:38:06 +03:00
</td>
2021-09-08 10:05:09 +03:00
<?php
} ?>
2015-05-18 17:38:06 +03:00
</tr>
2021-09-08 10:05:09 +03:00
<?php
} ?>
</tbody>
</table>
2024-11-06 19:30:00 +03:00
<button class="adm-btn-save add-custom-row" type="button">Добавить</button>
2021-09-08 10:05:09 +03:00
<br>
<br>
</div>
2015-05-18 17:38:06 +03:00
</div>
2021-09-08 10:05:09 +03:00
<?php
} ?>
2013-09-13 16:15:54 +04:00
</div>
2021-09-08 10:05:09 +03:00
<input type="hidden" name="count_checked" id="count_checked" value="<?=$intCountChecked?>">
2024-11-06 19:30:00 +03:00
<!-- <br>-->
<template id="custom-property-template-row">
<tr class="adm-list-table-row custom-property-row">
<td class="adm-list-table-cell">
<input type="text" title="Название нового свойства" name="custom-property-title" style="width: 200px">
</td>
<td class="adm-list-table-cell">
<select name="iblockPropertyProduct_" id="iblockPropertyProduct_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
</td>
<td class="adm-list-table-cell">
<select name="iblockPropertySku_" id="iiblockPropertySku_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
2024-11-06 19:30:00 +03:00
<button id="delete-custom-row" class="adm-btn-save" type="button">Удалить</button>
</td>
</tr>
</template>
2021-09-08 10:05:09 +03:00
<h3><?=GetMessage('SETTINGS_EXPORT')?></h3>
<span class="text"><?=GetMessage('FILENAME')?><br><br></span>
2022-06-14 12:00:14 +03:00
<input type="text" name="SETUP_FILE_NAME" value="<?=htmlspecialcharsbx(strlen($SETUP_FILE_NAME) > 0 ?
$SETUP_FILE_NAME : $settingsService->setupFileName); ?>" size="50"><br><br>
2021-09-08 10:05:09 +03:00
<span class="text"><?=GetMessage('LOAD_PURCHASE_PRICE')?>&nbsp;</span>
<input type="checkbox" name="loadPurchasePrice" value="Y" <?=$loadPurchasePrice === 'Y' ? 'checked' : ''?>>
<br><br>
<span class="text"><?=GetMessage('LOAD_NON_ACTIVITY')?>&nbsp;</span>
<input type="checkbox" name="loadNonActivity" value="Y" <?=$loadNonActivity === 'Y' ? 'checked' : ''?>>
<br><br>
2021-09-08 10:05:09 +03:00
<?php
if ($isSetupModulePage) { ?>
<span class="text"><?=GetMessage('AGENT_LOADING')?>&nbsp;</span>
<input id="add-agent" type="checkbox" name="NEED_CATALOG_AGENT" value="agent"><br><br>
<span class="text" style="font-weight: bold; font-size: 14px"><?=GetMessage('LOAD_NOW')?>&nbsp;</span>
<input id="load-now" type="checkbox" onchange="checkLoadStatus(this)" name="LOAD_NOW" value="now"><br>
2013-08-20 12:53:32 +04:00
<br>
<div id="loadMessageNow" hidden><?=GetMessage('LOAD_NOW_MSG')?></div>
2013-08-20 12:53:32 +04:00
<br>
2021-09-08 10:05:09 +03:00
<?php
}?>
2013-08-26 10:33:51 +04:00
2021-09-08 10:05:09 +03:00
<span class="text"><?=GetMessage('BASE_PRICE')?>&nbsp;</span>
2015-05-18 17:38:06 +03:00
<select name="price-types" class="typeselect">
<option value=""></option>
2021-09-08 10:05:09 +03:00
<?php
foreach ($priceTypes as $priceType) { ?>
<option value="<?=$priceType['ID']?>" <?= $priceType['ID'] == $basePriceId ? ' selected' : ''?>>
<?=$priceType['NAME']?>
2015-05-18 17:38:06 +03:00
</option>
2021-09-08 10:05:09 +03:00
<?php
} ?>
</select><br><br><br>
<?php
if ($ACTION === 'EXPORT_SETUP' || $ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_COPY') { ?>
<span class="text"><?=GetMessage('OFFERS_VALUE')?><br><br></span>
<label>
<input
type="text"
name="maxOffersValue"
value="<?=htmlspecialchars($maxOffersValue)?>"
size="15">
</label><br><br><br>
<span class="text"><?=GetMessage('PROFILE_NAME')?><br><br></span>
<label>
<input
type="text"
name="SETUP_PROFILE_NAME"
2022-06-14 12:00:14 +03:00
value="<?=htmlspecialchars(strlen($SETUP_PROFILE_NAME) > 0 ?
$SETUP_PROFILE_NAME : $settingsService->setupProfileName)?>"
2021-09-08 10:05:09 +03:00
size="50">
</label><br><br><br>
<?php
2022-06-14 12:00:14 +03:00
}
?>
2021-09-08 10:05:09 +03:00
<?=bitrix_sessid_post()?>
<?php
if ($isSetupModulePage) { ?>
<input type="hidden" name="lang" value="<?= LANG; ?>">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="6">
<input type="hidden" name="continue" value="5">
<div style="padding: 1px 13px 2px; height:28px;">
<div align="right" style="float:right; width:50%; position:relative;">
<input type="submit" name="inst" onclick="BX.showWait()" value="<?= GetMessage('MOD_NEXT_STEP'); ?>"
class="adm-btn-save">
</div>
<div align="left" style="float:right; width:50%; position:relative;">
<input type="submit" name="back" value="<?= GetMessage('MOD_PREV_STEP'); ?>" class="adm-btn-save">
</div>
</div>
2015-05-18 17:38:06 +03:00
2021-09-08 10:05:09 +03:00
<?php
} else {?>
<input type="hidden" name="lang" value="<?=LANGUAGE_ID?>">
<input type="hidden" name="ACT_FILE" value="<?=htmlspecialcharsbx($_REQUEST['ACT_FILE'])?>">
<input type="hidden" name="ACTION" value="<?=htmlspecialcharsbx($ACTION)?>">
<input type="hidden" name="STEP" value="<?=$STEP + 1?>">
<input type="hidden" name="SETUP_FIELDS_LIST" value="<?=
$settingsService->getSetupFieldsString(
array_keys($settingsService->actrualPropList) ?? [],
2021-09-08 10:05:09 +03:00
$hlblockModule === true,
$hlBlockList ?? []
)
?>">
<input type="submit" value="<?=($ACTION === 'EXPORT') ? GetMessage('EXPORT') : GetMessage('SAVE')?>">
<?php
} ?>
</form>
2015-05-18 17:38:06 +03:00
<?php CJSCore::Init(['jquery']);?>
<?php CUtil::InitJSCore(['intaro_custom_props']); ?>
2021-09-08 10:05:09 +03:00
<script type="text/javascript">
function checkLoadStatus(object)
{
if (object.checked) {
$('#loadMessageNow').show();
2021-09-08 10:05:09 +03:00
} else {
$('#loadMessageNow').hide();
2021-09-08 10:05:09 +03:00
}
}
function checkAll(obj, cnt) {
for (let i = 0; i < cnt; i++) {
if (obj.checked) {
BX.removeClass('iblockExportTable' + (i + 1), "iblock-export-table-display-none");
}
}
const table = BX(obj.id.replace('iblockExport', 'iblockExportTable'));
if (obj.checked) {
BX.removeClass(table, "iblock-export-table-display-none");
}
const easing = new BX.easing({
duration: 150,
start: {opacity: obj.checked ? 0 : 100},
finish: {opacity: obj.checked ? 100 : 0},
transition: BX.easing.transitions.linear,
step: function(state) {
for (let i = 0; i < cnt; i++) {
BX('iblockExportTable' + (i + 1)).style.opacity = state.opacity / 100;
2015-05-18 17:38:06 +03:00
}
2021-09-08 10:05:09 +03:00
},
complete: function() {
for (let i = 0; i < cnt; i++) {
if (!obj.checked) {
BX.addClass('iblockExportTable' + (i + 1), "iblock-export-table-display-none");
2018-03-22 16:11:04 +03:00
}
2015-05-18 17:38:06 +03:00
}
2021-09-08 10:05:09 +03:00
}
});
easing.animate();
const boolCheck = obj.checked;
for (let i = 0; i < cnt; i++) {
BX('iblockExport' + (i + 1)).checked = boolCheck;
}
BX('count_checked').value = (boolCheck ? cnt : 0);
}
function checkOne(obj, cnt) {
const table = BX(obj.id.replace('iblockExport', 'iblockExportTable'));
if (obj.checked) {
BX.removeClass(table, "iblock-export-table-display-none");
}
2018-05-23 12:19:59 +03:00
2021-09-08 10:05:09 +03:00
const easing = new BX.easing({
duration: 150,
start: {opacity: obj.checked ? 0 : 100},
finish: {opacity: obj.checked ? 100 : 0},
transition: BX.easing.transitions.linear,
step: function(state) {
table.style.opacity = state.opacity / 100;
},
complete: function() {
if (!obj.checked) {
BX.addClass(table, "iblock-export-table-display-none");
2018-05-23 12:19:59 +03:00
}
2021-09-08 10:05:09 +03:00
}
});
easing.animate();
const boolCheck = obj.checked;
let intCurrent = parseInt(BX('count_checked').value);
intCurrent += (boolCheck ? 1 : -1);
BX('icml_export_all').checked = (intCurrent >= cnt);
BX('count_checked').value = intCurrent;
}
function propertyChange(obj) {
let selectedOption = $(obj).find('option')[obj.selectedIndex];
if (selectedOption.className === 'not-highloadblock') {
let objId = '#' + obj.id;
$(objId).parent().children('#highloadblock').remove();
}
if (selectedOption.className === 'highloadblock') {
getHlTablesFromController(selectedOption, 'sku', obj.getAttribute('data-type'));
}
if (selectedOption.className === 'highloadblock-product') {
getHlTablesFromController(selectedOption, 'product', obj.getAttribute('data-type'));
}
}
2018-05-23 12:19:59 +03:00
2021-09-08 10:05:09 +03:00
function setHlFieldsInInstallPage(that, type, key){
const td = $(that).parents('td .adm-list-table-cell');
const select = $(that).parent('select').siblings('#highloadblock');
const iblock = $(that).parents('.iblockExportTable').attr('data-type');
const sessid = BX.bitrix_sessid();
const table_name = $(that).attr('id');
const step = $('input[name="continue"]').val();
const id = $('input[name="id"]').val();
const install = $('input[name="install"]').val();
const data = 'install=' + install + '&step=' + step + '&sessid=' + sessid +
'&id=' + id + '&ajax=1&table=' + table_name;
$.ajax({
url: '/bitrix/admin/partner_modules.php',
type: 'POST',
data: data,
dataType: "json",
success: function(res) {
$(select).remove();
$('#waiting').remove();
let new_options = '';
$.each(res.fields, function(key, value) {
new_options += '<option value="' + value + '">' + value + '</option>';
});
if (type === 'sku') {
$(td).append(getSelect(res, key, iblock, new_options, 'highloadblock'));
2018-05-23 12:19:59 +03:00
}
2021-09-08 10:05:09 +03:00
if (type === 'product') {
$(td).append(getSelect(res, key, iblock, new_options, 'highloadblock_product'));
2018-05-23 12:19:59 +03:00
}
2021-09-08 10:05:09 +03:00
},
beforeSend: function() {
$(td).append('<span style="margin-left:50px;" id="waiting"><?=GetMessage('WAIT')?></span>');
2018-03-22 16:11:04 +03:00
}
2021-09-08 10:05:09 +03:00
});
}
function setHlFieldsInSettingsPage(that, type, key){
const td = $(that).parents('td .adm-list-table-cell');
const select = $(that).parent('select').siblings('#highloadblock');
const table_name = $(that).attr('id');
const iblock = $(that).parents('.iblockExportTable').attr('data-type');
BX.ajax.runAction('intaro:retailcrm.api.icml.getHlTable',
{
method: 'POST',
data: {
sessid: BX.bitrix_sessid(),
tableName: table_name
}
2018-05-23 12:19:59 +03:00
}
2021-09-08 10:05:09 +03:00
).then((response) => {
$(select).remove();
$('#waiting').remove();
let new_options = '';
$.each(response.data.fields, function(key, value) {
new_options += '<option value="' + value + '">' + value + '</option>';
});
let typeValue = 'highloadblock';
2018-03-22 16:11:04 +03:00
2021-09-08 10:05:09 +03:00
if (type === 'product') {
typeValue += '_product'
}
$(td).append(getSelect (response.data, key, iblock, new_options, typeValue));
2018-05-23 12:19:59 +03:00
}
2021-09-08 10:05:09 +03:00
);
}
function getHlTablesFromController(that, type, key) {
const url = $('td .adm-list-table-cell').parents('form').attr('action');
if (url === '/bitrix/admin/partner_modules.php') {
setHlFieldsInInstallPage(that, type, key);
} else {
setHlFieldsInSettingsPage(that, type, key)
2018-03-22 16:11:04 +03:00
}
2015-05-18 17:38:06 +03:00
}
2014-04-15 20:31:11 +04:00
2021-09-08 10:05:09 +03:00
function getSelect (res, key, iblock, new_options, type){
let select = document.createElement('select');
let atrName = type + res.table + '_' + key + '[' + iblock + ']';
select.setAttribute('name', atrName);
select.setAttribute('id', 'highloadblock');
select.setAttribute('style','width: 100px; margin-left: 50px;');
select.innerHTML = new_options;
2013-08-20 12:53:32 +04:00
2021-09-08 10:05:09 +03:00
return select;
}
2024-11-06 19:30:00 +03:00
const setupFieldsListElement = $('input[name="SETUP_FIELDS_LIST"]');
let customProperties = {};
$('.add-custom-row').click(function () {
createCustomPropsRaw($(this));
});
$(document).on('click', '#delete-custom-row', function () {
deleteCustomPropsRaw($(this));
});
$(document).on('blur', 'input[name="custom-property-title"]', function () {
let inputElem = $(this);
let newPropertyTitle = inputElem.val();
if (!newPropertyTitle) {
return;
}
let newPropertyCode = getUniquePropertyCode(newPropertyTitle);
addCustomPropCodeToSelectAttributes(newPropertyCode, inputElem);
});
2024-11-06 19:30:00 +03:00
$('#submit-form').submit(function (formEvent) {
formEvent.preventDefault();
let formElem = formEvent.currentTarget;
let profileId = $($('input[name="PROFILE_ID"]')).val();
2024-11-06 19:30:00 +03:00
setCustomProperties();
if (Object.keys(customProperties).length > 0) {
addParamsToSetupFieldsList();
BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
json: {
properties: customProperties,
profileId: profileId
},
}).then(function() {
formElem.submit();
});
} else {
formElem.submit();
}
2024-11-06 19:30:00 +03:00
});
function addCustomPropCodeToSelectAttributes(customPropCode, customPropTitleElem)
{
let selectElements = customPropTitleElem.closest('.custom-property-row').find('td select');
let catalogId = customPropTitleElem.closest('.iblockExportTable').data('type');
selectElements.each(function (index, element) {
let selectElem = $(element);
let newSelectIdValue = selectElem.attr('id').match(/^[^_]*_/)[0] + customPropCode + catalogId;
let newSelectNameValue = selectElem.attr('name').match(/^[^_]*_/)[0] + customPropCode + `[${catalogId}]`;
selectElem.attr('id', newSelectIdValue);
selectElem.attr('name', newSelectNameValue);
selectElem.data('type', customPropCode);
triggerSelectChange(selectElem);
});
}
function triggerSelectChange(selectElem)
{
if (selectElem.val().length > 0) {
console.log('был')
selectElem.trigger('change', [self]);
}
}
2024-11-06 19:30:00 +03:00
function setCustomProperties()
{
let customPropertiesRows = $('.custom-property-row');
if (customPropertiesRows.length === 0) {
return;
}
2024-11-06 19:30:00 +03:00
let customPropertyCatalogId;
let customPropertyTitle = '';
let customPropertyCode = '';
let productPropertyMatch = '';
let offerPropertyMatch = '';
let catalogIds = [];
customPropertiesRows.each(function (index, propertyRow) {
let propertyRowObj = $(propertyRow);
customPropertyCatalogId = propertyRowObj.closest('.iblockExportTable').data('type');
customPropertyTitle = propertyRowObj.find('input[name="custom-property-title"]').val();
if (!customPropertyTitle) {
return true;
}
2024-11-06 19:30:00 +03:00
customPropertyCode = getUniquePropertyCode(customPropertyTitle);
productPropertyMatch = propertyRowObj.find('select[name=custom-product-property-select]').val();
offerPropertyMatch = propertyRowObj.find('select[name=custom-offer-property-select]').val();
let values = {
'title': customPropertyTitle,
'code': customPropertyCode,
'productProperty': productPropertyMatch,
'offerProperty': offerPropertyMatch
};
if (catalogIds.indexOf(customPropertyCatalogId) === -1) {
customProperties[customPropertyCatalogId] = [values];
} else {
customProperties[customPropertyCatalogId].push(values);
}
catalogIds.push(customPropertyCatalogId);
});
}
function getUniquePropertyCode(customPropertyTitle)
{
let uniqueValue = transliterate(customPropertyTitle).replace(/ /g, '_');
let counter = 0;
const setupFieldsListValues = setupFieldsListElement.val().split(',');
while (setupFieldsListValues.includes(uniqueValue)) {
uniqueValue = `${customPropertyTitle}${++counter}`;
}
return uniqueValue;
}
function addParamsToSetupFieldsList()
{
let newParams = '';
let parametersToFill = [
'iblockPropertySku_',
'iblockPropertyUnitSku_',
'iblockPropertyProduct_',
'iblockPropertyUnitProduct_',
'highloadblockb_hlsys_marking_code_group_',
'highloadblock_productb_hlsys_marking_code_group_',
'highloadblockeshop_color_reference_',
'highloadblock_producteshop_color_reference_',
'highloadblockeshop_brand_reference_',
'highloadblock_producteshop_brand_reference_'
];
for (let propertiesByCatalogId of Object.values(customProperties)) {
propertiesByCatalogId.forEach(function (values) {
parametersToFill.forEach(function (param) {
newParams += ',' + param + values.code;
2024-11-06 19:30:00 +03:00
});
});
}
let newValue = setupFieldsListElement.val() + newParams;
setupFieldsListElement.val(newValue);
2024-11-06 19:30:00 +03:00
}
function createCustomPropsRaw(addRowButton)
2024-11-06 19:30:00 +03:00
{
let templateRow = $($('#custom-property-template-row').html());
let templateSelectElements = templateRow.find('select');
2024-11-06 19:30:00 +03:00
let prevTableRow = $(addRowButton).prev('table').find('tbody tr:last-child');
let lastRawSelectElements = prevTableRow.find('td select');
2024-11-06 19:30:00 +03:00
lastRawSelectElements.each(function (index, element) {
let selectElement = $(element);
let templateSelectElement = templateSelectElements[index];
fillTemplateSelect(selectElement, templateSelectElement);
prevTableRow.after(templateRow);
2024-11-06 19:30:00 +03:00
});
}
function deleteCustomPropsRaw(buttonEvent)
{
buttonEvent.closest('tr').remove();
}
function fillTemplateSelect(sourceSelectElement, templateSelectElement)
{
let selectOptions = sourceSelectElement.find('option');
selectOptions.each(function (index, element) {
let optionElem = $(element);
let value = $(optionElem).val();
let text = $(optionElem).text();
$('<option>', { value: value, text: text }).appendTo(templateSelectElement);
});
}
function transliterate(titleToTransliterate)
{
const hasCyrillicChars = /[\u0400-\u04FF]/.test(titleToTransliterate);
if (!hasCyrillicChars) {
return titleToTransliterate;
}
2024-11-06 19:30:00 +03:00
translitedText = '';
for (var i = 0; i < titleToTransliterate.length; i++) {
switch (titleToTransliterate[i]) {
case 'а': case 'А': translitedText += 'a'; break;
case 'б': case 'Б': translitedText += 'b'; break;
case 'в': case 'В': translitedText += 'v'; break;
case 'г': case 'Г': translitedText += 'g'; break;
case 'д': case 'Д': translitedText += 'd'; break;
case 'е': case 'Е': translitedText += 'e'; break;
case 'ё': case 'Ё': translitedText += 'yo'; break;
case 'ж': case 'Ж': translitedText += 'zh'; break;
case 'з': case 'З': translitedText += 'z'; break;
case 'и': case 'И': translitedText += 'i'; break;
case 'й': case 'Й': translitedText += 'y'; break;
case 'к': case 'К': translitedText += 'k'; break;
case 'л': case 'Л': translitedText += 'l'; break;
case 'м': case 'М': translitedText += 'm'; break;
case 'н': case 'Н': translitedText += 'n'; break;
case 'о': case 'О': translitedText += 'o'; break;
case 'п': case 'П': translitedText += 'p'; break;
case 'р': case 'Р': translitedText += 'r'; break;
case 'с': case 'С': translitedText += 's'; break;
case 'т': case 'Т': translitedText += 't'; break;
case 'у': case 'У': translitedText += 'u'; break;
case 'ф': case 'Ф': translitedText += 'f'; break;
case 'х': case 'Х': translitedText += 'h'; break;
case 'ц': case 'Ц': translitedText += 'c'; break;
case 'ч': case 'Ч': translitedText += 'ch'; break;
case 'ш': case 'Ш': translitedText += 'sh'; break;
case 'щ': case 'Щ': translitedText += 'sch'; break;
case 'ъ': case 'Ъ': translitedText += ''; break;
case 'ы': case 'Ы': translitedText += 'y'; break;
case 'ь': case 'Ь': translitedText += ''; break;
case 'э': case 'Э': translitedText += 'e'; break;
case 'ю': case 'Ю': translitedText += 'yu'; break;
case 'я': case 'Я': translitedText += 'ya'; break;
default: translitedText += titleToTransliterate[i]; break;
}
}
return translitedText;
}
2021-09-08 10:05:09 +03:00
</script>
<?php
}
2013-08-20 12:53:32 +04:00
2021-09-08 10:05:09 +03:00
//Сохранение и выход
if ($STEP === 2) {
RetailcrmConfigProvider::setProfileBasePrice($_REQUEST['PROFILE_ID'], $_POST['price-types']);
$FINITE = true;
2013-08-20 12:53:32 +04:00
}
2018-05-23 12:19:59 +03:00
?>