[英]Magento - Redirect customer who hits review page to product page
有没有办法将访问产品评论页面(http://mydomain.com/review/product/list/id/139/category/79/)的客户重定向到实际的产品页面?
Assuming that seo friendly url is enable, then you could create a custom module that extend review/product and rewrite listAction method 假设启用了seo friendly url,那么您可以创建一个自定义模块来扩展review / product并重写listAction方法
In /app/etc/modules/MageIgniter_ReviewRedirect.xml 在/app/etc/modules/MageIgniter_ReviewRedirect.xml中
<?xml version="1.0"?>
<config>
<modules>
<MageIgniter_ReviewRedirect>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</MageIgniter_ReviewRedirect>
</modules>
</config>
In /app/code/local/MageIgniter/ReviewRedirect/controller/ReviewController.php 在/app/code/local/MageIgniter/ReviewRedirect/controller/ReviewController.php中
include_once 'Mage/Review/controllers/ProductController.php';
class MageIgniter_ReviewRedirect_ReviewController extends Mage_Review_ProductController
{
public function listAction(){
if ($product = $this->_initProduct()) {
$this->_redirect($product->getUrl());
}
}
in In /app/code/local/MageIgniter/ReviewRedirect/etc/config.xml 在/app/code/local/MageIgniter/ReviewRedirect/etc/config.xml中
<?xml version="1.0"?>
<config>
<modules>
<MageIgniter_ReviewRedirect>
<version>0.1.0</version>
</MageIgniter_ReviewRedirect>
</modules>
<frontend>
<routers>
<reviewredirect>
<use>standard</use>
<args>
<modules>
<MageIgniter_ReviewRedirect before="Mage_Review">MageIgniter_ReviewRedirect<MageIgniter_ReviewRedirect>
</modules>
<frontName>review</frontName>
</args>
</reviewredirect>
</routers>
</frontend>
<global>
<helpers>
<reviewredirect>
<class>MageIgniter_ReviewRedirect_Helper</class>
</reviewredirect>
</helpers>
</global>
</config>
In /app/code/local/MageIgniter/ReviewRedirect/Helper/Data.php 在/app/code/local/MageIgniter/ReviewRedirect/Helper/Data.php中
<?php
class MageIgniter_ReviewRedirect_Helper_Data extends Mage_Core_Helper_Abstract
{
}
You could place a redirect on the method listAction in the ProductController. 您可以在ProductController中的方法listAction上放置重定向。 (app/code/core/mage/Review/controllers/ProductController.php)
(应用程序/代码/核心/法师/评论/控制器/ ProductController.php)
Edit: Best practice is to create your own module to overwrite this controller, 编辑:最佳做法是创建自己的模块来覆盖此控制器,
There is an otherwise defunct feature from old Magento which only requires a module config: 旧Magento还有一个其他功能,它只需要一个模块配置:
<config>
<global>
<rewrite>
<yourmodulename>
<from><![CDATA[#^/review/product/list#]]></from>
<to><![CDATA[/catalog/product/view]]></to>
</yourmodulename>
</rewrite>
</global>
</config>
Underneath it is just using preg_replace
on the requested path so you should have no trouble understanding the PCRE patterns. 在它下面只是在请求的路径上使用
preg_replace
,所以你应该没有理解PCRE模式。 With a bit of imagination you could even merge the above into app/etc/local/xml
if you didn't want to create a whole module just for this. 如果你不想为此创建一个完整的模块,你甚至可以将上面的内容合并到
app/etc/local/xml
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.