Magento Forum

   
Review Observer - Stop controller action after saving review
 
dinesh12
Jr. Member
 
Total Posts:  1
Joined:  2013-06-04
 


I am using Magento 1.7.0.2. I need to prevent ratings in the frontend from saving after the reviews has been saved. So I have used the <reveiw_save_after> event in order to achieve it. But I am unable to stop the controller action from happening after the save event. Here is my code:

etc\\config.xml
<frontend>
    <
events>
        <
review_save_after>
            <
observers>
                <
rating_prevent_observer>
                    <
type>singleton</type>
                    <class>
MyModule_Rating_Model_Observer</class>
                    <
method>preventAddRatings</method>
                </
rating_prevent_observer>
            </
observers>
        </
review_save_after>
    </
events>
</
frontend>

Rating\\Model\\Observer.php
class MyModule_Rating_Model_Observer
     {
        
function preventAddRatings(Varien_Event_Observer $observer)
        
{
            $app 
Mage::app();
            
$request $app->getRequest();

            
$app->getFrontController()->getResponse()->setRedirect($request->getBaseUrl() . $request->getPathInfo());
        
}
    }
The observer is calling but the controller action is still executing. Is this the correct way to prevent the controller action?.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nasha
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2009-04-15
 

I think You need to overload a controller.

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

That`s right, catching an event with an observer does not stop the controller action. You have to overwrite the controller with an own.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top