Skip to content

Commit

Permalink
Fixed issue of url_key and url rewrites regeneration based on product…
Browse files Browse the repository at this point in the history
… name value.
  • Loading branch information
olegkoval committed Mar 8, 2020
1 parent 2a13b5f commit 3a06060
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Model/RegenerateProductRewrites.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function processProduct($entity, $storeId = 0)
}

if (!$this->regenerateOptions['noRegenUrlKey']) {
$generatedKey = $this->_getProductUrlPathGenerator()->getUrlKey($entity);
$generatedKey = $this->_getProductUrlPathGenerator()->getUrlKey($entity->setUrlKey(null));

This comment has been minimized.

Copy link
@jakubfrieb

jakubfrieb Dec 14, 2020

@olegkoval Hi, this line is causing me an issue with change existing url_key on product and generate wrong rewrite.
I have product with url_key = my-product-key-1 ... and product name = My Product Name ... when I run regenerate current url_key is nulled and then sent to url generator (\Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::prepareProductUrlKey) .. so new url key on my product is changed to my-product-name instead of keep same .. How I fixed that? I've only moved $entity->setUrlKey(null) to next line and leave only $entity there ... As I see it was before.

$this->_getProductAction()->updateAttributes(
[$entity->getId()],
['url_path' => null, 'url_key' => $generatedKey],
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Add into Magento 2 a CLI feature which allow to regenerate a Url rewrites of products and categories",
"keywords": ["magento", "magento2 extension", "magento 2 extension", "extension", "module", "magento2 module", "magento 2 module"],
"type": "magento2-module",
"version": "1.5.0",
"version": "1.5.1",
"homepage": "https://github.com/olegkoval/magento2-regenerate_url_rewrites",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="OlegKoval_RegenerateUrlRewrites" setup_version="1.5.0">
<module name="OlegKoval_RegenerateUrlRewrites" setup_version="1.5.1">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_Catalog"/>
Expand Down

0 comments on commit 3a06060

Please sign in to comment.