Изменил для настроек экспорта получение данных из файлов. Сделал фикс на фронте. Сделал вывод значений кастомных свойств только для каталогов, где они были заполнены
This commit is contained in:
parent
0ceee2c0d7
commit
832b8f34b7
@ -494,7 +494,7 @@ if ($STEP === 1) {
|
||||
<select name="iblockPropertyProduct_" id="iblockPropertyProduct_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
|
||||
</td>
|
||||
<td class="adm-list-table-cell">
|
||||
<select name="iblockPropertyProduct_" id="iblockPropertyProduct_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
|
||||
<select name="iblockPropertySku_" id="iiblockPropertySku_" class="property-export" onchange="propertyChange(this)" style="width: 200px"></select>
|
||||
<button id="delete-custom-row" class="adm-btn-save" type="button">Удалить</button>
|
||||
</td>
|
||||
</tr>
|
||||
@ -816,7 +816,7 @@ if ($STEP === 1) {
|
||||
let profileId = $($('input[name="PROFILE_ID"]')).val();
|
||||
setCustomProperties();
|
||||
|
||||
if (customProperties.length > 0) {
|
||||
if (Object.keys(customProperties).length > 0) {
|
||||
addParamsToSetupFieldsList();
|
||||
BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
|
||||
json: {
|
||||
|
@ -34,7 +34,7 @@ class CustomExportProps extends Controller
|
||||
$newPropertiesString .= PHP_EOL . $property['code'] . ' = ' . $property['title'];
|
||||
}
|
||||
$filePath = sprintf(
|
||||
'%s/%s_%s_%s.txt',
|
||||
'%s/%s_profileId_%s_catalogId_%s.txt',
|
||||
$_SERVER['DOCUMENT_ROOT'] . '/local',
|
||||
'icml_property_retailcrm',
|
||||
$profileId,
|
||||
|
@ -13,9 +13,10 @@ use RetailcrmConfigProvider;
|
||||
|
||||
/**
|
||||
* Отвечает за управление настройками выгрузки icml каталога
|
||||
*
|
||||
* @var $PROFILE_ID
|
||||
* Class SettingsService
|
||||
*
|
||||
*
|
||||
* @package Intaro\RetailCrm\Icml
|
||||
*/
|
||||
class SettingsService
|
||||
@ -100,6 +101,12 @@ class SettingsService
|
||||
/** @var array */
|
||||
public $actrualPropList = [];
|
||||
|
||||
/** @var array */
|
||||
public $customPropList = [];
|
||||
|
||||
/** @var array */
|
||||
public $defaultPropList = [];
|
||||
|
||||
/**
|
||||
* @var \Intaro\RetailCrm\Icml\SettingsService|null
|
||||
*/
|
||||
@ -128,7 +135,9 @@ class SettingsService
|
||||
$this->getPriceTypes();
|
||||
$this->getVatRates();
|
||||
|
||||
$this->actrualPropList = array_merge($this->getIblockPropsPreset(), $this->parseNewProps());
|
||||
$this->customPropList = $this->parseNewProps();
|
||||
$this->defaultPropList = $this->getIblockPropsPreset();
|
||||
$this->actrualPropList = $this->getActualPropList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,6 +155,21 @@ class SettingsService
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getActualPropList(): array
|
||||
{
|
||||
$customProps = [];
|
||||
|
||||
foreach ($this->customPropList as $propsByCatalog) {
|
||||
$customProps = array_merge($customProps, $propsByCatalog);
|
||||
}
|
||||
|
||||
return [
|
||||
...$this->defaultPropList,
|
||||
...$customProps
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function getPriceTypes()
|
||||
{
|
||||
$dbPriceType = CCatalogGroup::GetList(['SORT' => 'ASC'], [], [], [], ['ID', 'NAME', 'BASE']);
|
||||
@ -230,7 +254,9 @@ class SettingsService
|
||||
private function setProperties(array &$properties, string $propName): void
|
||||
{
|
||||
foreach ($this->arOldSetupVars[$propName] as $iblock => $val) {
|
||||
$properties[$iblock][$propName] = $val;
|
||||
if (!empty($val)) {
|
||||
$properties[$iblock][$propName] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,24 +289,50 @@ class SettingsService
|
||||
private function parseNewProps(): array
|
||||
{
|
||||
global $APPLICATION;
|
||||
global $PROFILE_ID;
|
||||
$currentProfile = $PROFILE_ID;
|
||||
$currentProfileCatalogIds = $this->getProfileCatalogIds();
|
||||
|
||||
$result = [];
|
||||
$text = $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . "/local/icml_property_retailcrm.txt");
|
||||
foreach ($currentProfileCatalogIds as $catalogId) {
|
||||
$customPropsFilePath = sprintf(
|
||||
'%s/%s_profileId_%s_catalogId_%s.txt',
|
||||
$_SERVER['DOCUMENT_ROOT'] . '/local',
|
||||
'icml_property_retailcrm',
|
||||
$currentProfile,
|
||||
$catalogId,
|
||||
);
|
||||
$text = $APPLICATION->GetFileContent($customPropsFilePath);
|
||||
|
||||
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])) {
|
||||
if ($text === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[trim($elements[0])] = trim($elements[1]);
|
||||
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[$catalogId][trim($elements[0])] = trim($elements[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getProfileCatalogIds(): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($this->arOldSetupVars as $varName => $oldSetupVar) {
|
||||
if (is_array($oldSetupVar) && strpos($varName, 'iblockPropertySku_') !== false) {
|
||||
$result = array_keys($oldSetupVar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
Loading…
Reference in New Issue
Block a user