Magento将产品网址密钥中的正斜杠(/)更改为短划线( - ),如下所示,我不想要: -
category / subcategory / productname to category-subcategory-productname
答案 0 :(得分:1)
您需要做的就是更改方法getCategoryUrlPath中的文件app / code / core / Mage / Catalog / Helper / Category.php
从:
if ($slash) {
$regexp = '#('.preg_quote($this->getCategoryUrlSuffix($storeId), '#').')/$#i';
$replace = '/';
}
为:
if ($slash) {
$regexp = '#('.preg_quote($this->getCategoryUrlSuffix($storeId), '#').')/$#i';
$replace = '-';
}
并在文件app / code / core / Mage / Catalog / Model / Url.php中的方法getProductRequestPath
从:
$requestPath = $categoryUrl . '/' . $urlKey;
为:
$requestPath = $categoryUrl . '-' . $urlKey;
之后重新编制索引(目录URL重写)并清理缓存,就是这样。
<强>更新强>
关于Feroz的评论:
为了在产品网址中也包含“/”,首先您应该撤消上述更改,然后在课程app/code/core/Mage/Catalog/Model/Product/Url.php
中而不是:
public function formatUrlKey($str)
{
$urlKey = preg_replace('#[^0-9a-z]+#i', '-', Mage::helper('catalog/product_url')->format($str));
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '-');
return $urlKey;
}
组:
public function formatUrlKey($str)
{
$urlKey = preg_replace('#[^0-9a-z]+#i', '/', Mage::helper('catalog/product_url')->format($str));
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '/');
return $urlKey;
}
答案 1 :(得分:0)
我想你提出了相反的问题:这个扩展名:https://github.com/fullbl/snh_settings_CategoryParentUrl 你可以删除父路径并在url-keys中使用“/”作为类别!