Skip to content

Commit

Permalink
Динамическое добавление свойств в ICML (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Dec 10, 2024
1 parent 1ec3bcc commit 3162031
Show file tree
Hide file tree
Showing 15 changed files with 818 additions and 119 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2024-12-09 v6.6.0
- Добавлено динамическое изменение свойств товаров при настройке экспорта

## 2024-12-08 v6.5.39
- Исправлена поломка заказов с промокодом Maxma при включенной передаче корзины в CRM

Expand Down
2 changes: 1 addition & 1 deletion intaro.retailcrm/description.ru
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Исправлена поломка заказов с промокодом Maxma при включенной передаче корзины в CRM
- Добавлено динамическое изменение свойств товаров при настройке экспорта
5 changes: 3 additions & 2 deletions intaro.retailcrm/export/export_run.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@
}
}

$settingService = SettingsService::getInstance([], '');
global $PROFILE_ID;
$settingService = SettingsService::getInstance([], '', $PROFILE_ID);
$iblockPropertySku = [];
$iblockPropertySkuHl = [];
$iblockPropertyUnitSku = [];
$iblockPropertyProduct = [];
$iblockPropertyProductHl = [];
$iblockPropertyUnitProduct = [];

foreach (array_keys($settingService->actrualPropList) as $prop) {
foreach (array_keys($settingService->actualPropList) as $prop) {
$skuUnitProps = ('iblockPropertyUnitSku_' . $prop);
$skuUnitProps = $$skuUnitProps;

Expand Down
246 changes: 224 additions & 22 deletions intaro.retailcrm/export/export_setup.php

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions intaro.retailcrm/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
'js' => '/bitrix/js/intaro/sms.js',
'rel' => [],
],
'intaro_custom_props' => [
'js' => '/bitrix/js/intaro/export/custom-props-export.js',
'rel' => [],
],
];

foreach ($arJsConfig as $ext => $arExt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@

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 = {
'code': deletedPropCode,
'title': deletedPropTitle,
};

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]);
}
}

function setCustomProperties()
{
let customPropertiesRows = $('.custom-property-row');

if (customPropertiesRows.length === 0) {
return;
}

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;
}

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];
} else {
customProps[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 = '';

if (Object.keys(customProps).length === 0) {
return;
}

for (let propertiesByCatalogId of Object.values(customProps)) {
propertiesByCatalogId.forEach(function (values) {
setupFieldsParamsToFill.forEach(function (param) {
newParams += ',' + param + values.code;
});
});
}

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)
{
let templateRow = $($('#custom-property-template-row').html());
let templateSelectElements = templateRow.find('select');

let prevTableRow = $(addRowButton).prev('table').find('tbody tr:last-child');
let lastRawSelectElements = prevTableRow.find('td select');

lastRawSelectElements.each(function (index, element) {
let selectElement = $(element);
let templateSelectElement = templateSelectElements[index];
fillTemplateSelect(selectElement, templateSelectElement);
prevTableRow.after(templateRow);
});
}

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;
}

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;
}
4 changes: 2 additions & 2 deletions intaro.retailcrm/install/version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$arModuleVersion = [
'VERSION' => '6.5.39',
'VERSION_DATE' => '2024-12-08 18:30:00'
'VERSION' => '6.6.0',
'VERSION_DATE' => '2024-12-09 14:00:00'
];
2 changes: 2 additions & 0 deletions intaro.retailcrm/lang/en/icml_export_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@
$MESS['WAIT'] = 'Loading...';
$MESS["OFFERS_VALUE"] = "Maximum number of trade offers for a product";
$MESS["LOAD_NON_ACTIVITY"] = "Unload inactive products, services and trade offers";
$MESS["ADD_PROPERTY"] = "Add property";
$MESS["DELETE_PROPERTY"] = "Delete";
2 changes: 2 additions & 0 deletions intaro.retailcrm/lang/ru/icml_export_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@
$MESS['BASE_PRICE'] = 'Базовая цена';
$MESS['WAIT'] = 'Загрузка...';
$MESS["OFFERS_VALUE"] = "Максимальное количество торговых предложений у товара";
$MESS["ADD_PROPERTY"] = "Добавить свойство";
$MESS["DELETE_PROPERTY"] = "Удалить";
20 changes: 12 additions & 8 deletions intaro.retailcrm/lib/component/advanced/installertrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ public function installExport()
false
);

$path = $_SERVER['DOCUMENT_ROOT'] . '/local/';

CheckDirPath($path);

$file = new \Bitrix\Main\IO\File($path . 'icml_property_retailcrm.txt', $siteId = null);
$pathFrom = $_SERVER['DOCUMENT_ROOT'] .
'/bitrix/modules/' .
Constants::MODULE_ID .
'/install/export/bitrix/js/intaro/export'
;

if (!$file->isExists()) {
$file->putContents("");
}
CopyDirFiles(
$pathFrom,
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/js/intaro/export/',
true,
true,
false
);
}

public function subscriptionSetup()
Expand Down
Loading

0 comments on commit 3162031

Please sign in to comment.