From 07840450147ce5c6cac01c662085af822a306586 Mon Sep 17 00:00:00 2001 From: jhruehl Date: Mon, 13 Aug 2018 09:07:38 +0200 Subject: [PATCH 1/2] Prevent empty string as useless product URL key on product imports Using the given class for product import processes leads to comulative problems of handling product url key related processes. Since 2.4 at least the url key for the sku, which is given in an import file's row, is set to an empty string, if there is no corresponding url key or name column given. This leads to a variety of problems: a) if no url key is given on import, it leads to changing the url key to Magento 2 standards by using the value in the name column. this totally ignores the fact that url keys get customized a lot of times and overwrites all efforts before. furthermore causing SEO problems, if as a consequence the url rewrites get adjusted accordingly. a product, which was exported to google shopping may not be reachable anymore by the link given to google or loose all linked SEO data by the next export given (if no 301 redirect is given). b) if nor url key or name column is given on import, the url key is set as an empty string, which is even worse. this leads to several products having the same empty string as an url key, causing problems, when regenerating or reindexing url rewrites, because of duplicate entries. and so on and so on. furthermore an empty string as an url key is just useless. synopsis: if no url key or name column is given in the import file, this change prevents any url key to be set as or updated to an empty string, which is useless and causes even more problems in the aftermath. --- app/code/Magento/CatalogImportExport/Model/Import/Product.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 743bcddede9c3..b71c316fe9e97 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -1561,7 +1561,8 @@ protected function _saveProducts() } $rowScope = $this->getRowScope($rowData); - $rowData[self::URL_KEY] = $this->getUrlKey($rowData); + if ($urlKey = $this->getUrlKey($rowData)) + $rowData[self::URL_KEY] = $urlKey; $rowSku = $rowData[self::COL_SKU]; From 409fb3b181b749185dc996ccf464755f2cb1a9b7 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Wed, 15 Aug 2018 12:42:19 +0300 Subject: [PATCH 2/2] Fixed according to Coding standards --- .../Magento/CatalogImportExport/Model/Import/Product.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index b71c316fe9e97..5b13000e539f4 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -1561,8 +1561,9 @@ protected function _saveProducts() } $rowScope = $this->getRowScope($rowData); - if ($urlKey = $this->getUrlKey($rowData)) - $rowData[self::URL_KEY] = $urlKey; + if ($this->getUrlKey($rowData)) { + $rowData[self::URL_KEY] = $this->getUrlKey($rowData); + } $rowSku = $rowData[self::COL_SKU];