diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php index c52c2fe2..2dbaaf5e 100644 --- a/intaro.retailcrm/export/export_setup.php +++ b/intaro.retailcrm/export/export_setup.php @@ -494,7 +494,7 @@ if ($STEP === 1) { - + @@ -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: { diff --git a/intaro.retailcrm/lib/controller/customexportprops.php b/intaro.retailcrm/lib/controller/customexportprops.php index 2bdfc451..aa70c3df 100644 --- a/intaro.retailcrm/lib/controller/customexportprops.php +++ b/intaro.retailcrm/lib/controller/customexportprops.php @@ -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, diff --git a/intaro.retailcrm/lib/icml/settingsservice.php b/intaro.retailcrm/lib/icml/settingsservice.php index 856ddfbb..4c5d60db 100644 --- a/intaro.retailcrm/lib/icml/settingsservice.php +++ b/intaro.retailcrm/lib/icml/settingsservice.php @@ -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;