zco_notifier
The event handling in zen-cart is soemthing I have never spent a lot of time thinking about. I had to, though, when implementing the email handling. It was the only way to hook into some of the zen-cart code the way I needed.
The ZMZcoObserver class makes attaching custom code quite easy while keeping things pretty local. Especially, adding callbacks to functional code is easy done in three simple steps (it’s still easier for subsequent events):
- Extend ZMZcoObserver like you would any other ZenMagick class
- Add a line in the contructor registering the class itself for the desired event:
$zco_notifier->attach($this, array('NOTIFY_HEADER_START_GV_SEND')); - Implement a method in the class following the naming pattern documented in the class; for the above
example the method name would beonHeaderStartGvSend
While being convenient, I do not like the event architecture very much. So it is no wonder that there isn’t something equivalent in ZenMagick. It’s not needed, though, as themes can easily extend existing controller and thus do whatever they like before or after request handling. They might even reimplement request handling altogether.
If needed, the base ZMController class could be extended to call some new methods at the various stages of the request handling. Unitil then, no events in ZenMagick.
