Magento PHP Developer’s Guide

Magento PHP Developer’s Guide
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Build your first Magento extension, step by step
  • Extend core Magento functionality, such as the API
  • Learn how to test your Magento code

Book Details

Language : English
Paperback : 256 pages [ 235mm x 191mm ]
Release Date : April 2013
ISBN : 1782163069
ISBN 13 : 9781782163060
Author(s) : Allan MacGregor
Topics and Technologies : All Books, Web Development, e-Commerce, Open Source, PHP

Table of Contents

Chapter 1: Understanding and Setting Up Our Development Environment
Chapter 2: Magento Fundamentals for Developers
Chapter 3: ORM and Data Collections
Chapter 4: Frontend Development
Chapter 5: Backend Development
Chapter 6: The Magento API
Chapter 7: Testing and Quality Assurance
Chapter 8: Deployment and Distribution
Appendix: Hello Magento
    • Chapter 2: Magento Fundamentals for Developers
      • Zend Framework – the base of Magento
      • Magento folder structure
      • Modular architecture
        • Autoloader
        • Code pools
      • Routing and request flow
      • Magento version of MVC
        • Models
        • Views
        • Dissecting a layout file
        • Controllers
      • Websites and store scopes
      • Factory names and functions
      • Events and observers
        • Event dispatch
        • Observer bindings
      • Summary
      • Chapter 3: ORM and Data Collections
        • Magento Model Anatomy
          • It's magic – methods
        • EAV Model
          • What is EAV?
          • Retrieving the data
        • Working with Magento collections
          • Get product collection only from a specific category
          • Get new products added since X date
          • Get Bestseller products
          • Filter product collection by visibility
          • Filter products without images
          • Add multiple sort orders
        • Using Direct SQL
          • Reading
          • Writing
        • Summary
        • Chapter 4: Frontend Development
          • Extending Magento
            • Scenario
            • Features
            • Further improvements
          • Hello Magento
          • XML module configuration
          • Models and saving data
            • Creating the models
            • Setup resources
              • Defining a setup resource
              • Creating the Installer Script
            • What have we learned?
          • Setting up our routes
            • The index controller
            • The search controller
            • The view controller
          • Block and layouts
            • IndexController blocks and views
            • SearchController blocks and views
            • ViewController block and views
            • Adding products to the registry
          • Summary
          • Chapter 5: Backend Development
            • Extending the Adminhtml
              • Back to the configuration
            • The grid widget
              • Managing the registries
              • Permissions and the ACL
              • Updating in bulk with Massactions
            • The form widget
              • Loading the data
              • Saving the data
            • Summary
            • Chapter 6: The Magento API
              • The Core API
                • XML-RPC
                • SOAP
                • RESTful API
              • Using the API
                • Setting up the API credentials for XML-RPC/SOAP
                • Setting up the REST API credentials
                • Loading and reading data
                • Updating data
                • Deleting a product
              • Extending the API
                • Extending the REST API
              • Securing the API
              • Summary
              • Chapter 7: Testing and Quality Assurance
                • Testing Magento
                  • Unit testing
                  • Regression testing
                  • Functional tests
                  • TDD
                • Tools and testing frameworks
                  • Unit testing with PHPUnit
                    • Installing Ecomdev_PHPUnit
                    • Setting up the configuration for our extension
                    • Anatomy of a Test case
                    • Creating a unit test
                  • Functional tests with Mink
                    • Magento Mink installation and setup
                • Creating our first test
                • Summary
                • Chapter 8: Deployment and Distribution
                  • The road towards zero-downtime deployment
                    • Make it right from scratch
                    • Be sure that what you see is what you get
                    • Ready means ready
                  • Version control system and deployment
                    • SVN
                    • Git
                  • Distribution
                    • Packing our extension
                      • Package Info
                      • Release Info
                      • Authors
                      • Dependencies
                      • Contents
                      • Load Local Package
                  • Publishing our extension
                  • Summary

                    Allan MacGregor

                    Allan MacGregor is a Magento Certified Developer Plus with four years of Magento experience. He also has a certification in Linux System Administration by IBM. He started working with Magento as a freelance looking for a better framework to build e-commerce solutions, and he is now the Magento Lead Developer at Demac Media ( He's very passionate about software development in general. He is constantly working with new technologies and frameworks. At Demac Media, he has participated in building core solutions for a wide range of clients; this has given him the experience and knowledge to solve many Magento challenges. As part of an internal project at Demac Media, he worked on (, a unique service for monitoring and auditing the code health of a Magento store. You can also follow him on Twitter at

                    Code Downloads

                    Download the code and support files for this book.

                    Submit Errata

                    Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                    - 20 submitted: last submission 05 Jun 2014

                    Page No.: 108 | Errata type: Code

                    In the "Index Controller" Section the file name should be IndexController.php instead of Index.php. Otherwise the autoloader will not find it.

                    Readers can also find the solutions for their errata at

                    Page No.: 25 | Errata Type: Technical

                    Under the definition for merging towards the top of the page, the second sentence should use branch instead of brand.

                    Page No.: 30 | Errata Type: Typo

                    There is an extra "the" under the third bullet point for "Controller"

                    It should be "The classes in this folder are meant to be abstract classes and extended by the controller class under the controllers folder"

                    Page No.: 40 | Errata type: Technical

                    Second bullet point should say "groups" not "group" since there is no "group" node in the provided code sample.

                    Page No.: 29 | Errata type: technical

                    The image at the bottom shows a typical Magento module folder structure. It should folder name as "Controllers" with a capital "C". It should be "controllers"

                    Page No.: 79 | Errata Type: Code

                    The second code snippet, 1st line of code says:

                    $productCollection->addAttributeToFilter('small_image', array('notnull'=>'','neq'=>'no_selection'));

                    should be

                    $productCollection->addAttributeToFilter('small_image', array('notnull'=>'','neq'=>'no_selection'))

                    There should be no semi colon at the end of the code line.

                    Page No.: 96 | Errata Type: Code

                    At the bottom of the page, bullet point 3:


                    should be


                    Errata type: Typo | Page number: 92

                    In the bottom section the second step:

                    Create a new file called Type.php and copy the following content into the file (the file location is app/code/local/Mdg/Giftregistry/Model/Mysql4/ Type/Collection.php):

                    should be:

                    Create a new file called Collection.php and copy the following content into the file (the file location is app/code/local/Mdg/Giftregistry/Model/Mysql4/ Type/Collection.php):

                    Errata type: Code | Page number: 144

                    The first bullet states the location of the main.phtml template as:


                    The location should read:


                    Errata type: Code | Page number: 81

                    In the section "Using Direct SQL", under "Reading" subsection, the description of `fetchOne` is incorrect

                    Quoting the source code's phpdoc at lib/Varien/Db/Interface.php, `fetchOne` fetches the first column of the first row of the SQL result.

                    Errata type: Code | Page number: 125

                    The edit.phtml file is like this:

                      <input type="hidden" id="type_id" value="<?php echo 
                    $loadedRegistry->getTypeId(); ?>" />

                    This field will not be posted without a name. If you update the edit.phml file like this it works:

                    <input type="hidden" name="type_id" id="type_id" value="<?php echo 
                    $loadedRegistry->getTypeId(); ?>" />
                                <input type="hidden" name="registry_id" id="registry_id"
                    value="<?php echo $loadedRegistry->getEntityId(); ?>" >

                    Errata type: Code | Page number: 125

                    At the bottom of the page there is a table with function can also be written as:


                    Errata type: Code | Page no: 82

                    The line: $read = $resource->getConnection('core_write);

                    Should read: $write = $resource->getConnection('core_write');

                    Errata type: Code | Page no: 113

                    The line: if($this->getRequest()->getPosts() && !empty($data))

                    Should be: if($this->getRequest()->getPost()&&  !empty($data))

                    Errata type: Technical | Page number: 143

                    It reads: "We are setting the gridId; the default sort to be by eventDate, and we are enabling pagination and filtering."

                    Should be: "We are setting the gridId; the default sort to be by eventDate, and we are disabling pagination and filtering." 

                    Errata type: Code | Page number: 129 

                    The line: if ($searchParams = $this->getRequest()->getParam('search_params'))

                    Should be: if ($searchParams = $this->getRequest()->getParam())



                    The line: $this->getLayout()->getBlock('')

                    Should be: $this->getLayout()->getBlock('giftregistry.results')

                    Errata type: Code | Page number: 119

                    The following step:
                    3. Add the following code inside the node (the file location is app/design/frontend/base/default/layout/mdg_giftregistry.xml)

                    Should be:

                    3. Add the following code inside the node (the file location is app/code/local/Mdg/Giftregistry/etc/config.xml)

                    Errata type: Code | Page number: 112

                    The function $this->getRequest()->getPost(), as used within newPostAction, >> editPostAction, and deleteAction, should actually be written as $this->getRequest()->isPost().

                    Errata type: Code | Page number: 114

                    The function deleteAction() must end with a call to $this->_redirect('*/*/'); Otherwise, the registry will be deleted as requested. The end must match the ends of newPostAction() (page 112) and editPostAction() (page 113) 


                    Sample chapters

                    You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                    Frequently bought together

                    Magento PHP Developer’s Guide +    Sakai CLE Courseware Management: The Official Guide =
                    50% Off
                    the second eBook
                    Price for both: A$41.55

                    Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                    What you will learn from this book

                    • Understand the fundamental concepts of Magento
                    • Deploy and distribute custom modules
                    • Explore development techniques and tools for Magento
                    • Extend Magento core functionality
                    • Discover the design patterns which form Magento
                    • Understand Magento architecture
                    • Test Magento with different tools and frameworks

                    In Detail

                    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.

                    "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.

                    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.

                    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.

                    "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.


                    "Magento PHP Developer’s Guide" is an easily accessible tutorial, designed and written to give the reader maximum understanding of the powerful Magento framework.

                    Who this book is for

                    This book is written for developers who have previous experience with PHP and PHP frameworks, such as Zend or CakePHP, and want to start developing and working with Magento. Even developers with previous experience with Magento will find the book extremely useful to gain a full understanding of Magento fundamentals, architecture, and overall philosophy.

                    Code Download and Errata
                    Packt Anytime, Anywhere
                    Register Books
                    Print Upgrades
                    eBook Downloads
                    Video Support
                    Contact Us
                    Awards Voting Nominations Previous Winners
                    Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                    Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software