6

By default the Magento URL for the review form is:

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 a URL something like:

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

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

How can I achieve that?

  • Just to get the requirements straight: is this about the URL structure or about the form. The form bit, doesn't have to be backend code at all. – Melvyn Jun 4 '15 at 22:17
  • @Melvyn It's about loading the review form on it's own and single page. The URL for this doesn't matter. I just want to load the form on its own page. – Henk Z Jun 5 '15 at 7:25
  • Ah, so you want the reviews to really not be there. Saving performance. Then my idea won't work, unless you also Ajax the review content. I'll take a stab this weekend, see what I can come up with. – Melvyn Jun 5 '15 at 7:30
  • @Melvyn Yes indeed. I want to display the reviews on its own page and also the reviewform. Great, many thanks! – Henk Z Jun 5 '15 at 7:42
3

If this exact url structure is an requirement, you could solve this by implementing an own router.

the xml needed is something like

<config>
    <default>
    <web>
        <routers>
            <my_review>
                <area>frontend</area>
                <class>My_Review_Controller_Review_Router</class>
            </my_review>
        </routers>
    </web>
    </default>
</config>

this class needs to extend from Mage_Core_Controller_Varien_Router_Standard and overwrite the match method.

You can then parse the url, if it ends with -review-form you can extract the product part, and see if you have a product with this url-key or look in the rewrite table for it, not sure what is more stable. If it does not match, exit the function with a return. If it matches, I would suggest to an internal redirect to a route of your controller which is implemented as the others suggested.

The performance impact is nearly nothing, as you dont cause a database query for the initial -review-form test, and trough the internal redirect towards a normal controller you keep the additional complexity low.

2

Setting up exactly like that could involve a bit of messy looking coding, since you would need to override some controllers to interpret the url and direct the user to the correct controller action.

An alternative solution would be to setup a new front end controller eg a new ReviewController, which would implement an action such as writeAction which would take a url paramater.

This would give you something along the lines of domain.com/review/write/product/16

Then from that, you can setup a layout handle for that action which will include the relevent parts of the review form in the page layout and display the form and handle as normal from there.

  • Thanks! Do you have any code for this, because I can't get it done. – Henk Z Jun 3 '15 at 8:16
  • It wouldn't be that hard to get the URL bit done. Just use rewrites. The issue will be that for each product you add one more rewrite - that can add up, but it's not complex. – Melvyn Jun 4 '15 at 22:15
2
+25

Is it a hard requirement to have that URL structure?

A more approachable method would be to have a URL structure like:

http://yoursite.com/product-reviews/id/5

You could simply implement your own controller to resolve the product-reviews segment, and then load the id of the product to get a specific product.

In the event that you want a more semantic URL, possibly:

http://yoursite.com/product-reviews/id/purple-little-widget

You could try loading the product by name and some string manipulation. This would require a predictable and consistent product naming structure.

// how you manipulate the `id` param to match your product name is probably something like this
$name = uc_words(str_replace('-', ' ', $this->getRequest()->getParam('id')));
$product = Mage::getModel('catalog/product')->load($name, 'name');

As @JohnCuthbert mentioned, using the URL like you described would require doing some awkward things. I'm thinking you would need to create your controller as the first example I listed, and then create URL rewrites for every product. I'd work, but I'm not really fond of that approach.

  • No it is not a hard requirement. I only want to load it on a external page, so that the review form of a product got its own page. But how can I load this exactly? – Henk Z Jun 5 '15 at 6:41
2

[Edited]

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.domain.com/laptop1-review-form

but internally it hit to

http://www.domain.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

2. 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)

6. 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);

7. 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

note: pattern match by string -review-form in request url

  • hey jell, producturl mean product url_key or else,please explain – Amit Bera Jun 11 '15 at 7:24
0

I believe all you want is to show only review section when clicked on review this product, even though the url remains same.

If that's the case then just go to- theme/layout/review.xml and find <review_product_list> and edit as you wish.

Basically you are removing few unwanted blocks.

  • Thanks, but that is not what I want. I want to remove the review form on that page. And place the review form on a new page. So I want to separate the two sections of the page into 2 different pages. – Henk Z Jun 10 '15 at 9:16
  • That's right, this is already separate from product page isn't it? – Adarsh Khatri Jun 10 '15 at 9:19
  • Yes it is, it is on the page www.domain.com/(producturl)-reviews#review-form. Thats the place were all reviews are displayed, including the review form. But I want to separate all the reviews and the review form into two different pages. – Henk Z Jun 10 '15 at 9:21
  • If you have review tab on product page, then you can remove your reviews block from review section too. So at the end you only keep review_form section in <review_product_list>. You might want to include go back to product url in that form. – Adarsh Khatri Jun 10 '15 at 9:27
  • If you don't have review tab then simply add it. link. – Adarsh Khatri Jun 10 '15 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.