Magento: Load review form on external page

In this case,it will better idea to create custom route like Mage_Cms module.

Where depends on request path using Custom route match internally set the request path

  • modules ->Mage_Review

  • controller ->ProductController.php

  • Action ->listAction.

Customer will see that like

http://www.example.com/laptop1-review-form

but internally it hit to

http://www.example.com/review/product/list/id/33661/

Here

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

 `-reviews-form` suffix for review url as you want
  1. create custom font router for this custom module

`<frontend>
    <routers>
        <productview> <!--  router identifire -->
            <use>standard</use>
            <args>
                <modules>
                    <module>Dev_Productreview</module>
                    <frontName>productreview</frontName>
                </modules>
            </args>
        </productview>
    </routers>
</frontend>`

Refernce

  1. Add an observer on 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);
        
    }

3.add router class

. Now you need define router class at Controller folder not controllers folders

Where using match () check the request path match with your pattern (producturl)-review-form. . check string review-form exits in this request path() reference

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

4.Get product url from request path and save it

If request path contain review-form then then save require an variable then remove review-form from this string.

$producturl=str_replace('-review-form','',$requestPathInfo)
  1. Check product exits in current store

Then using $producturl check this path for which product

$Rewrite=Mage::getModel('core/url_rewrite')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->loadByRequestPath($identifier);
  1. Set internal request Module,controller,Action name

If product is exits then module,controller,action for this request. which will be hit

Mage_Review Module ProductController at listAction

$request->setModuleName('review') 
            ->setControllerName('product')
            ->setActionName('list')
        ->setParam('id', $productid);
  1. Finally now set request alias as producturl-review-form thus customer can only laptop1-review-form as review page.

Hope this will help you

you can get full module at Github

In this module i have make review like :

http://YOurmagentoInstanceurl/linen-blazer-585.html-review-form

whenerever product url is

http://YOurmagentoInstanceurl/linen-blazer-585.html

Tags:

Php

Forms

Magento