1
0
mirror of synced 2024-11-21 21:06:09 +03:00

ref #93387 Экспорт дополнительных свойств товаров через конфигурируемый файл (#334)

This commit is contained in:
Kocmonavtik 2024-01-18 11:48:35 +03:00 committed by GitHub
parent d9cdfced49
commit b8ac495a37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 150 additions and 61 deletions

View File

@ -1,3 +1,6 @@
## 2024-01-12 v.6.5.6
- Добавлена передача дополнительных свойств товаров через конфигурируемый файл
## 2024-01-09 v.6.5.5 ## 2024-01-09 v.6.5.5
- Исправлен вывод справочников при установке модуля - Исправлен вывод справочников при установке модуля

View File

@ -1 +1 @@
- Исправлен вывод справочников при установке модуля - Добавлена передача дополнительных свойств товаров через конфигурируемый файл

View File

@ -6,6 +6,7 @@ use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetup;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupProps; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupProps;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupPropsCategories; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupPropsCategories;
use Intaro\RetailCrm\Repository\CatalogRepository; use Intaro\RetailCrm\Repository\CatalogRepository;
use Intaro\RetailCrm\Icml\SettingsService;
/** @var $SETUP_FILE_NAME */ /** @var $SETUP_FILE_NAME */
@ -37,17 +38,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
} }
} }
$iblockProperties = [ $settingService = SettingsService::getInstance([], '');
'article' => 'article',
'manufacturer' => 'manufacturer',
'color' => 'color',
'weight' => 'weight',
'size' => 'size',
'length' => 'length',
'width' => 'width',
'height' => 'height',
];
$iblockPropertySku = []; $iblockPropertySku = [];
$iblockPropertySkuHl = []; $iblockPropertySkuHl = [];
$iblockPropertyUnitSku = []; $iblockPropertyUnitSku = [];
@ -55,7 +46,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
$iblockPropertyProductHl = []; $iblockPropertyProductHl = [];
$iblockPropertyUnitProduct = []; $iblockPropertyUnitProduct = [];
foreach ($iblockProperties as $prop) { foreach (array_keys($settingService->actrualPropList) as $prop) {
$skuUnitProps = ('iblockPropertyUnitSku_' . $prop); $skuUnitProps = ('iblockPropertyUnitSku_' . $prop);
$skuUnitProps = $$skuUnitProps; $skuUnitProps = $$skuUnitProps;

View File

@ -49,7 +49,6 @@ __IncludeLang(GetLangFileName(
$basePriceId = RetailcrmConfigProvider::getCrmBasePrice($_REQUEST['PROFILE_ID']); $basePriceId = RetailcrmConfigProvider::getCrmBasePrice($_REQUEST['PROFILE_ID']);
$priceTypes = $settingsService->priceTypes; $priceTypes = $settingsService->priceTypes;
$iblockFieldsName = $settingsService->getIblockFieldsNames(); $iblockFieldsName = $settingsService->getIblockFieldsNames();
$iblockPropertiesHint = $settingsService->getHintProps();
$units = $settingsService->getUnitsNames(); $units = $settingsService->getUnitsNames();
$hintUnit = $settingsService->getHintUnit(); $hintUnit = $settingsService->getHintUnit();
@ -63,7 +62,6 @@ if (($ACTION === 'EXPORT' || $ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_CO
$SETUP_FILE_NAME = $settingsService->setupFileName; $SETUP_FILE_NAME = $settingsService->setupFileName;
$SETUP_PROFILE_NAME = $settingsService->setupProfileName; $SETUP_PROFILE_NAME = $settingsService->setupProfileName;
$iblockProperties = $settingsService->getIblockPropsPreset();
$loadPurchasePrice = $settingsService->loadPurchasePrice; $loadPurchasePrice = $settingsService->loadPurchasePrice;
$iblockExport = $settingsService->iblockExport; $iblockExport = $settingsService->iblockExport;
$loadNonActivity = $settingsService->loadNonActivity; $loadNonActivity = $settingsService->loadNonActivity;
@ -192,7 +190,7 @@ if ($STEP === 1) {
<tbody> <tbody>
<?php <?php
foreach ($settingsService->getIblockPropsNames() as $propertyKey => $property) { foreach ($settingsService->actrualPropList as $propertyKey => $property) {
$productSelected = false; ?> $productSelected = false; ?>
<tr class="adm-list-table-row"> <tr class="adm-list-table-row">
@ -568,7 +566,7 @@ if ($STEP === 1) {
<input type="hidden" name="STEP" value="<?=$STEP + 1?>"> <input type="hidden" name="STEP" value="<?=$STEP + 1?>">
<input type="hidden" name="SETUP_FIELDS_LIST" value="<?= <input type="hidden" name="SETUP_FIELDS_LIST" value="<?=
$settingsService->getSetupFieldsString( $settingsService->getSetupFieldsString(
$iblockProperties ?? [], array_keys($settingsService->actrualPropList) ?? [],
$hlblockModule === true, $hlblockModule === true,
$hlBlockList ?? [] $hlBlockList ?? []
) )

View File

@ -252,6 +252,7 @@ class intaro_retailcrm extends CModule
$this->addEvents(); $this->addEvents();
$this->addAgreement(); $this->addAgreement();
$this->addUserFields(); $this->addUserFields();
$this->createCustomPropertyFile();
OrderLoyaltyDataService::createLoyaltyHlBlock(); OrderLoyaltyDataService::createLoyaltyHlBlock();

View File

@ -1,6 +1,6 @@
<?php <?php
$arModuleVersion = [ $arModuleVersion = [
'VERSION' => '6.5.5', 'VERSION' => '6.5.6',
'VERSION_DATE' => '2024-01-09 15:30:00' 'VERSION_DATE' => '2024-01-12 17:00:00'
]; ];

View File

@ -232,6 +232,19 @@ trait InstallerTrait
} }
} }
public function createCustomPropertyFile(): void
{
$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("");
}
}
/** /**
* delete loyalty program events handlers * delete loyalty program events handlers
*/ */

View File

@ -97,11 +97,15 @@ class SettingsService
*/ */
public $loadNonActivity; public $loadNonActivity;
/** @var array */
public $actrualPropList = [];
/** /**
* @var \Intaro\RetailCrm\Icml\SettingsService|null * @var \Intaro\RetailCrm\Icml\SettingsService|null
*/ */
private static $instance = null; private static $instance = null;
/** /**
* SettingsService constructor. * SettingsService constructor.
* *
@ -123,6 +127,8 @@ class SettingsService
$this->getPriceTypes(); $this->getPriceTypes();
$this->getVatRates(); $this->getVatRates();
$this->actrualPropList = array_merge($this->getIblockPropsPreset(), $this->parseNewProps());
} }
/** /**
@ -131,12 +137,12 @@ class SettingsService
* *
* @return \Intaro\RetailCrm\Icml\SettingsService|null * @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); self::$instance = new self($arOldSetupVars, $action);
} }
return self::$instance; return self::$instance;
} }
@ -239,21 +245,47 @@ class SettingsService
/** /**
* @return string[] * @return string[]
*/ */
public function getIblockPropsPreset(): array private function getIblockPropsPreset(): array
{ {
return [ return [
'article' => 'article', 'article' => GetMessage('PROPERTY_ARTICLE_HEADER_NAME'),
'manufacturer' => 'manufacturer', 'manufacturer' => GetMessage('PROPERTY_MANUFACTURER_HEADER_NAME'),
'color' => 'color', 'color' => GetMessage('PROPERTY_COLOR_HEADER_NAME'),
'size' => 'size', 'size' => GetMessage('PROPERTY_SIZE_HEADER_NAME'),
'weight' => 'weight', 'weight' => GetMessage('PROPERTY_WEIGHT_HEADER_NAME'),
'length' => 'length', 'length' => GetMessage('PROPERTY_LENGTH_HEADER_NAME'),
'width' => 'width', 'width' => GetMessage('PROPERTY_WIDTH_HEADER_NAME'),
'height' => 'height', 'height' => GetMessage('PROPERTY_HEIGHT_HEADER_NAME'),
'picture' => 'picture', '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 * @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[] * @return array[]
*/ */
@ -351,7 +365,7 @@ class SettingsService
public function setProps(): void 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->iblockPropertySku, 'iblockPropertySku_' . $prop);
$this->setProperties($this->iblockPropertyUnitSku, 'iblockPropertyUnitSku_' . $prop); $this->setProperties($this->iblockPropertyUnitSku, 'iblockPropertyUnitSku_' . $prop);
$this->setProperties($this->iblockPropertyProduct, 'iblockPropertyProduct_' . $prop); $this->setProperties($this->iblockPropertyProduct, 'iblockPropertyProduct_' . $prop);
@ -587,9 +601,9 @@ class SettingsService
$props = []; $props = [];
if (isset($oldValues[$iblockId])) { if (isset($oldValues[$iblockId])) {
foreach ($this->getIblockPropsNames() as $key => $prop) { foreach (array_keys($this->actrualPropList) as $prop) {
$fullKey = $keyGroup . '_' . $key; $fullKey = $keyGroup . '_' . $prop;
$props[$key] = $oldValues[$iblockId][$fullKey]; $props[$prop] = $oldValues[$iblockId][$fullKey];
} }
} }

View File

@ -94,6 +94,11 @@ class XmlOfferBuilder
*/ */
private $vatRates; private $vatRates;
/**
* @var SettingsService
*/
private $settingsService;
/** /**
* IcmlDataManager constructor. * IcmlDataManager constructor.
* *
@ -107,9 +112,8 @@ class XmlOfferBuilder
{ {
$this->setup = $setup; $this->setup = $setup;
$this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice(); $this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice();
/** @var \Intaro\RetailCrm\Icml\SettingsService $settingsService */ $this->settingsService = SettingsService::getInstance([], '');
$settingsService = SettingsService::getInstance([], ''); $this->vatRates = $this->settingsService->vatRates;
$this->vatRates = $settingsService->vatRates;
$this->measures = $this->prepareMeasures($measure); $this->measures = $this->prepareMeasures($measure);
$this->defaultServerName = $defaultServerName; $this->defaultServerName = $defaultServerName;
} }
@ -461,16 +465,16 @@ class XmlOfferBuilder
private function createParamObject(array $params): array private function createParamObject(array $params): array
{ {
$offerParams = []; $offerParams = [];
$names = $this->settingsService->actrualPropList;
foreach ($params as $code => $value) { foreach ($params as $code => $value) {
$paramName = GetMessage('PARAM_NAME_' . $code);
if (empty($paramName)) { if (!isset($names[$code])) {
continue; continue;
} }
$offerParam = new OfferParam(); $offerParam = new OfferParam();
$offerParam->name = $paramName; $offerParam->name = $names[$code];
$offerParam->code = $code; $offerParam->code = $code;
$offerParam->value = $value; $offerParam->value = $value;
$offerParams[] = $offerParam; $offerParams[] = $offerParam;

View File

@ -1203,8 +1203,24 @@ function update()
'custom_fields_toggle', 'custom_fields_toggle',
'N' '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 { try {
update(); update();
} catch (Main\ObjectPropertyException | Main\ArgumentException | Main\SystemException $exception) { } catch (Main\ObjectPropertyException | Main\ArgumentException | Main\SystemException $exception) {

View File

@ -0,0 +1,49 @@
<?php
namespace lib\icml;
use Intaro\RetailCrm\Icml\SettingsService;
class SettingServiceTest extends \BitrixTestCase
{
private $mockSettingService;
public function setUp(): void
{
parent::setUp();
$this->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"
];
}
}