From 7c762dff2fe208468a5bc272594fd0c9c9f11a2d Mon Sep 17 00:00:00 2001 From: "a.belikin" Date: Mon, 11 Nov 2024 19:36:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2,=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=BE=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2.=20?= =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BE=D0=BC=D0=B0=D0=BB=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=B8=D0=BB=D0=B8=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/export/export_setup.php | 230 +++++++++++++++--- .../bitrix/js/intaro/custom-props-export.js | 8 +- .../lib/controller/customexportprops.php | 26 +- intaro.retailcrm/lib/icml/settingsservice.php | 7 + 4 files changed, 229 insertions(+), 42 deletions(-) diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php index 2dbaaf5e..adc7f3f1 100644 --- a/intaro.retailcrm/export/export_setup.php +++ b/intaro.retailcrm/export/export_setup.php @@ -190,7 +190,7 @@ if ($STEP === 1) { actrualPropList as $propertyKey => $property) { + foreach ($settingsService->defaultPropList as $propertyKey => $property) { $productSelected = false; ?> @@ -473,6 +473,95 @@ if ($STEP === 1) { + + customPropList[$catalogId]; + + foreach ($catalogCustomProps as $catalogCustomPropCode => $catalogCustomPropValue) { ?> + + + + + + + + + + + + + + + + @@ -484,7 +573,7 @@ if ($STEP === 1) { } ?> - +
@@ -787,14 +876,33 @@ if ($STEP === 1) { } 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 () { createCustomPropsRaw($(this)); }); + $(document).on('click', '#delete-new-custom-row', function () { + deleteCustomPropRow($(this)); + }); + $(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 () { @@ -811,26 +919,66 @@ if ($STEP === 1) { $('#submit-form').submit(function (formEvent) { formEvent.preventDefault(); - + let savePromise = null; + let deletePromise = null; let formElem = formEvent.currentTarget; let profileId = $($('input[name="PROFILE_ID"]')).val(); + setCustomProperties(); - if (Object.keys(customProperties).length > 0) { - addParamsToSetupFieldsList(); - BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', { + if (Object.keys(customProps).length > 0) { + savePromise = BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', { json: { - properties: customProperties, + properties: customProps, profileId: profileId }, - }).then(function() { - formElem.submit(); - }); + }).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(); + formElem.submit(); } }); + 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'); @@ -851,7 +999,6 @@ if ($STEP === 1) { function triggerSelectChange(selectElem) { if (selectElem.val().length > 0) { - console.log('был') selectElem.trigger('change', [self]); } } @@ -893,9 +1040,9 @@ if ($STEP === 1) { }; if (catalogIds.indexOf(customPropertyCatalogId) === -1) { - customProperties[customPropertyCatalogId] = [values]; + customProps[customPropertyCatalogId] = [values]; } else { - customProperties[customPropertyCatalogId].push(values); + customProps[customPropertyCatalogId].push(values); } catalogIds.push(customPropertyCatalogId); }); @@ -917,22 +1064,14 @@ if ($STEP === 1) { 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)) { + if (Object.keys(customProps).length === 0) { + return; + } + + for (let propertiesByCatalogId of Object.values(customProps)) { propertiesByCatalogId.forEach(function (values) { - parametersToFill.forEach(function (param) { + setupFieldsParamsToFill.forEach(function (param) { newParams += ',' + param + values.code; }); }); @@ -940,6 +1079,30 @@ if ($STEP === 1) { 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; } function createCustomPropsRaw(addRowButton) @@ -958,11 +1121,6 @@ if ($STEP === 1) { }); } - function deleteCustomPropsRaw(buttonEvent) - { - buttonEvent.closest('tr').remove(); - } - function fillTemplateSelect(sourceSelectElement, templateSelectElement) { let selectOptions = sourceSelectElement.find('option'); diff --git a/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js b/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js index 94065dc3..35014e28 100644 --- a/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js +++ b/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js @@ -17,7 +17,7 @@ $('#submit-form').submit(function (formEvent) { addParamsToSetupFieldsList(); BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', { - json: {properties: customProperties}, + json: {properties: customProps}, }).then(function() { formElem.submit(); }); @@ -75,9 +75,9 @@ function setCustomProperties() }; if (catalogIds.indexOf(customPropertyCatalogId) === -1) { - customProperties[customPropertyCatalogId] = [values]; + customProps[customPropertyCatalogId] = [values]; } else { - customProperties[customPropertyCatalogId].push(values); + customProps[customPropertyCatalogId].push(values); } catalogIds.push(customPropertyCatalogId); }); @@ -112,7 +112,7 @@ function addParamsToSetupFieldsList() 'highloadblock_producteshop_brand_reference_' ]; - for (let propertiesByCatalogId of Object.values(customProperties)) { + for (let propertiesByCatalogId of Object.values(customProps)) { propertiesByCatalogId.forEach(function (values) { parametersToFill.forEach(function (param) { newParams += ',' + param + values.code; diff --git a/intaro.retailcrm/lib/controller/customexportprops.php b/intaro.retailcrm/lib/controller/customexportprops.php index aa70c3df..cc16417d 100644 --- a/intaro.retailcrm/lib/controller/customexportprops.php +++ b/intaro.retailcrm/lib/controller/customexportprops.php @@ -24,7 +24,7 @@ class CustomExportProps extends Controller $response->setStatus(new Error('Ошибка')); } - $requestData = json_decode($this->getRequest()->getInput(), true); + $requestData = json_decode($request, true); $properties = $requestData['properties']; $profileId = $requestData['profileId']; @@ -40,6 +40,7 @@ class CustomExportProps extends Controller $profileId, $catalogId ); + $saveResult = file_put_contents($filePath, $newPropertiesString, FILE_APPEND); } @@ -52,6 +53,27 @@ class CustomExportProps extends Controller 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); + } } } \ No newline at end of file diff --git a/intaro.retailcrm/lib/icml/settingsservice.php b/intaro.retailcrm/lib/icml/settingsservice.php index 4c5d60db..88ab9614 100644 --- a/intaro.retailcrm/lib/icml/settingsservice.php +++ b/intaro.retailcrm/lib/icml/settingsservice.php @@ -167,7 +167,14 @@ class SettingsService ...$this->defaultPropList, ...$customProps ]; + } + public function getFrontPropList(): array + { + $result = [...$this->defaultPropList]; + $result['customProps'] = $this->customPropList; + + return $result; } public function getPriceTypes()