Magento2 操作分类报 URL key for specified store already exists.错误

Magento2 某些版本的bug,这里分享一下 操作分类报 URL key for specified store already exists.错误 解决方式
url_key_error

vendor/magento/module-url-rewrite/Model/Storage/DbStorage.php
找到
protected function doReplace($urls)
....
}
替换成
protected function doReplace($urls)
{
foreach ($this->createFilterDataBasedOnUrls($urls) as $type => $urlData) {
$urlData[UrlRewrite::ENTITY_TYPE] = $type;
$this->deleteByData($urlData);
}
$data = [];
$storeId_requestPaths = [];
foreach ($urls as $url) {
$storeId = $url->getStoreId();
$requestPath = $url->getRequestPath();
// Skip if is exist in the database
$sql = "SELECT * FROM url_rewrite where store_id = $storeId and request_path = '$requestPath'";
$exists = $this->connection->fetchOne($sql);

if ($exists) continue;

$storeId_requestPaths[] = $storeId . '-' . $requestPath;
$data[] = $url->toArray();
}

// Remove duplication data;
$n = count($storeId_requestPaths);
for ($i = 0; $i < $n - 1; $i++) { for ($j = $i + 1; $j < $n; $j++) { if ($storeId_requestPaths[$i] == $storeId_requestPaths[$j]) { unset($data[$j]); } } } $this->insertMultiple($data);
}

发表评论
Magento2 技术支持 上门服务

工作时间
周一至周六
9:00-18:00
相关咨询电话
15360669780
侨海科技