Book Image

Magento PHP Developer's Guide

By : Allan MacGregor
Book Image

Magento PHP Developer's Guide

By: Allan MacGregor

Overview of this book

<p>Magento has completely reshaped the face of e-commerce since its launch in 2008. Its revolutionary focus on object oriented and EAV design patterns has allowed it to become the preferred tool for developers and retailers alike.</p> <p>"Magento PHP Developer’s Guide" is a complete reference to Magento, allowing developers to understand its fundamental concepts, and get them developing and testing Magento code.</p> <p>The book starts by building the reader’s knowledge of Magento, providing them with the information, techniques, and tools that they require to start their first Magento development.</p> <p>After building this knowledge, the book will then look at more advanced topics: how to test your code, how to extend the frontend and backend, and deploying and distributing custom modules.</p> <p>"Magento PHP Developer’s Guide" will help you navigate your way around your first Magento developments, helping you to avoid all of the most common headaches new developers face when first getting started.</p>
Table of Contents (16 chapters)
Magento PHP Developer's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Events and observers


The event and observer pattern is probably one of Magento's more interesting features, since it allows developers to extend Magento in critical parts of the application flow.

In order to provide more flexibility and facilitate the interaction between the different modules, Magento implements an event/observer pattern; this pattern allows for modules to be loosely coupled.

There are two parts of this system – an event dispatch with the object and event information, and an observer listening to a particular event.

Event dispatch

Events are created or dispatched using the Mage::dispatchEvent() function. The core team has already created several events on critical parts of the core. For example, the model abstract class Mage_Core_Model_Abstract calls two protected functions every time a model is saved – _beforeSave() and _afterSave(); on each of these methods two events are fired:

protected function _beforeSave()
{
    if (!$this->getId()) {
        $this->isObjectNew(true...