Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Load review form on external page

Tags:

forms

php

magento

By default the Magento URL for the review form is like:

www.domain.com/(producturl)-reviews#review-form.

But in this page the review-form is a section in the reviews page.

I want to load the review-form in unique page with this URL:

www.domain.com/(producturl)-review-form.

This review-form will only be the form for this product.

How can I achieve that?

like image 724
JGeer Avatar asked Jun 01 '15 14:06

JGeer


1 Answers

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
like image 131
Amit Bera Avatar answered Oct 18 '22 13:10

Amit Bera