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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

$rowData[self::URL_KEY] = $urlKey;
}

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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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.

* @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;
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

}

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

return '';
return false;
}

/**
Expand Down