2

I'm trying to import products into v2.2.7 but apparently this has been a problem since 2016 and has not been resolved until v2.3.x.

When importing to magento, some categories are like Socks/types a / b. When i import without changing anything, the structure is like the following:

Socks
`-- types a
    `--  b

If i use ascii, i end up with the right text visually in the backend, but my URL strings all are ascii and the back-end clean URL isn't correct using / and products that should be nested under it do not get nested appropriately.

Socks
`-- types a / b

If I upload category looking like this Socks/types a \/ b, I end up with the following:

Socks
`-- types a \
    `--  b

The ascii and the escape option are discussed in an issue here. Escaping could be the perfect solution for import because I could easily handle the hundreds of records.

The solution suggested in this thread is the following:

// In \Magento\CatalogImportExport\Model\Import\Product\Category there is a function upsertCategory.

protected function upsertCategory($categoryPath)
{
    if (!isset($this->categories[$categoryPath])) {
        $pathParts = explode(self::DELIMITER_CATEGORY, $categoryPath);
        $parentId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
        $path = '';

        foreach ($pathParts as $pathPart) {
            $path .= $pathPart;
            if (!isset($this->categories[$path])) {
                $this->categories[$path] = $this->createCategory($pathPart, $parentId);
            }
            $parentId = $this->categories[$path];
            $path .= self::DELIMITER_CATEGORY;
        }
    }

    return $this->categories[$categoryPath];
}

However, i'm new to magento and don't see \Magento\CatalogImportExport in the directory structure. I looked in vendor and don't see CatalogImportExport there either.

I have a script that can replace all the / with \/. However, magento is not escaping the \/. The desired directory structure when importing Socks/types a \/ b is:

Socks
`-- types a / b

Does anyone know how I can make this work in v2.2.x or especially v2.2.7?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.