This commit is contained in:
parent
d9cdfced49
commit
b8ac495a37
@ -1,3 +1,6 @@
|
||||
## 2024-01-12 v.6.5.6
|
||||
- Добавлена передача дополнительных свойств товаров через конфигурируемый файл
|
||||
|
||||
## 2024-01-09 v.6.5.5
|
||||
- Исправлен вывод справочников при установке модуля
|
||||
|
||||
|
@ -1 +1 @@
|
||||
- Исправлен вывод справочников при установке модуля
|
||||
- Добавлена передача дополнительных свойств товаров через конфигурируемый файл
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
foreach ($settingsService->getIblockPropsNames() as $propertyKey => $property) {
|
||||
foreach ($settingsService->actrualPropList as $propertyKey => $property) {
|
||||
$productSelected = false; ?>
|
||||
|
||||
<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="SETUP_FIELDS_LIST" value="<?=
|
||||
$settingsService->getSetupFieldsString(
|
||||
$iblockProperties ?? [],
|
||||
array_keys($settingsService->actrualPropList) ?? [],
|
||||
$hlblockModule === true,
|
||||
$hlBlockList ?? []
|
||||
)
|
||||
|
@ -252,6 +252,7 @@ class intaro_retailcrm extends CModule
|
||||
$this->addEvents();
|
||||
$this->addAgreement();
|
||||
$this->addUserFields();
|
||||
$this->createCustomPropertyFile();
|
||||
|
||||
OrderLoyaltyDataService::createLoyaltyHlBlock();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$arModuleVersion = [
|
||||
'VERSION' => '6.5.5',
|
||||
'VERSION_DATE' => '2024-01-09 15:30:00'
|
||||
'VERSION' => '6.5.6',
|
||||
'VERSION_DATE' => '2024-01-12 17:00:00'
|
||||
];
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -97,11 +97,15 @@ class SettingsService
|
||||
*/
|
||||
public $loadNonActivity;
|
||||
|
||||
/** @var array */
|
||||
public $actrualPropList = [];
|
||||
|
||||
/**
|
||||
* @var \Intaro\RetailCrm\Icml\SettingsService|null
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
|
||||
/**
|
||||
* SettingsService constructor.
|
||||
*
|
||||
@ -123,6 +127,8 @@ class SettingsService
|
||||
|
||||
$this->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];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
49
tests/lib/icml/SettingServiceTest.php
Normal file
49
tests/lib/icml/SettingServiceTest.php
Normal 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"
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user