Skip to content

CatalogImportExport categoryProcessor is using default store id values #6992

@koenner01

Description

@koenner01

When importing product data through the catalogImportExport module, new categories will be created even though categories with the correct path already exist.

Preconditions

  1. Magento 2.1
  2. PHP7.0

Steps to reproduce

  1. Create a category 'Test'
  2. Set the category name to something completely different on default storeview
  3. Create a csv with catalog product data
  4. Set 'Default Category/Test' as the 'categories' value
  5. Import

Expected result

  1. The product is added to the existing category 'Test' (which we just created)

Actual result

  1. The product will not be added to the existing category
  2. A new category with the exact same path is created and the product is put in the new category
    OR
  3. An error is thrown with message "1. Category "Default Category/Test" has not been created. URL key for specified store already exists. in row(s): 1"

I traced this issue back to \Magento\CatalogImportExport\Model\Import\Product\CategoryProcessor.
In the initCategories function a category collection is loaded with store id equal to the default store id.

protected function initCategories() { if (empty($this->categories)) { $collection = $this->categoryColFactory->create(); $collection->addAttributeToSelect('name') ->addAttributeToSelect('url_key') ->addAttributeToSelect('url_path'); /* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */ foreach ($collection as $category) { $structure = explode(self::DELIMITER_CATEGORY, $category->getPath()); $pathSize = count($structure); $this->categoriesCache[$category->getId()] = $category; if ($pathSize > 1) { $path = []; for ($i = 1; $i < $pathSize; $i++) { $path[] = $collection->getItemById((int)$structure[$i])->getName(); } $index = implode(self::DELIMITER_CATEGORY, $path); $this->categories[$index] = $category->getId(); } } } return $this; } 

In my opinion the collection should have a setStoreId(0) because the values for categories in the import csv should be the admin values.

$collection->setStoreId(0) ->addAttributeToSelect('name') ->addAttributeToSelect('url_key') ->addAttributeToSelect('url_path'); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogComponent: ImportExportIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions