Book Image

Getting Started with Magento Extension Development

By : Branko Ajzele
Book Image

Getting Started with Magento Extension Development

By: Branko Ajzele

Overview of this book

Modules, are a group of php and xml files meant to extend the system with new functionality, or override core system behavior. Most of the base Magento system is built using the module system, so you can see why they are an important feature for this rich open-source e-commerce solutions. This book explores key module development techniques and teaches you to modify, understand and structure your modules making it easy for you to get a strong foundation for clean and unobtrusive Magento module development. Getting Started with Magento Extension Development is a practical, hands-on guide to building Magento modules from scratch. This book provides an in depth introduction and helps you discover features such as; blocks, controllers, models, configuration files, and other crucial elements which contribute to the Magento architecture. This book introduces the you to real-world modules and helps provide a strong foundation which you need to become a professional Magento module developer. The book further explores best practices and tips and tricks offering you the ultimate go to guide. Getting Started with Magento Extension Development focuses on three areas. First you are guided through the entire Magento structure, where each important directory or file is explored in detail. Then the essence of the module structure and development is explained through the detailed coverage of models, blocks, controllers, configuration, and other files that manifest a single module. Finally, a detailed set of instructions is given for building four real-world modules, including a payment and shipping module.
Table of Contents (13 chapters)
Getting Started with Magento Extension Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Basic extension configuration


With everything said, by now we should have a solid understanding of the Magento directory structure and be ready to grasp further concepts of the Magento internal structure.

What better way to explain things than an example; so let's start off by creating the simplest extension, which we will then extend bit by bit as we explain the Magento way of doing the object-oriented Model-View-Controller (MVC) architecture. If you are hearing of MVC for the first time, please take some time to familiarize yourself with the concept. You can find good starting material about it at http://en.wikipedia.org/wiki/Model–view–controller.

Previously, we gave examples on the extension name Foggyline_HappyHour, so let's start with that.

In Magento, everything starts with a configuration file; after all, Magento is what we call the configuration-based MVC system. In a configuration-based system, in addition to adding the new files and classes, you often need to explicitly tell the system about them.

The first file we will create is app/etc/modules/Foggyline_HappyHour.xml with the following content:

<?xml version="1.0"?>
<config>
   <modules>
      <Foggyline_HappyHour>
         <active>true</active>
            <codePool>community</codePool>
      </Foggyline_HappyHour>
   </modules>
</config>

With this file in place, Magento already becomes aware of your extension. You can confirm that by going under the Magento administration under System | Configuration | Advanced | Advanced | Disable Modules Output. Once you're there, you should see your Foggyline_HappyHour extension on the list. It is important to know that setting the Disable Modules Output value to Disabled and saving the configuration has absolutely no impact on your extension being truly enabled or disabled.

Disabling the extension output is not the same as disabling the extension itself. Disabling the output of the extension via this configuration option has an effect only on your extension block classes that represent the visually output part of your extension. To truly disable the extension, one must edit the app/etc/modules/Foggyline_HappyHour.xml file and change <active>true</active> to <active>false</active>.

Now that Magento sees our extension, we move on to the next step: creating the app/code/community/Foggyline/HappyHour/etc/config.xml file. This config.xml file is what is usually referred to as the extension configuration file by developers. The following code is the basic definition of our app/code/community/Foggyline/HappyHour/etc/config.xml file:

<?xml version="1.0"?>
<config>
   <modules>
      <Foggyline_HappyHour>
         <version>1.0.0.0</version>
      </Foggyline_HappyHour>
   </modules>
</config>