From 832b8f34b733be026e2aa5244f70be830120d78e Mon Sep 17 00:00:00 2001 From: "a.belikin" Date: Fri, 8 Nov 2024 19:09:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA=20=D1=8D=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B8=D0=B7=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE=D0=B2.=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=BD=D0=B0=20=D1=84=D1=80?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D0=B5.=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BA=D0=B0=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=D0=BD=D1=8B=D1=85=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= =?UTF-8?q?,=20=D0=B3=D0=B4=D0=B5=20=D0=BE=D0=BD=D0=B8=20=D0=B1=D1=8B?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/export/export_setup.php | 4 +- .../lib/controller/customexportprops.php | 2 +- intaro.retailcrm/lib/icml/settingsservice.php | 82 +++++++++++++++---- 3 files changed, 70 insertions(+), 18 deletions(-) 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;