Skip to content

Commit a021d5f

Browse files
Do not overwrite URL Key with blank value
- do not update existing products with a blank URL Key if no `url_key` value is provided in the import data - do not update existing products with a new URL Key if a `name` but no `url_key` value is provided in the import data
1 parent 19bec6f commit a021d5f

File tree

1 file changed

+29
-3
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+29
-3
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,13 @@ protected function _saveProducts()
15611561
}
15621562
$rowScope = $this->getRowScope($rowData);
15631563

1564-
$rowData[self::URL_KEY] = $this->getUrlKey($rowData);
1564+
/**
1565+
* Only populate URL KEY if a value has been provided.
1566+
* @see https://github.com/magento/magento2/issues/17023
1567+
*/
1568+
if ($urlKey = $this->getUrlKey($rowData)) {
1569+
$rowData[self::URL_KEY] = $urlKey;
1570+
}
15651571

15661572
$rowSku = $rowData[self::COL_SKU];
15671573

@@ -2406,6 +2412,17 @@ public function validateRow(array $rowData, $rowNum)
24062412
*/
24072413
private function isNeedToValidateUrlKey($rowData)
24082414
{
2415+
/**
2416+
* If the product exists, assume it already has a URL Key and even
2417+
* if a name is provided in the import data, it should not be used
2418+
* to overwrite that existing URL Key the product already has.
2419+
* @see https://github.com/magento/magento2/issues/17023
2420+
*/
2421+
$isSkuExist = $this->isSkuExist($rowData[self::COL_SKU]);
2422+
if ($isSkuExist && !array_key_exists(self::URL_KEY, $rowData)) {
2423+
return false;
2424+
}
2425+
24092426
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
24102427
&& (empty($rowData[self::COL_VISIBILITY])
24112428
|| $rowData[self::COL_VISIBILITY]
@@ -2710,20 +2727,29 @@ protected function getProductUrlSuffix($storeId = null)
27102727

27112728
/**
27122729
* @param array $rowData
2713-
* @return string
2730+
* @return string|bool
27142731
* @since 100.0.3
27152732
*/
27162733
protected function getUrlKey($rowData)
27172734
{
27182735
if (!empty($rowData[self::URL_KEY])) {
27192736
return strtolower($rowData[self::URL_KEY]);
27202737
}
2738+
2739+
/**
2740+
* If the product already exists, do not overwrite its
2741+
* URL Key with a value generated from the provided name.
2742+
* @see https://github.com/magento/magento2/issues/17023
2743+
*/
2744+
if ($this->isSkuExist($rowData[self::COL_SKU])) {
2745+
return false;
2746+
}
27212747

27222748
if (!empty($rowData[self::COL_NAME])) {
27232749
return $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
27242750
}
27252751

2726-
return '';
2752+
return false;
27272753
}
27282754

27292755
/**

0 commit comments

Comments
 (0)