-
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
Do not overwrite URL Key with blank value #17882
Conversation
- 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
Hi @josephmcdermott. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
$rowData[self::URL_KEY] = $this->getUrlKey($rowData); | ||
/** | ||
* Only populate URL KEY if a value has been provided. | ||
* @see https://github.com/magento/magento2/issues/17023 |
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.
Comments are good, can you please remove Magento issues links from the code. Let keep it clean.
* 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. | ||
* @see https://github.com/magento/magento2/issues/17023 |
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.
Comments are good, can you please remove Magento issues links from the code. Let keep it clean.
/** | ||
* If the product already exists, do not overwrite its | ||
* URL Key with a value generated from the provided name. | ||
* @see https://github.com/magento/magento2/issues/17023 |
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.
Comments are good, can you please remove Magento issues links from the code. Let keep it clean.
@@ -1561,7 +1561,9 @@ protected function _saveProducts() | |||
} | |||
$rowScope = $this->getRowScope($rowData); | |||
|
|||
$rowData[self::URL_KEY] = $this->getUrlKey($rowData); | |||
if ($urlKey = $this->getUrlKey($rowData)) { |
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.
@@ -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 comment
The 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 comment
The 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.
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
see comment before about return type
@josephmcdermott thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository. |
@nuzil looks like a test is now failing, but it is now an invalid test I believe: This pre-existing test is to state that the URL Key SHOULD be updated if an import CSV does not contain a value for I would say the expected result in the test is as follows, since the first two SKUs existed already, the third one did not:
So perhaps the test data now should be:
Obviously I don't just want to change an integration test though since it was added for reason, so it might be worth checking with the developer who wrote the now-failing test. Over to you on how to proceed. |
@josephmcdermott |
…ple3` being modified by other tests
@josephmcdermott can you please sign CLA and also I see that one of integration tests are failed |
…mination from other tests
…om cache (due to simple3 being deleted)
…ird product, to prevent other tests interfering
…y unrelated) tests are failing because they have hard coded product counts impacted by other tests
OK tests passing @nuzil and CLA signed. The test itself was actually fine all along, but other tests were impacting the results (some tests check for 3 products instead of 4, despite the fact that other tests may have added products, etc.) - was a little frustrating to be honest, the test interdependencies seem a little too delicate. |
Hi @slavvka, thank you for the review. |
Hi @josephmcdermott. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
Is this PR released yet? I can see in the 2.2.8 CHANGELOG.md:
But when i look into the code the method getUrlKey() looks still like:
|
Description
url_key
value is provided in the import dataname
but nourl_key
value is provided in the import dataFixed Issues
sku,attribute
emptiesurl_key
value #17023: CSV Import ofsku,attribute
emptiesurl_key
valueManual testing scenarios
See issue for details. Essentially if importing a CSV with
sku,name
orsku,description
only, the result is the unexpected update or removal of the URL Key of the product.Contribution checklist