diff --git a/classes/import/ImportCategoryModelFromXML.php b/classes/import/ImportCategoryModelFromXML.php index 50a84e5f..719359fc 100644 --- a/classes/import/ImportCategoryModelFromXML.php +++ b/classes/import/ImportCategoryModelFromXML.php @@ -28,6 +28,8 @@ class ImportCategoryModelFromXML extends AbstractImportModelFromXML /** @var Category */ protected $obModel; + protected $bHasChildrenField = false; + /** * ImportCategoryModelFromCSV constructor. */ @@ -84,7 +86,7 @@ protected function prepareImportData() */ protected function processModelObject() { - if ($this->obParentCategory === false) { + if ($this->obParentCategory === false || ($this->bHasChildrenField && empty($this->obParentCategory))) { $this->obModel->parent_id = null; $this->obModel->save(); } elseif (!empty($this->obParentCategory)) { @@ -104,7 +106,7 @@ protected function processModelObject() */ protected function initParentCategory() { - if (!array_key_exists('parent_id', $this->arImportData)) { + if (!array_key_exists('parent_id', $this->arImportData) && !$this->bHasChildrenField) { return; } @@ -159,7 +161,7 @@ protected function prepareImportSettings() $this->sImageFolderPath = trim($this->sImageFolderPath, '/'); $this->bDeactivate = (bool) XmlImportSettings::getValue('category_deactivate'); - $this->arImportSettings = XmlImportSettings::getValue('category'); + $this->arImportSettings = (array) XmlImportSettings::getValue('category'); $this->sElementListPath = XmlImportSettings::getValue('category_path_to_list'); $iFileNumber = XmlImportSettings::getValue('category_file_path'); @@ -167,5 +169,12 @@ protected function prepareImportSettings() $this->sMainFilePath = array_get($this->arXMLFileList, $iFileNumber.'.path'); $this->sMainFilePath = trim($this->sMainFilePath, '/'); } + + foreach ($this->arImportSettings as $arFieldData) { + if (array_get($arFieldData, 'field') == 'children') { + $this->bHasChildrenField = true; + break; + } + } } } diff --git a/updates/version.yaml b/updates/version.yaml index cb87ddec..ebb8675c 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -95,4 +95,6 @@ 1.22.1: - 'Fixed command shopaholic:import_from_xml.' 1.22.2: - - 'Added "deactivate" fields to config of XmlImportSettings model.' \ No newline at end of file + - 'Added "deactivate" fields to config of XmlImportSettings model.' +1.22.3: + - 'Fixed attaching of children categories to parent category in script of import from XML.' \ No newline at end of file