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.
Try this way:
Go to your theme/layout/review.xml
.
Now, find
<catalog_product_view>
<reference name="product.info">
<block type="review/product_view_list" name="product.reviews" as="reviews" template="review/product/view/list.phtml" after="additional">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Reviews</value></action>
</block>
</reference>
</catalog_product_view>
and change <action method="addToParentGroup"><group>detailed_info</group></action>
to
<action method="addToParentGroup"><group>review_info</group></action>
See we are just replacing detailed_info
to review_info
.
Then go to your theme/template/catalog/view.phtml
and add following code after that description
code:
<div class="product-collateral toggle-content tabs">
<?php if ($review = $this->getChildGroup('review_info', 'getChildHtml')):?>
<dl id="collateral-tabs" class="collateral-tabs">
<?php foreach ($review as $alias => $html):?>
<dt class="tab"><span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></span></dt>
<dd class="tab-container">
<div class="tab-content"><?php echo $html ?></div>
</dd>
<?php endforeach;?>
</dl>
<?php endif; ?>
</div>
I haven't tested, but should work.
Good luck.
Best Answer
Note: I assume that you are okay with modifying Msp Recaptcha module.
This will add review page option in the reCaptcha settings.
Add the following code in di.xml file (just before
</config>
tag) mentioned above to override template file.then
Above code should be pasted just before the following:
This will add the reCaptcha in the review form.
If you want code for validation of captcha also, please let me know. I will update soon.
Update: Steps for reCaptcha validation
Since this module is validating reCaptcha using
/vendor/msp/recaptcha/Observer/ReCaptchaObserver.php
, I tried to find call to this observer, but could not find direct call to this observer.But I found definition of validation observers in
/vendor/msp/recaptcha/etc/frontend/events.xml
, so follow from step 10 now.The observer classes defined in
/vendor/msp/recaptcha/etc/frontend/events.xml
file don't exist. Instead they are being replaced by virtualType.Now the only problem remaining is redirecting to correct URL if reCaptcha validation fails. Currently I have redirected to
cms/index/index
action.Please share the code if you get success in redirecting to the product URL on which the user filled the review.
Please let me know if you have any query.