Zen Cart Observers: Observations
One thing to consider when you're writing a Zen Cart plugin that includes an observer-class module is the point at which any monitored notification is going to be "fired". Auto-loading observers, previously discussed here, are great since using that method can reduce the number of files that a plugin needs in its distribution ... but there's a potential downside (isn't there always?).
All auto-loading observers are loaded at breakpoint 175 during the Zen Cart autoload process. That processing loads all files present in the
/includes/classes/observers directory whose names match auto.*.php and, if the class' name adheres to the auto-loading "rules", creates an instance of the associated class.
If the notifications that your plugin is observing are issued prior to breakpoint 175, then auto-loading isn't for you!
For example, let's say that your plugin is monitoring
NOTIFIER_CART_ADD_CART_START, issued by the shopping-cart class at the beginning of an add-to-cart action. Those cart-manipulation actions occur during
init_cart_handler.php's processing at breakpoint 140, so an auto-loading observer will never see that notification. Your plugin will need to include an additional file (in
/includes/auto_loaders) to instruct Zen Cart the point at which your observer should be loaded (prior to 140!) and instantiated and its observer-class file's name must not start with "auto.".
In summary, while auto-loading observers can simplify a plugin's distribution, plugin authors need to ensure that auto-loading is compatible with the plugin's expected functionality.
Latest Blog Posts [View All]
If I've helped you on the Zen Cart forums or you've found one of my free plugins helpful, feel free to give a little back by clicking here.