-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not overwrite URL Key with blank value #17882
Changes from 2 commits
a021d5f
a02bf03
e48683c
7df4e12
fffb6ff
002aa19
172e2ec
3a54946
2fb7183
fda664a
abd95bd
0f26b52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1561,7 +1561,9 @@ 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]; | ||
|
||
|
@@ -2406,6 +2408,16 @@ public function validateRow(array $rowData, $rowNum) | |
*/ | ||
private function isNeedToValidateUrlKey($rowData) | ||
{ | ||
/** | ||
* If the product exists, assume it already has a URL Key and even | ||
* if a name is provided in the import data, it should not be used | ||
* to overwrite that existing URL Key the product already has. | ||
*/ | ||
$isSkuExist = $this->isSkuExist($rowData[self::COL_SKU]); | ||
if ($isSkuExist && !array_key_exists(self::URL_KEY, $rowData)) { | ||
return false; | ||
} | ||
|
||
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME])) | ||
&& (empty($rowData[self::COL_VISIBILITY]) | ||
|| $rowData[self::COL_VISIBILITY] | ||
|
@@ -2710,20 +2722,28 @@ protected function getProductUrlSuffix($storeId = null) | |
|
||
/** | ||
* @param array $rowData | ||
* @return string | ||
* @return string|bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment before about return type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's a good point, I was on the fence myself about this change. |
||
* @since 100.0.3 | ||
*/ | ||
protected function getUrlKey($rowData) | ||
{ | ||
if (!empty($rowData[self::URL_KEY])) { | ||
return strtolower($rowData[self::URL_KEY]); | ||
} | ||
|
||
/** | ||
* If the product already exists, do not overwrite its | ||
* URL Key with a value generated from the provided name. | ||
*/ | ||
if ($this->isSkuExist($rowData[self::COL_SKU])) { | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment before about return type |
||
} | ||
|
||
if (!empty($rowData[self::COL_NAME])) { | ||
return $this->productUrl->formatUrlKey($rowData[self::COL_NAME]); | ||
} | ||
|
||
return ''; | ||
return false; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not recommend here to change return type of the method (line 2725, 2739). As user of getUrlKey method I expecting to receive back some url. Can you please change this implementation to check if URL is empty then do not overwrite it.