From 6703ada209d5fc861e0fa8ec24b26b3f55fd87c0 Mon Sep 17 00:00:00 2001 From: Pau Iranzo Date: Sun, 5 Apr 2020 07:16:43 +0200 Subject: [PATCH] Fix additional headers and root category selection * The additional headers generated array can generate empty values (which lend later to warning or errors). We use array_filter to remove empty values. * If no parent id is selected, instead of automatically selecting '2' as category root, we check what the category root for the default store view is. --- Console/Command/CategoriesCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Console/Command/CategoriesCommand.php b/Console/Command/CategoriesCommand.php index 567dfd2..712cf81 100644 --- a/Console/Command/CategoriesCommand.php +++ b/Console/Command/CategoriesCommand.php @@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new LocalizedException(__('Please specify path to file! (eg. "var/import/categories.csv")')); } $additionalHeadersDefinedByUser = explode(',', $input->getOption('additional')); - $this->additionalHeaders = array_merge($this->additionalHeaders, $additionalHeadersDefinedByUser); + $this->additionalHeaders = array_filter(array_merge($this->additionalHeaders, $additionalHeadersDefinedByUser)); $file = $this->directoryList->getRoot() . '/' . $path; @@ -264,7 +264,8 @@ protected function addOrUpdateCategory($data, $isParent = false) $category->setIsActive($this->getOptionalAttributeValue($data, 'is_active', true)); $category->setIncludeInMenu($this->getOptionalAttributeValue($data, 'include_in_menu', true)); if ($isParent) { - $category->setParentId(2); + $rootCategoryId = $this->storeManager->getStore(1)->getRootCategoryId(); + $category->setParentId($rootCategoryId); } else { $categoryCollection = $this->getCategoryFromCollectionByOldId($categoryFactory, $data, 'parent_id'); if ($categoryCollection->getSize()) {