Skip to content

Commit

Permalink
Fixed attaching of children categories to parent category in script o…
Browse files Browse the repository at this point in the history
…f import from XML
  • Loading branch information
Andrey Kharanenka committed May 31, 2019
1 parent 5675dee commit 9361ed9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions classes/import/ImportCategoryModelFromXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ImportCategoryModelFromXML extends AbstractImportModelFromXML
/** @var Category */
protected $obModel;

protected $bHasChildrenField = false;

/**
* ImportCategoryModelFromCSV constructor.
*/
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -159,13 +161,20 @@ 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');
if ($iFileNumber !== null) {
$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;
}
}
}
}
4 changes: 3 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@
1.22.1:
- 'Fixed command shopaholic:import_from_xml.'
1.22.2:
- 'Added "deactivate" fields to config of XmlImportSettings model.'
- '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.'

0 comments on commit 9361ed9

Please sign in to comment.