I’m running into an issue when using event dispatch in Magento.
I’m using controller_action_predispatch to set a frontend session variable from a parameter in the URL.
Now, the issue seems like, when the user comes to the site initially, they might lend on a page that will redirect them to base URL (such a example.com to http://www.example.com).
But for some reason, after redirect, the session variable is lost…
Any ideas?
Thank you.
EDIT:
adding the code used:
public function grabRef($observer) {
$ref = Mage::app()->getRequest()->getParam('ref', $default);
if (isset($ref) && !is_null($ref) and !empty($ref)) {
Mage::getSingleton('core/session',array('name'=>'frontend'))->setRefid($ref);
}
}
There are only two remotely useful events dispatched prior to this redirection, but they are not specific to the redirect:
controller_front_init_beforecontroller_front_init_routersThe redirect depends on the “Auto-redirect to Base URL” setting from System > Configuration > Web > Url Options, which is evaluated by
Mage_Core_Controller_Varien_Front->_checkBaseUrl(). This redirect occurs before any dispatching takes place, and it does not append GET or POST data, hence the loss of the param you are trying to capture.Normally sessions are initialized under
adminhtmlorfrontendsession namespace based on the controller class being used (ref the action controller superclass methodMage_Core_Controller_Varien_Action->preDispatch(). You should be able to move your observer configuration underglobal/events/controller_front_init_before. Note that you must do this in theglobalevent area, as the frontend event configuration part does not load until after this event is dispatched. That particular scenario cost me an hour once!