Magento URL 重写如何更改生成产品的格式 URL

Magento URL Rewrite how to change the format of generated product URL

是否有人有正确的解决方案来重写产品 URL 的格式如下:

http://domain/{product_id}_{标题}

并且在重复的情况下去掉 Magento 粘贴在标题前的前缀。

您需要覆盖 class Mage_Catalog_Model_Url 的“_refresh Product Rewrite”功能。

改变

if ($product->getUrlKey() == '') {
    $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
    }else {
    $urlKey = $this->getProductModel()->formatUrlKey($product>getUrlKey());
}

if ($product->getUrlKey() == '') {
   $urlKey = $this->getProductModel()->formatUrlKey($product->getId(). '_' .$product->getName());
} else {
   $urlKey = $this->getProductModel()->formatUrlKey($product->getId(). '_' .$product->getName());
}

您需要或创建一个模块或将文件 app/code/core/Mage/Catalog/Model/Url.php 复制到 app/code/local/Mage/Catalog/ Model/Url.php

重建索引器后 catalog_url