1
0
mirror of synced 2024-11-30 01:06:06 +03:00
bitrix-module/intaro.retailcrm/export/export_setup.php

1190 lines
58 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->defaultPropList as $propertyKey => $property) { ?>
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
$isSelected = $settingsService->isOptionSelected(
2021-09-08 10:05:09 +03:00
$field,
$arIBlock['OLD_PROPERTY_PRODUCT_SELECT'],
$propertyKey
);
2015-05-18 17:38:06 +03:00
?>
2021-09-08 10:05:09 +03:00
<?= $isSelected ? ' selected' : ''?>
2021-09-08 10:05:09 +03:00
>
<?=$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);
$isSelected = $settingsService->isOptionSelected(
2021-09-08 10:05:09 +03:00
$prop,
$arIBlock['OLD_PROPERTY_PRODUCT_SELECT'],
$propertyKey
);
$productHlTableName
= $settingsService->getHlTableName($prop)
?? $productHlTableName;
echo $isSelected ? ' selected' : '';
2021-09-08 10:05:09 +03:00
?>
>
<?=$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);
$isSelected = $settingsService->isOptionSelected(
$prop,
$arIBlock['OLD_PROPERTY_SKU_SELECT'],
$propertyKey
);
2021-09-08 10:05:09 +03:00
$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
} ?>
<?php
$catalogId = $arIBlock['ID'];
$catalogCustomProps = $settingsService->customPropList[$catalogId];
foreach ($catalogCustomProps as $catalogCustomPropCode => $catalogCustomPropValue) { ?>
<tr class="adm-list-table-row custom-property-row">
<td class="adm-list-table-cell custom-property-title">
<?=htmlspecialcharsex($catalogCustomPropValue)?>
</td>
<td class="adm-list-table-cell">
<select
name="iblockPropertyProduct_<?=$catalogCustomPropCode?>[<?= $catalogId ?>]"
id="iblockPropertyProduct_<?=$catalogCustomPropCode . $catalogId ?>"
class="property-export"
data-type="<?= $catalogCustomPropCode ?>"
onchange="propertyChange(this)"
style="width: 200px">
<option value=""></option>
<?php foreach ($arIBlock['PROPERTIES_PRODUCT'] as $prop) {
$productHlTableName = ''; ?>
<option value="<?=$prop['CODE']?>"
<?php
echo $settingsService->getOptionClass($prop, true);
$isSelected = $settingsService->isOptionSelected(
$prop,
$arIBlock['OLD_PROPERTY_PRODUCT_SELECT'],
$catalogCustomPropCode
);
$productHlTableName
= $settingsService->getHlTableName($prop)
?? $productHlTableName;
echo $isSelected ? ' selected' : '';
?>
>
<?=$prop['NAME']?>
</option>
<?php } ?>
</select>
</td>
<?php if ($arIBlock['PROPERTIES_SKU'] !== null) { ?>
<td class="adm-list-table-cell">
<select
name="iblockPropertySku_<?=$catalogCustomPropCode?>[<?= $catalogId ?>]"
id="iblockPropertySku_<?=$catalogCustomPropCode . $catalogId ?>"
class="property-export"
data-type="<?= $catalogCustomPropCode ?>"
onchange="propertyChange(this)"
style="width: 200px">
<option value=""></option>
<?php foreach ($arIBlock['PROPERTIES_SKU'] as $prop) {
$skuHlTableName = ''; ?>
<option value="<?=$prop['CODE']?>"
<?php
echo $settingsService->getOptionClass($prop, false);
$isSelected = $settingsService->isOptionSelected(
$prop,
$arIBlock['OLD_PROPERTY_SKU_SELECT'],
$catalogCustomPropCode
);
$skuHlTableName
= $settingsService->getHlTableName($prop)
?? $skuHlTableName;
echo $isSelected ? ' selected' : '';
?>
>
<?=$prop['NAME']?>
</option>
<?php } ?>
</select>
<button id="delete-custom-row" class="adm-btn-save" type="button">Удалить</button>
</td>
<?php } ?>
</tr>
<?php } ?>
2021-09-08 10:05:09 +03:00
</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?>">
<br>
2024-11-06 19:30:00 +03:00
<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>
<button id="delete-new-custom-row" class="adm-btn-save" type="button">Удалить</button>
2024-11-06 19:30:00 +03:00
</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];
console.log(selectedOption);
2021-09-08 10:05:09 +03:00
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 customProps = {};
let customPropsToDelete = {};
const setupFieldsParamsToFill = [
'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_'
];
2024-11-06 19:30:00 +03:00
$('.add-custom-row').click(function () {
createCustomPropsRaw($(this));
});
$(document).on('click', '#delete-new-custom-row', function () {
deleteCustomPropRow($(this));
});
2024-11-06 19:30:00 +03:00
$(document).on('click', '#delete-custom-row', function () {
let buttonElem = $(this);
addCustomPropToDelete(buttonElem);
deleteCustomPropRow(buttonElem);
2024-11-06 19:30:00 +03:00
});
$(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 savePromise = null;
let deletePromise = null;
let formElem = formEvent.currentTarget;
let profileId = $($('input[name="PROFILE_ID"]')).val();
2024-11-06 19:30:00 +03:00
setCustomProperties();
if (Object.keys(customProps).length > 0) {
savePromise = BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
json: {
properties: customProps,
profileId: profileId
},
}).then(addParamsToSetupFieldsList());
}
if (Object.keys(customPropsToDelete).length > 0) {
deletePromise = BX.ajax.runAction('intaro:retailcrm.api.customexportprops.delete', {
json: {
properties: customPropsToDelete,
profileId: profileId
},
}).then(deleteParamsFromSetupFieldsList());
}
const promises = [savePromise, deletePromise].filter(Boolean);
if (promises.length > 0) {
Promise.all(promises)
.finally(() => {
formElem.submit();
});
} else {
formElem.submit();
}
2024-11-06 19:30:00 +03:00
});
function deleteCustomPropRow(deleteButton)
{
deleteButton.closest('tr').remove();
}
function addCustomPropToDelete(deleteButton)
{
let deletedPropTitle = deleteButton.closest('td').siblings().filter('.custom-property-title').text().trim();
let deletedPropCode = deleteButton.siblings().filter('select').first().data('type');
let customPropCatalogId = deleteButton.closest('.iblockExportTable').data('type');
let values = {
'title': deletedPropTitle,
'code': deletedPropCode,
};
if (customPropsToDelete.hasOwnProperty(customPropCatalogId)) {
customPropsToDelete[customPropCatalogId].push(values);
} else {
customPropsToDelete[customPropCatalogId] = [values];
}
}
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) {
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) {
customProps[customPropertyCatalogId] = [values];
2024-11-06 19:30:00 +03:00
} else {
customProps[customPropertyCatalogId].push(values);
2024-11-06 19:30:00 +03:00
}
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 = '';
if (Object.keys(customProps).length === 0) {
return;
}
for (let propertiesByCatalogId of Object.values(customProps)) {
2024-11-06 19:30:00 +03:00
propertiesByCatalogId.forEach(function (values) {
setupFieldsParamsToFill.forEach(function (param) {
newParams += ',' + param + values.code;
2024-11-06 19:30:00 +03:00
});
});
}
let newValue = setupFieldsListElement.val() + newParams;
setupFieldsListElement.val(newValue);
return true;
}
function deleteParamsFromSetupFieldsList()
{
let setupFields = setupFieldsListElement.val();
if (Object.keys(customPropsToDelete).length === 0) {
return;
}
for (let propsByCatalogId of Object.values(customPropsToDelete)) {
propsByCatalogId.forEach(function (propValues) {
setupFieldsParamsToFill.forEach(function (param) {
let paramToDelete = ',' + param + propValues.code;
setupFields = setupFields.replace(paramToDelete, '');
});
});
}
setupFieldsListElement.val(setupFields);
return true;
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 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
?>