From b8ac495a377b83a6d5b92198203eef0e6372af82 Mon Sep 17 00:00:00 2001
From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com>
Date: Thu, 18 Jan 2024 11:48:35 +0300
Subject: [PATCH] =?UTF-8?q?ref=20#93387=20=D0=AD=D0=BA=D1=81=D0=BF=D0=BE?=
=?UTF-8?q?=D1=80=D1=82=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82?=
=?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D1=81=D0=B2=D0=BE=D0=B9?=
=?UTF-8?q?=D1=81=D1=82=D0=B2=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=BE=D0=B2?=
=?UTF-8?q?=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD=D1=84?=
=?UTF-8?q?=D0=B8=D0=B3=D1=83=D1=80=D0=B8=D1=80=D1=83=D0=B5=D0=BC=D1=8B?=
=?UTF-8?q?=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20(#334)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CHANGELOG.md | 3 +
intaro.retailcrm/description.ru | 2 +-
intaro.retailcrm/export/export_run.php | 15 +---
intaro.retailcrm/export/export_setup.php | 6 +-
intaro.retailcrm/install/index.php | 1 +
intaro.retailcrm/install/version.php | 4 +-
.../component/installer/installertrait.php | 15 +++-
intaro.retailcrm/lib/icml/settingsservice.php | 84 +++++++++++--------
intaro.retailcrm/lib/icml/xmlofferbuilder.php | 16 ++--
intaro.retailcrm/updater.php | 16 ++++
tests/lib/icml/SettingServiceTest.php | 49 +++++++++++
11 files changed, 150 insertions(+), 61 deletions(-)
create mode 100644 tests/lib/icml/SettingServiceTest.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 610946ab..d71f2cd1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 2024-01-12 v.6.5.6
+- Добавлена передача дополнительных свойств товаров через конфигурируемый файл
+
## 2024-01-09 v.6.5.5
- Исправлен вывод справочников при установке модуля
diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru
index 2eda76f6..f3e26994 100644
--- a/intaro.retailcrm/description.ru
+++ b/intaro.retailcrm/description.ru
@@ -1 +1 @@
-- Исправлен вывод справочников при установке модуля
+- Добавлена передача дополнительных свойств товаров через конфигурируемый файл
diff --git a/intaro.retailcrm/export/export_run.php b/intaro.retailcrm/export/export_run.php
index 4449c336..22c74766 100644
--- a/intaro.retailcrm/export/export_run.php
+++ b/intaro.retailcrm/export/export_run.php
@@ -6,6 +6,7 @@ use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetup;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupProps;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupPropsCategories;
use Intaro\RetailCrm\Repository\CatalogRepository;
+use Intaro\RetailCrm\Icml\SettingsService;
/** @var $SETUP_FILE_NAME */
@@ -37,17 +38,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
}
}
- $iblockProperties = [
- 'article' => 'article',
- 'manufacturer' => 'manufacturer',
- 'color' => 'color',
- 'weight' => 'weight',
- 'size' => 'size',
- 'length' => 'length',
- 'width' => 'width',
- 'height' => 'height',
- ];
-
+ $settingService = SettingsService::getInstance([], '');
$iblockPropertySku = [];
$iblockPropertySkuHl = [];
$iblockPropertyUnitSku = [];
@@ -55,7 +46,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
$iblockPropertyProductHl = [];
$iblockPropertyUnitProduct = [];
- foreach ($iblockProperties as $prop) {
+ foreach (array_keys($settingService->actrualPropList) as $prop) {
$skuUnitProps = ('iblockPropertyUnitSku_' . $prop);
$skuUnitProps = $$skuUnitProps;
diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php
index 51467fc4..d9d0f91e 100644
--- a/intaro.retailcrm/export/export_setup.php
+++ b/intaro.retailcrm/export/export_setup.php
@@ -49,7 +49,6 @@ __IncludeLang(GetLangFileName(
$basePriceId = RetailcrmConfigProvider::getCrmBasePrice($_REQUEST['PROFILE_ID']);
$priceTypes = $settingsService->priceTypes;
$iblockFieldsName = $settingsService->getIblockFieldsNames();
-$iblockPropertiesHint = $settingsService->getHintProps();
$units = $settingsService->getUnitsNames();
$hintUnit = $settingsService->getHintUnit();
@@ -63,7 +62,6 @@ if (($ACTION === 'EXPORT' || $ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_CO
$SETUP_FILE_NAME = $settingsService->setupFileName;
$SETUP_PROFILE_NAME = $settingsService->setupProfileName;
- $iblockProperties = $settingsService->getIblockPropsPreset();
$loadPurchasePrice = $settingsService->loadPurchasePrice;
$iblockExport = $settingsService->iblockExport;
$loadNonActivity = $settingsService->loadNonActivity;
@@ -192,7 +190,7 @@ if ($STEP === 1) {
getIblockPropsNames() as $propertyKey => $property) {
+ foreach ($settingsService->actrualPropList as $propertyKey => $property) {
$productSelected = false; ?>
@@ -568,7 +566,7 @@ if ($STEP === 1) {
getPriceTypes();
$this->getVatRates();
+
+ $this->actrualPropList = array_merge($this->getIblockPropsPreset(), $this->parseNewProps());
}
/**
@@ -131,12 +137,12 @@ class SettingsService
*
* @return \Intaro\RetailCrm\Icml\SettingsService|null
*/
- static public function getInstance(array $arOldSetupVars, ?string $action): ?SettingsService
+ public static function getInstance(array $arOldSetupVars, ?string $action): ?SettingsService
{
- if(is_null(self::$instance))
- {
+ if (is_null(self::$instance)) {
self::$instance = new self($arOldSetupVars, $action);
}
+
return self::$instance;
}
@@ -239,21 +245,47 @@ class SettingsService
/**
* @return string[]
*/
- public function getIblockPropsPreset(): array
+ private function getIblockPropsPreset(): array
{
return [
- 'article' => 'article',
- 'manufacturer' => 'manufacturer',
- 'color' => 'color',
- 'size' => 'size',
- 'weight' => 'weight',
- 'length' => 'length',
- 'width' => 'width',
- 'height' => 'height',
- 'picture' => 'picture',
+ 'article' => GetMessage('PROPERTY_ARTICLE_HEADER_NAME'),
+ 'manufacturer' => GetMessage('PROPERTY_MANUFACTURER_HEADER_NAME'),
+ 'color' => GetMessage('PROPERTY_COLOR_HEADER_NAME'),
+ 'size' => GetMessage('PROPERTY_SIZE_HEADER_NAME'),
+ 'weight' => GetMessage('PROPERTY_WEIGHT_HEADER_NAME'),
+ 'length' => GetMessage('PROPERTY_LENGTH_HEADER_NAME'),
+ 'width' => GetMessage('PROPERTY_WIDTH_HEADER_NAME'),
+ 'height' => GetMessage('PROPERTY_HEIGHT_HEADER_NAME'),
+ 'picture' => GetMessage('PROPERTY_PICTURE_HEADER_NAME'),
];
}
+ private function parseNewProps(): array
+ {
+ global $APPLICATION;
+
+ $result = [];
+ $text = $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . "/local/icml_property_retailcrm.txt");
+
+ if ($text === false) {
+ return $result;
+ }
+
+ preg_match_all('/\w+\s*=\s*\w+[ *\w+]*/mu', $text, $matches);
+
+ foreach ($matches[0] as $newProp) {
+ $elements = explode("=", $newProp);
+
+ if (empty($elements[0]) || empty($elements[1])) {
+ continue;
+ }
+
+ $result[trim($elements[0])] = trim($elements[1]);
+ }
+
+ return $result;
+ }
+
/**
* @return array
*/
@@ -272,24 +304,6 @@ class SettingsService
];
}
- /**
- * @return array
- */
- public function getIblockPropsNames(): array
- {
- return [
- 'article' => GetMessage('PROPERTY_ARTICLE_HEADER_NAME'),
- 'manufacturer' => GetMessage('PROPERTY_MANUFACTURER_HEADER_NAME'),
- 'color' => GetMessage('PROPERTY_COLOR_HEADER_NAME'),
- 'size' => GetMessage('PROPERTY_SIZE_HEADER_NAME'),
- 'weight' => GetMessage('PROPERTY_WEIGHT_HEADER_NAME'),
- 'length' => GetMessage('PROPERTY_LENGTH_HEADER_NAME'),
- 'width' => GetMessage('PROPERTY_WIDTH_HEADER_NAME'),
- 'height' => GetMessage('PROPERTY_HEIGHT_HEADER_NAME'),
- 'picture' => GetMessage('PROPERTY_PICTURE_HEADER_NAME'),
- ];
- }
-
/**
* @return array[]
*/
@@ -351,7 +365,7 @@ class SettingsService
public function setProps(): void
{
- foreach ($this->getIblockPropsPreset() as $prop) {
+ foreach (array_keys($this->actrualPropList) as $prop) {
$this->setProperties($this->iblockPropertySku, 'iblockPropertySku_' . $prop);
$this->setProperties($this->iblockPropertyUnitSku, 'iblockPropertyUnitSku_' . $prop);
$this->setProperties($this->iblockPropertyProduct, 'iblockPropertyProduct_' . $prop);
@@ -587,9 +601,9 @@ class SettingsService
$props = [];
if (isset($oldValues[$iblockId])) {
- foreach ($this->getIblockPropsNames() as $key => $prop) {
- $fullKey = $keyGroup . '_' . $key;
- $props[$key] = $oldValues[$iblockId][$fullKey];
+ foreach (array_keys($this->actrualPropList) as $prop) {
+ $fullKey = $keyGroup . '_' . $prop;
+ $props[$prop] = $oldValues[$iblockId][$fullKey];
}
}
diff --git a/intaro.retailcrm/lib/icml/xmlofferbuilder.php b/intaro.retailcrm/lib/icml/xmlofferbuilder.php
index ce3f3375..68a7dd8c 100644
--- a/intaro.retailcrm/lib/icml/xmlofferbuilder.php
+++ b/intaro.retailcrm/lib/icml/xmlofferbuilder.php
@@ -94,6 +94,11 @@ class XmlOfferBuilder
*/
private $vatRates;
+ /**
+ * @var SettingsService
+ */
+ private $settingsService;
+
/**
* IcmlDataManager constructor.
*
@@ -107,9 +112,8 @@ class XmlOfferBuilder
{
$this->setup = $setup;
$this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice();
- /** @var \Intaro\RetailCrm\Icml\SettingsService $settingsService */
- $settingsService = SettingsService::getInstance([], '');
- $this->vatRates = $settingsService->vatRates;
+ $this->settingsService = SettingsService::getInstance([], '');
+ $this->vatRates = $this->settingsService->vatRates;
$this->measures = $this->prepareMeasures($measure);
$this->defaultServerName = $defaultServerName;
}
@@ -461,16 +465,16 @@ class XmlOfferBuilder
private function createParamObject(array $params): array
{
$offerParams = [];
+ $names = $this->settingsService->actrualPropList;
foreach ($params as $code => $value) {
- $paramName = GetMessage('PARAM_NAME_' . $code);
- if (empty($paramName)) {
+ if (!isset($names[$code])) {
continue;
}
$offerParam = new OfferParam();
- $offerParam->name = $paramName;
+ $offerParam->name = $names[$code];
$offerParam->code = $code;
$offerParam->value = $value;
$offerParams[] = $offerParam;
diff --git a/intaro.retailcrm/updater.php b/intaro.retailcrm/updater.php
index 35b823a2..a7c1f0d8 100644
--- a/intaro.retailcrm/updater.php
+++ b/intaro.retailcrm/updater.php
@@ -1203,8 +1203,24 @@ function update()
'custom_fields_toggle',
'N'
);
+
+ createCustomPropertyFile();
}
+function createCustomPropertyFile()
+{
+ $path = $_SERVER['DOCUMENT_ROOT'] . '/local/';
+
+ CheckDirPath($path);
+
+ $file = new \Bitrix\Main\IO\File($path . 'icml_property_retailcrm.txt', $siteId = null);
+
+ if (!$file->isExists()) {
+ $file->putContents("");
+ }
+}
+
+
try {
update();
} catch (Main\ObjectPropertyException | Main\ArgumentException | Main\SystemException $exception) {
diff --git a/tests/lib/icml/SettingServiceTest.php b/tests/lib/icml/SettingServiceTest.php
new file mode 100644
index 00000000..2fed5dde
--- /dev/null
+++ b/tests/lib/icml/SettingServiceTest.php
@@ -0,0 +1,49 @@
+mockSettingService = $this->getMockBuilder(SettingsService::class)
+ ->disableOriginalConstructor()
+ ->getMock()
+ ;
+ }
+
+ public function testConstruct(): SettingsService
+ {
+ $path = $_SERVER['DOCUMENT_ROOT'] . '/local/';
+
+ CheckDirPath($path);
+
+ $file = new \Bitrix\Main\IO\File($path . '/icml_property_retailcrm.txt', $siteId = null);
+
+ $file->putContents("property1 = test prop \n property2 = test prop 2");
+
+ $settingService = SettingsService::getInstance($this->getSetupVars(), "");
+
+ $this->assertInstanceOf(SettingsService::class, $settingService);
+ $this->assertArrayHasKey('property1', $settingService->actrualPropList);
+ $this->assertArrayHasKey('property2', $settingService->actrualPropList);
+
+ return $settingService;
+ }
+
+ private function getSetupVars()
+ {
+ return [
+ 'iblockExport' => 2,
+ 'loadPurchasePrice' => "",
+ 'loadNonActivity' => "",
+ 'SETUP_FILE_NAME' => "/bitrix/catalog_export/retailcrm.xml",
+ 'SETUP_PROFILE_NAME' => "Выгрузка каталога RetailCRM"
+ ];
+ }
+}