(None of this is tested code, but the concepts should get you where you need to go)
Magento is a project run by a bunch of software engineers. When you're working with a bunch of software engineers, the documentation is the code.
i.e. Whenever you need to do something common with Magento, observe how the core team has done it, taking into account that you should limit yourself to observers, overrides, and new code since you can't discuss your changes with said core team.
Take a look at the one page checkout controller's IndexAction
method
app/code/core/Mage/Checkout/controllers/OnepageController.php
public function indexAction()
{
if (!Mage::helper('checkout')->canOnepageCheckout()) {
Mage::getSingleton('checkout/session')->addError($this->__('The onepage checkout is disabled.'));
$this->_redirect('checkout/cart');
return;
}
...
Magento allows you add errors to the session object, which will be processed by the messaging block on the next request.
Mage::getSingleton('checkout/session')->addError($this->__('The onepage checkout is disabled.'));
That that handles an error. Next, there's the redirect. This happens here
$this->_redirect('checkout/cart');
Since you're calling this code from an observer, you won't have access to this method. However, if you examine the controller
/**
* Retrieve request object
*
* @return Mage_Core_Controller_Request_Http
*/
public function getRequest()
{
return $this->_request;
}
...
protected function _redirect($path, $arguments=array())
{
$this->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
return $this;
}
You can see its using the response object. Magento uses a global response object (similar to Zend, and other Web frameworks) to handle what gets sent back to the browser (i.e. redirect headers). You can get a reference to the same object via
Mage::app()->getResponse()
and could perform a redirect with something like
Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));