gpt4 book ai didi

Magento 标签 URL 重写并生成

转载 作者:行者123 更新时间:2023-12-02 10:43:24 27 4
gpt4 key购买 nike

我在 Magento 中添加了很多标签重写规则。例如,

Request Path: tag/abc
Target Path: tag/product/list/tagId/7/
Type: Custom

请求和响应一切顺利。但我想知道如何更改前面的标签 URL?虽然重写规则运行完美,但不会改变已重写的 URL。

我在标签模块中找到了 getTaggedProductsUrl() 方法,最终,像其他人一样,它调用了 core/url 模型中的 getUrl() 方法。我尝试将 '_use_rewrite' => true 添加到路由参数中。但它没有生成正确的 URL。

我真的很想知道这到底是怎么回事!

最佳答案

如果您重写 tag/tag 模型并使用以下代码覆盖 getTaggedProductsUrl() ,它将起作用:

public function getTaggedProductsUrl()
{
$fullTargetPath = Mage::getUrl('tag/product/list', array(
'tagId' => $this->getTagId(),
'_nosid' => true
));
$targetPath = substr($fullTargetPath, strlen(Mage::getBaseUrl()));
$rewriteUrl = Mage::getModel('core/url_rewrite')->loadByIdPath($targetPath);
if ($rewriteUrl->getId()) {
return $rewriteUrl->getRequestPath();
}
return $fullTargetPath;
}

假设您使用不带基本网址的目标路径作为“ID 路径”“目标路径”属性,例如 tag/product/list/tagId/30/
如果您不想重复该设置,则需要使用标签资源模型并手动调整 SQL 以匹配 target_path 列而不是 id_path,因为资源模型没有为您预定义方法。
不过,您仍然可以使用 Mage_Tag_Model_Resource_Tag::loadByRequestPath() 方法作为引用。

关于Magento 标签 URL 重写并生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8320857/

27 4 0