Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

CatalogImportExport categoryProcessor is using default store id values #88

Closed
piotrekkaminski opened this issue Jan 3, 2018 · 11 comments
Assignees
Milestone

Comments

@piotrekkaminski
Copy link
Contributor

From @koenner01 on October 13, 2016 13:5

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');

Copied from original issue: magento/magento2#6992

@piotrekkaminski
Copy link
Contributor Author

From @sevos1984 on October 18, 2016 15:4

Internal ticket created MAGETWO-59827, thanks for posting

@piotrekkaminski
Copy link
Contributor Author

From @MattDelac on December 18, 2016 20:12

Hello everyone,

As @koenner01, I have the same issue (Magento 2.1.2) and I don't know why categories do not work as attributes.
Indeed, it's very important to synchronize by 'Admin value' and to easily change the name in each store view.

Can someone tell me if this issue is resolved with the new update (Magento 2.1.3) ? I did not see in the changelog.
If not, when should it be resolved (approximately) ?

Thank you

@piotrekkaminski
Copy link
Contributor Author

From @Tchinkatchuk on December 19, 2016 8:30

hello,

I dot agree with @MattDelac & @koenner01.
We should be able to do this. This is minimum valuable for export/import.

Thanks.

@piotrekkaminski
Copy link
Contributor Author

From @MattDelac on December 19, 2016 8:44

@koenner01

Did you find a hack to do it in another way ?

Thank you

@piotrekkaminski
Copy link
Contributor Author

From @vherasymenko on May 11, 2017 13:38

"Steps:

  1. Install Magento latest develop version
  2. Go to Admin side
  3. Click ""Catalog > Categories""
  4. Add new category with name for example (test)
  5. Change location on top side on ""Default Store View""
  6. And change name of created cateogry on something else
  7. Create csv file for import with product (cateogry for product set ""Default Category/test"")
  8. Go to ""System > Import""
  9. Entity type choose ""Products""
  10. Import Behavior choose ""Add\Update""
  11. Choose created csv file
  12. Click Import

AR: The product will not be added to the existing category
- A new category with the exact same path is created and the product is put in the new category
- 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""
ER: The product should be added to existing category 'test' successfully"

@piotrekkaminski
Copy link
Contributor Author

From @arshadpkm on June 10, 2017 11:41

I will check this one

@piotrekkaminski
Copy link
Contributor Author

From @arshadpkm on June 13, 2017 11:12

@okorshenko Need one help Travis fails with test INTEGRATION_INDEX=3, here is the link https://travis-ci.org/magento/magento2/jobs/242316296 But I am not sure how my commit related to this file. and how can I fix this?

@piotrekkaminski
Copy link
Contributor Author

From @okorshenko on June 13, 2017 16:54

@arshadpkm please, create pull request against 2.1-develop branch, but not 2.1

@piotrekkaminski
Copy link
Contributor Author

From @magento-team on August 1, 2017 1:9

Internal ticket to track issue progress: MAGETWO-69864

@piotrekkaminski
Copy link
Contributor Author

From @magento-engcom-team on October 18, 2017 11:30

@koenner01, thank you for your report.
We've created internal ticket(s) MAGETWO-59827 to track progress on the issue.

@dmanners dmanners added this to the Phase 2 milestone Feb 13, 2018
pogster pushed a commit to pogster/import-export-improvements that referenced this issue Jun 16, 2018
…o 0. Would otherwise be null and set to 1 in \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection::getStoreId, leading to unwanted store values for category names.
pogster added a commit to pogster/import-export-improvements that referenced this issue Jun 30, 2018
…For category identification, admin name must be used.
pogster added a commit to pogster/import-export-improvements that referenced this issue Jul 5, 2018
@dmanners
Copy link
Contributor

Thank you @pogster your PR #112 has covered this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants