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" + ]; + } +}