Magento 1.9 Event Observer – How to Stop Process or Flow of an Event Observer

event-observerextensionsmagento-1.9module

Please someone tell me how to stop process(flow) of any event observer.

i.e an event observer if – "before_create_account"

i know this i can use this event and do something before a new account create. But what i have to do if i want to stop actual process of this event. i want to stop flow. If some condition is false then user will not able to create account. i want to check some condition before account create and if that condition is false new account registration should be rejected. what code i have to write for this.

  • before_create_account is just an example i know its not true event

Best Answer

The event observer system of Magento does not have its own mechanism to stop processing whatever happens after the event. So most of the time the only solution is to throw an exception and hope that it will be catched appropiately.

Depending on the code where the event is dispatched, this can yield different outcomes:

  1. the exception gets caught and logged (or silently swallowed) and a generic error message is shown to the user
  2. the exception gets caught and its message is shown to the user
  3. the exception is not caught and the user sees the dreaded "There was an error processing your request" or a plain "Internal Server Error" page.

See also: How prevent a model data save using _save_before event

Related Topic