1

I have problem when trying to import products via CSV i get this error:

  1. Url key: '******' was already generated for an item with the SKU:'*******'. You need to specify the unique URL key manually en filas: 2, 3, 5

the problem is that i have 170 rows of this, is there any chance that when magento recognize this error add "-(number)" after to product url key?

0

Unfortunately not. You need to check the names of your products.

You also can check at this closed issue at Magento's github repository.

https://github.com/magento/magento2/issues/1471

0

The duplicate url issue can be fixed by install this extension https://github.com/ho-nl/magento2-Ho_Import

It'll add a postfix -1, -2 in your url generated

0

This is strange bug in Magento.

This will happened - if URL-key exist in Magento, and if Product name exist in Magento.

If each Products will with Unique Name - will be all OK. Becouse URL-key based in Product name.

This very strange logic by Magento.

So, for fix this bug need to edit file vendor/magento/module-catalog-import-export/Model/Import/Product.php

1) change isNeedToValidateUrlKey

private function isNeedToValidateUrlKey($rowData)
     {
        return (!empty($rowData[self::URL_KEY]))
             && (empty($rowData[self::COL_VISIBILITY])
             || $rowData[self::COL_VISIBILITY]
             !== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
     }

2) change getUrlKey

protected function getUrlKey($rowData)
 {
     if (!empty($rowData[self::URL_KEY])) {
         return strtolower($rowData[self::URL_KEY]);
     }

     if (!empty($rowData[self::COL_NAME])) {
        return $this->productUrl->formatUrlKey($rowData[self::COL_NAME].'-'.$rowData[self::COL_SKU]);
     }

     return '';
 }

3) change _saveProducts - cut code - $rowData[self::URL_KEY] = $this->getUrlKey($rowData); and insert under - $rowSku = $rowData[self::COL_SKU]; following code

if ($this->isSkuExist($rowSku)) {
    if (!empty($rowData[self::URL_KEY])) {
        $rowData[self::URL_KEY] = $this->getUrlKey($rowData);
    } else {

    }
} else {
    $rowData[self::URL_KEY] = $this->getUrlKey($rowData);
}

Now if in import CSV file - not exist column url_key, will set url_key like ProductName-ProductSku

And without bugs :)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.