Magento 2.1.3 : URL key For Specified Store Already Exists When Saving Categories
-
12-01-2021 - |
Pregunta
I searched for this kind of issue and saw many others experiencing this thing like me. I tried those fixes that they recommend but it's not working on my end.
Maybe you guys can suggest what is the best thing or any recommendations how to fix this one.
Any ideas on the best solution to fix this bug?
Thanks!
Solución
Truncating your url_rewrite
table & run re-indexing.
It will create all url-key's automatically.
=> Note : Take backup of that table before truncate it.
For regenerate url :
Download this module and copy the Iazel directory into app/code/
Then you can regenerate SEO Friendly URL's for catalog/products via Console
# Regenerate url for all products and the global store
php bin/magento iazel:regenurl
# Regenerate url for products with id (1, 2, 3, 4) for store 1
php bin/magento iazel:regenurl -s1 1 2 3 4
Otros consejos
That's known issue in Magento2.1.x
this issue is solved now magento2.2
you can check here for more detail
https://github.com/magento/magento2/issues/7298
for quick hack you can do following
Create a prefrence of this class vendor/magento/module-url-rewrite/Model/Storage/DbStorage.php
and rewrite doReplace()
this method
protected function doReplace($urls)
{
foreach ($this->createFilterDataBasedOnUrls($urls) as $type => $urlData) {
$urlData[UrlRewrite::ENTITY_TYPE] = $type;
$this->deleteByData($urlData);
}
$data = [];
foreach ($urls as $url) {
$data[] = $url->toArray();
}
/* Add this line : Get rid of rewrite for root Magento category to unduplicate things*/
foreach($data as $key =>$info){
if(isset($info['target_path']) && stristr($info['target_path'],'/category/1') && $info['entity_type']=='product'){
unset($data[$key]);
}
}
$this->insertMultiple($data);
}