Skip to content
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

Merged
merged 12 commits into from
Oct 4, 2018

Conversation

josephmcdermott
Copy link
Contributor

Description

  • 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

Fixed Issues

Manual testing scenarios

See issue for details. Essentially if importing a CSV with sku,name or sku,description only, the result is the unexpected update or removal of the URL Key of the product.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

- 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
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Aug 31, 2018

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team
Copy link
Contributor

Hi @josephmcdermott. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me {$VERSION} instance - deploy vanilla Magento instance

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)) {
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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

@magento-engcom-team magento-engcom-team added this to the Release: 2.2.7 milestone Sep 4, 2018
@magento-engcom-team
Copy link
Contributor

@josephmcdermott thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@josephmcdermott
Copy link
Contributor Author

@nuzil looks like a test is now failing, but it is now an invalid test I believe:
\Magento\CatalogImportExport\Model\Import\ProductTest::testImportWithoutUrlKeys

This pre-existing test is to state that the URL Key SHOULD be updated if an import CSV does not contain a value for url_key (in this case the CSV contains url_key but empty value), whereas this PR states that those products URL Key should NOT be updated

I would say the expected result in the test is as follows, since the first two SKUs existed already, the third one did not:

  • sku: simple1 / url_key: url-key
  • sku: simple2 / url_key: url-key2
  • sku: simple3 / url_key: simple-3

So perhaps the test data now should be:

$products = [
    'simple1' => 'url-key',
    'simple2' => 'url-key2',
    'simple3' => 'simple-3'
];

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.

@nuzil
Copy link
Contributor

nuzil commented Sep 7, 2018

@josephmcdermott
Thats generally purpose of integration tests to detect problems.
But in your case as you changed logic of urk_key import, definitely test also have to be changed according to new logic.
So I will ask you, can you please align tests so, that it correctly process new logic.
Feel free to do so.

@nuzil
Copy link
Contributor

nuzil commented Sep 18, 2018

@josephmcdermott can you please sign CLA and also I see that one of integration tests are failed

…y unrelated) tests are failing because they have hard coded product counts impacted by other tests
@josephmcdermott
Copy link
Contributor Author

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.

@slavvka slavvka self-assigned this Oct 3, 2018
@magento-engcom-team
Copy link
Contributor

Hi @slavvka, thank you for the review.
ENGCOM-2916 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @josephmcdermott. Thank you for your contribution.
We will aim to release these changes as part of 2.2.8.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

@dzschille
Copy link

Is this PR released yet? I can see in the 2.2.8 CHANGELOG.md:

#17023 -- CSV Import of sku,attribute empties url_key value (fixed in magento/magento2#17882)

But when i look into the code the method getUrlKey() looks still like:

protected function getUrlKey($rowData)
{
    if (!empty($rowData[self::URL_KEY])) {
        return $this->productUrl->formatUrlKey($rowData[self::URL_KEY]);
    }

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

    return '';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants