I am using an Observer to catch that event: controller_action_postdispatch_checkout_onepage_saveBilling
I want that event in order to check the billing address of the customer.
My question is: How can i send a message to the user at this point.When continue button is pressed.
I used the : Mage::getSingleton('core/session')->addError('My message');
but the message is not shown until you refresh the page.And here is the second question.
How can i redirect the page from that point?
I have use with no luck: $this->_redirect('*/*/');
and hardcoded urls with no luck.
Ideally i want when the customer presses the continue button, after some checks that i make, the process to be stopped with a message.The observer is checked and it works as it supposed to work.
Hope it make sense..
EDIT That's my code.Just to make sure i'm doing it right: Model/Observer
class Company_Restrictions_Model_Observer {
public function notifyUser($observer) {
//Lot's off lines are tested here.Nothing seems to work..
//$observer->getRequest()->setParam('return_url','http://www.google.com/');
//Edited after comments
$result = array();
$result['error'] = '-1';
$result['message'] = 'YOUR MESSAGE HERE';
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Restrictions>
<version>0.1.0</version>
</Company_Restrictions>
</modules>
<global>
<models>
<company_restrictions>
<class>Company_Restrictions_Model</class>
</company_restrictions>
</models>
<helpers>
<company_restrictions>
<class>Company_Restrictions_Helper</class>
</company_restrictions>
</helpers>
<events>
<controller_action_postdispatch_checkout_onepage_saveBilling>
<observers>
<notify_user>
<type>singleton</type>
<class>Company_Restrictions_Model_Observer</class>
<method>notifyUser</method>
</notify_user>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
</events>
</global>
</config>
EDIT AGAIN After debuuging i found out that a lot of functions are giving me error.Undefined method ... for ex: _redirect() or Response() or Body().. Does anyone knows why??