Magento:在外部页面上加载评论表单

Hen*_*k Z 9 php forms magento

默认情况下,评论表单的Magento URL如下:

www.domain.com/(producturl)-reviews#review-form.
Run Code Online (Sandbox Code Playgroud)

但在此页面中,评论表单是评论页面中的一个部分.

我想使用以下URL在唯一页面中加载评论表单:

www.domain.com/(producturl)-review-form.
Run Code Online (Sandbox Code Playgroud)

此评论表仅为此产品的表格.

我怎样才能做到这一点?

Ami*_*era 6

在这种情况下,它将better idea创建像Mage_Cms模块一样的自定义路由。

在哪里取决于request path using Custom route match internally设置request path

  • modules ->Mage_Review

  • controller ->ProductController.php

  • Action ->listAction.

客户会看到像

http://www.example.com/laptop1-review-form
Run Code Online (Sandbox Code Playgroud)

但在内部它击中了

http://www.example.com/review/product/list/id/33661/
Run Code Online (Sandbox Code Playgroud)

这里

`laptop1` is  `product url_path` value
 `33661` is `product id` 

 `-reviews-form` suffix for review url as you want
Run Code Online (Sandbox Code Playgroud)
  1. 为此自定义模块创建自定义字体路由器

`<frontend>
    <routers>
        <productview> <!--  router identifire -->
            <use>standard</use>
            <args>
                <modules>
                    <module>Dev_Productreview</module>
                    <frontName>productreview</frontName>
                </modules>
            </args>
        </productview>
    </routers>
</frontend>`
Run Code Online (Sandbox Code Playgroud)

参考资料

  1. 在 controller_front_init_routers 上添加一个观察者

<controller_front_init_routers>
        <observers> 
        <add_review_route>  <!-- observer identifier -->
            <class>Dev_Productreview_Controller_Router</class>
            <method>initControllerRouters</method>
        </add_review_route> 
        </observers>
    </controller_front_init_routers>

This observer add new routers 



public function initControllerRouters($observer){
        $front=$observer->getEvent()->getFront();
        $front->addRouter('productreview',$this);
        
    }
Run Code Online (Sandbox Code Playgroud)

3.添加路由类

. 现在你需要define router class at Controller folder not controllers folders

在哪里使用match () 检查request path match with your pattern (producturl)-review-form. . review-form 在 this request path()引用中检查字符串 退出

$requestPathInfo=trim($request->getPathInfo(),'/'); 
    if(strpos($requestPathInfo,'-review-form')==false):
            return  false;
        endif;
Run Code Online (Sandbox Code Playgroud)

4.从请求路径中获取产品url并保存

如果请求路径包含, review-form 则保存需要一个变量,然后review-form从此字符串中删除。

$producturl=str_replace('-review-form','',$requestPathInfo)
Run Code Online (Sandbox Code Playgroud)
  1. 检查当前商店中的产品出口

然后使用$producturl检查此路径product

$Rewrite=Mage::getModel('core/url_rewrite')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->loadByRequestPath($identifier);
Run Code Online (Sandbox Code Playgroud)
  1. 设置内部请求模块、控制器、动作名称

如果产品退出,那么 module,controller,action for this request.哪个将被命中

Mage_Review模块ProductControllerlistAction

$request->setModuleName('review') 
            ->setControllerName('product')
            ->setActionName('list')
        ->setParam('id', $productid);
Run Code Online (Sandbox Code Playgroud)
  1. 最后现在将请求别名设置为producturl-review-form因此客户只能将 notebook1-review-form 作为评论页面。

希望能帮到你

你可以在Github 上获得完整的模块

在这个模块中,我进行了如下评论:

http://YOurmagentoInstanceurl/linen-blazer-585.html-review-form
Run Code Online (Sandbox Code Playgroud)

每当产品网址是

http://YOurmagentoInstanceurl/linen-blazer-585.html
Run Code Online (Sandbox Code Playgroud)