From ee02f45637d45684bc57d624d3305f6a48989c81 Mon Sep 17 00:00:00 2001 From: "a.belikin" Date: Wed, 6 Nov 2024 19:30:00 +0300 Subject: [PATCH] MVP --- intaro.retailcrm/export/export_setup.php | 204 +++++++++++++++++- intaro.retailcrm/include.php | 4 + .../bitrix/js/intaro/custom-props-export.js | 94 ++++++++ .../lib/controller/customexportprops.php | 54 +++++ 4 files changed, 353 insertions(+), 3 deletions(-) create mode 100644 intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js create mode 100644 intaro.retailcrm/lib/controller/customexportprops.php diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php index d9d0f91e..1baa20d6 100644 --- a/intaro.retailcrm/export/export_setup.php +++ b/intaro.retailcrm/export/export_setup.php @@ -110,7 +110,7 @@ if ($STEP === 1) { } -
+ @@ -475,6 +475,7 @@ if ($STEP === 1) { } ?> +

@@ -483,7 +484,21 @@ if ($STEP === 1) { } ?> -
+ +



function checkLoadStatus(object) { @@ -770,6 +784,190 @@ if ($STEP === 1) { return select; } + + 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)); + }); + + $('#submit-form').submit(function (formEvent) { + let formElem = formEvent.currentTarget; + formEvent.preventDefault(); + setCustomProperties(); + addParamsToSetupFieldsList(); + + BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', { + json: {properties: customProperties}, + }).then(function(response) { + formElem.submit(); + }); + }); + + function setCustomProperties() + { + let customPropertiesRows = $('.custom-property-row'); + 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(); + 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; + }); + }); + } + + setupFieldsListElement.value = setupFieldsListElement.value + ',' + newParams; + } + + function createCustomPropsRaw(buttonEvent) + { + let rawTemplate = $($('#custom-property-template-row').html()); + let templateSelectElements = rawTemplate.find('select'); + + let lastTableRow = $(buttonEvent).prev('table').find('tbody tr:last-child'); + let lastRawSelectElements = lastTableRow.find('td select'); + + lastRawSelectElements.each(function (index, element) { + let selectElement = $(element); + let templateSelectElement = templateSelectElements[index]; + fillTemplateSelect(selectElement, templateSelectElement); + lastTableRow.after(rawTemplate); + }); + } + + function deleteCustomPropsRaw(buttonEvent) + { + buttonEvent.closest('tr').remove(); + } + + function fillTemplateSelect(sourceSelectElement, templateSelectElement) + { + let name = sourceSelectElement.attr('name'); + let id = sourceSelectElement.attr('id'); + let type = sourceSelectElement.data('type'); + templateSelectElement.setAttribute('name', name); + templateSelectElement.setAttribute('id', id); + templateSelectElement.setAttribute('data-type', type); + + let selectOptions = sourceSelectElement.find('option'); + selectOptions.each(function (index, element) { + let optionElem = $(element); + let value = $(optionElem).val(); + let text = $(optionElem).text(); + + $('