Добавил удаление из файлов, раздельный показ свойств. Поломал вывод или сохранение значений свойств
This commit is contained in:
parent
832b8f34b7
commit
7c762dff2f
@ -190,7 +190,7 @@ if ($STEP === 1) {
|
|||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
foreach ($settingsService->actrualPropList as $propertyKey => $property) {
|
foreach ($settingsService->defaultPropList as $propertyKey => $property) {
|
||||||
$productSelected = false; ?>
|
$productSelected = false; ?>
|
||||||
|
|
||||||
<tr class="adm-list-table-row">
|
<tr class="adm-list-table-row">
|
||||||
@ -473,6 +473,95 @@ if ($STEP === 1) {
|
|||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
} ?>
|
} ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$productSelected = false;
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$productSelected = $settingsService->isOptionSelected(
|
||||||
|
$prop,
|
||||||
|
$arIBlock['OLD_PROPERTY_PRODUCT_SELECT'],
|
||||||
|
$catalogCustomPropCode
|
||||||
|
);
|
||||||
|
|
||||||
|
$productHlTableName
|
||||||
|
= $settingsService->getHlTableName($prop)
|
||||||
|
?? $productHlTableName;
|
||||||
|
|
||||||
|
echo $productSelected ? ' selected' : '';
|
||||||
|
?>
|
||||||
|
>
|
||||||
|
<?=$prop['NAME']?>
|
||||||
|
</option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<?php if ($arIBlock['PROPERTIES_SKU'] !== null) {
|
||||||
|
$productSelected = false; ?>
|
||||||
|
<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_SKU'] as $prop) {
|
||||||
|
$skuHlTableName = ''; ?>
|
||||||
|
<option value="<?=$prop['CODE']?>"
|
||||||
|
<?php
|
||||||
|
echo $settingsService->getOptionClass($prop, false);
|
||||||
|
|
||||||
|
if (!$productSelected) {
|
||||||
|
$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 } ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<button class="adm-btn-save add-custom-row" type="button">Добавить</button>
|
<button class="adm-btn-save add-custom-row" type="button">Добавить</button>
|
||||||
@ -484,7 +573,7 @@ if ($STEP === 1) {
|
|||||||
} ?>
|
} ?>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="count_checked" id="count_checked" value="<?=$intCountChecked?>">
|
<input type="hidden" name="count_checked" id="count_checked" value="<?=$intCountChecked?>">
|
||||||
<!-- <br>-->
|
<br>
|
||||||
<template id="custom-property-template-row">
|
<template id="custom-property-template-row">
|
||||||
<tr class="adm-list-table-row custom-property-row">
|
<tr class="adm-list-table-row custom-property-row">
|
||||||
<td class="adm-list-table-cell">
|
<td class="adm-list-table-cell">
|
||||||
@ -495,7 +584,7 @@ if ($STEP === 1) {
|
|||||||
</td>
|
</td>
|
||||||
<td class="adm-list-table-cell">
|
<td class="adm-list-table-cell">
|
||||||
<select name="iblockPropertySku_" id="iiblockPropertySku_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
|
<select name="iblockPropertySku_" id="iiblockPropertySku_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
|
||||||
<button id="delete-custom-row" class="adm-btn-save" type="button">Удалить</button>
|
<button id="delete-new-custom-row" class="adm-btn-save" type="button">Удалить</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
@ -787,14 +876,33 @@ if ($STEP === 1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setupFieldsListElement = $('input[name="SETUP_FIELDS_LIST"]');
|
const setupFieldsListElement = $('input[name="SETUP_FIELDS_LIST"]');
|
||||||
let customProperties = {};
|
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_'
|
||||||
|
];
|
||||||
|
|
||||||
$('.add-custom-row').click(function () {
|
$('.add-custom-row').click(function () {
|
||||||
createCustomPropsRaw($(this));
|
createCustomPropsRaw($(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '#delete-new-custom-row', function () {
|
||||||
|
deleteCustomPropRow($(this));
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('click', '#delete-custom-row', function () {
|
$(document).on('click', '#delete-custom-row', function () {
|
||||||
deleteCustomPropsRaw($(this));
|
let buttonElem = $(this);
|
||||||
|
addCustomPropToDelete(buttonElem);
|
||||||
|
deleteCustomPropRow(buttonElem);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('blur', 'input[name="custom-property-title"]', function () {
|
$(document).on('blur', 'input[name="custom-property-title"]', function () {
|
||||||
@ -811,19 +919,36 @@ if ($STEP === 1) {
|
|||||||
|
|
||||||
$('#submit-form').submit(function (formEvent) {
|
$('#submit-form').submit(function (formEvent) {
|
||||||
formEvent.preventDefault();
|
formEvent.preventDefault();
|
||||||
|
let savePromise = null;
|
||||||
|
let deletePromise = null;
|
||||||
let formElem = formEvent.currentTarget;
|
let formElem = formEvent.currentTarget;
|
||||||
let profileId = $($('input[name="PROFILE_ID"]')).val();
|
let profileId = $($('input[name="PROFILE_ID"]')).val();
|
||||||
|
|
||||||
setCustomProperties();
|
setCustomProperties();
|
||||||
|
|
||||||
if (Object.keys(customProperties).length > 0) {
|
if (Object.keys(customProps).length > 0) {
|
||||||
addParamsToSetupFieldsList();
|
savePromise = BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
|
||||||
BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
|
|
||||||
json: {
|
json: {
|
||||||
properties: customProperties,
|
properties: customProps,
|
||||||
profileId: profileId
|
profileId: profileId
|
||||||
},
|
},
|
||||||
}).then(function() {
|
}).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();
|
formElem.submit();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -831,6 +956,29 @@ if ($STEP === 1) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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)
|
function addCustomPropCodeToSelectAttributes(customPropCode, customPropTitleElem)
|
||||||
{
|
{
|
||||||
let selectElements = customPropTitleElem.closest('.custom-property-row').find('td select');
|
let selectElements = customPropTitleElem.closest('.custom-property-row').find('td select');
|
||||||
@ -851,7 +999,6 @@ if ($STEP === 1) {
|
|||||||
function triggerSelectChange(selectElem)
|
function triggerSelectChange(selectElem)
|
||||||
{
|
{
|
||||||
if (selectElem.val().length > 0) {
|
if (selectElem.val().length > 0) {
|
||||||
console.log('был')
|
|
||||||
selectElem.trigger('change', [self]);
|
selectElem.trigger('change', [self]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -893,9 +1040,9 @@ if ($STEP === 1) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (catalogIds.indexOf(customPropertyCatalogId) === -1) {
|
if (catalogIds.indexOf(customPropertyCatalogId) === -1) {
|
||||||
customProperties[customPropertyCatalogId] = [values];
|
customProps[customPropertyCatalogId] = [values];
|
||||||
} else {
|
} else {
|
||||||
customProperties[customPropertyCatalogId].push(values);
|
customProps[customPropertyCatalogId].push(values);
|
||||||
}
|
}
|
||||||
catalogIds.push(customPropertyCatalogId);
|
catalogIds.push(customPropertyCatalogId);
|
||||||
});
|
});
|
||||||
@ -917,22 +1064,14 @@ if ($STEP === 1) {
|
|||||||
function addParamsToSetupFieldsList()
|
function addParamsToSetupFieldsList()
|
||||||
{
|
{
|
||||||
let newParams = '';
|
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)) {
|
if (Object.keys(customProps).length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let propertiesByCatalogId of Object.values(customProps)) {
|
||||||
propertiesByCatalogId.forEach(function (values) {
|
propertiesByCatalogId.forEach(function (values) {
|
||||||
parametersToFill.forEach(function (param) {
|
setupFieldsParamsToFill.forEach(function (param) {
|
||||||
newParams += ',' + param + values.code;
|
newParams += ',' + param + values.code;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -940,6 +1079,30 @@ if ($STEP === 1) {
|
|||||||
|
|
||||||
let newValue = setupFieldsListElement.val() + newParams;
|
let newValue = setupFieldsListElement.val() + newParams;
|
||||||
setupFieldsListElement.val(newValue);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCustomPropsRaw(addRowButton)
|
function createCustomPropsRaw(addRowButton)
|
||||||
@ -958,11 +1121,6 @@ if ($STEP === 1) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteCustomPropsRaw(buttonEvent)
|
|
||||||
{
|
|
||||||
buttonEvent.closest('tr').remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
function fillTemplateSelect(sourceSelectElement, templateSelectElement)
|
function fillTemplateSelect(sourceSelectElement, templateSelectElement)
|
||||||
{
|
{
|
||||||
let selectOptions = sourceSelectElement.find('option');
|
let selectOptions = sourceSelectElement.find('option');
|
||||||
|
@ -17,7 +17,7 @@ $('#submit-form').submit(function (formEvent) {
|
|||||||
addParamsToSetupFieldsList();
|
addParamsToSetupFieldsList();
|
||||||
|
|
||||||
BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
|
BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
|
||||||
json: {properties: customProperties},
|
json: {properties: customProps},
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
formElem.submit();
|
formElem.submit();
|
||||||
});
|
});
|
||||||
@ -75,9 +75,9 @@ function setCustomProperties()
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (catalogIds.indexOf(customPropertyCatalogId) === -1) {
|
if (catalogIds.indexOf(customPropertyCatalogId) === -1) {
|
||||||
customProperties[customPropertyCatalogId] = [values];
|
customProps[customPropertyCatalogId] = [values];
|
||||||
} else {
|
} else {
|
||||||
customProperties[customPropertyCatalogId].push(values);
|
customProps[customPropertyCatalogId].push(values);
|
||||||
}
|
}
|
||||||
catalogIds.push(customPropertyCatalogId);
|
catalogIds.push(customPropertyCatalogId);
|
||||||
});
|
});
|
||||||
@ -112,7 +112,7 @@ function addParamsToSetupFieldsList()
|
|||||||
'highloadblock_producteshop_brand_reference_'
|
'highloadblock_producteshop_brand_reference_'
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let propertiesByCatalogId of Object.values(customProperties)) {
|
for (let propertiesByCatalogId of Object.values(customProps)) {
|
||||||
propertiesByCatalogId.forEach(function (values) {
|
propertiesByCatalogId.forEach(function (values) {
|
||||||
parametersToFill.forEach(function (param) {
|
parametersToFill.forEach(function (param) {
|
||||||
newParams += ',' + param + values.code;
|
newParams += ',' + param + values.code;
|
||||||
|
@ -24,7 +24,7 @@ class CustomExportProps extends Controller
|
|||||||
$response->setStatus(new Error('Ошибка'));
|
$response->setStatus(new Error('Ошибка'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$requestData = json_decode($this->getRequest()->getInput(), true);
|
$requestData = json_decode($request, true);
|
||||||
$properties = $requestData['properties'];
|
$properties = $requestData['properties'];
|
||||||
$profileId = $requestData['profileId'];
|
$profileId = $requestData['profileId'];
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ class CustomExportProps extends Controller
|
|||||||
$profileId,
|
$profileId,
|
||||||
$catalogId
|
$catalogId
|
||||||
);
|
);
|
||||||
|
|
||||||
$saveResult = file_put_contents($filePath, $newPropertiesString, FILE_APPEND);
|
$saveResult = file_put_contents($filePath, $newPropertiesString, FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +53,27 @@ class CustomExportProps extends Controller
|
|||||||
|
|
||||||
public function deleteAction()
|
public function deleteAction()
|
||||||
{
|
{
|
||||||
|
$request = $this->getRequest()->getInput();
|
||||||
|
|
||||||
|
$requestData = json_decode($request, true);
|
||||||
|
$properties = $requestData['properties'];
|
||||||
|
$profileId = $requestData['profileId'];
|
||||||
|
|
||||||
|
foreach ($properties as $catalogId => $propsArray) {
|
||||||
|
$filePath = sprintf(
|
||||||
|
'%s/%s_profileId_%s_catalogId_%s.txt',
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] . '/local',
|
||||||
|
'icml_property_retailcrm',
|
||||||
|
$profileId,
|
||||||
|
$catalogId
|
||||||
|
);
|
||||||
|
$fileContent = file_get_contents($filePath);
|
||||||
|
|
||||||
|
foreach ($propsArray as $property) {
|
||||||
|
$propStringToDelete = PHP_EOL . $property['code'] . ' = ' . $property['title'];
|
||||||
|
$fileContent = str_replace($propStringToDelete, '', $fileContent);
|
||||||
|
}
|
||||||
|
file_put_contents($filePath, $fileContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -167,7 +167,14 @@ class SettingsService
|
|||||||
...$this->defaultPropList,
|
...$this->defaultPropList,
|
||||||
...$customProps
|
...$customProps
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFrontPropList(): array
|
||||||
|
{
|
||||||
|
$result = [...$this->defaultPropList];
|
||||||
|
$result['customProps'] = $this->customPropList;
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPriceTypes()
|
public function getPriceTypes()
|
||||||
|
Loading…
Reference in New Issue
Block a user