Grokking Magento: Book 1 - Basics & Request Flow

Grokking Magento: Book 1 - Basics & Request Flow

Grokking Magento: Book 1 - Basics & Request Flow Vinai Kopp 2 Contents 1 Introduction7 About this book....................................7 The Magento Developer Certification Preparation Study Group Moderator Kit 9 Prerequisites...................................9 What this book offers.............................. 10 How to use this material............................. 12 Acknowledgements................................ 14 2 Development Environment 17 PHP........................................... 17 IDE........................................... 18 Testing Framework Integrations............................ 18 3 Exercise: Rewrite the sales/order model, add the group ID as an email template variable 21 Original task description................................ 21 Overview..................................... 21 Scenario......................................... 22 Research......................................... 22 3 4 CONTENTS Switching Areas: core/app_emulation..................... 22 Email template placeholders and variables................... 24 Custom email template directives........................ 29 Solution......................................... 30 Why class rewrites work............................. 31 Class name resolution continued........................ 37 Adding the custom email template variable.................. 40 4 Exercise: Redirect to / if the home page is accessed directly by CMS page identifier 43 Original task description................................ 43 Overview..................................... 43 Scenario......................................... 44 Research......................................... 44 The cms/page Entity............................... 44 Request Flow................................... 45 The Front Controller Routing Process..................... 46 The Action Controller Dispatch Process.................... 69 Wrap-Up Summary of the Exercise Research................. 77 Solution......................................... 78 Event Dispatch Process and Observer Configuration............. 78 5 Exercise: Custom frontend controller route; setting the response body 91 Original task description................................ 91 Overview..................................... 91 Scenario......................................... 92 Research......................................... 92 CONTENTS 5 Solution......................................... 95 The Route Configuration............................ 95 The Action Controller Class........................... 96 6 Exercise: Action controller rewrite; customer/session before_auth_url property 99 Original task description................................ 99 Overview..................................... 99 Scenario......................................... 100 Research......................................... 100 Request Rewrite Summary........................... 108 Solution......................................... 108 The customer session before_ and after_auth_url.............. 111 7 Exercise: Dynamic class rewrites 115 Original task description................................ 115 Overview..................................... 115 Scenario......................................... 116 Research......................................... 116 Reading Configuration Values.......................... 116 Setting Configuration Values.......................... 123 Solution......................................... 126 8 Exercise: Diagram of the dispatch process 129 Overview..................................... 129 Scenario......................................... 129 Research......................................... 130 Mage vs. Mage::app().............................. 130 6 CONTENTS The Configuration Load Process........................ 131 The Magento Dispatch Process overview.................... 145 Solution......................................... 146 9 Exercise: Store view selection priorities 149 Overview..................................... 149 Scenario......................................... 149 Research......................................... 150 Summary of the core/app store view selection................. 155 Setting MAGE_RUN_CODE and MAGE_RUN_TYPE.......... 157 The admin store view.............................. 160 Solution......................................... 161 Summary of all store view selection methods................. 162 10 Addendum 165 Varien_Object Magic Setters and Getters...................... 165 Class Name Resolution................................. 167 Model Instantiation Steps............................ 168 Resource Model Instantiation Steps....................... 169 Chapter 1 Introduction Welcome to the first book of the Grokking Magento series. About this book This book series has been a long time dream of mine. I am happy to be able to finally start this project, together with my friend and colleague Ben Marks. The target audience for this book are experienced PHP developers wanting to learn about the Magento platform. The book series has three main goals: 1. Help prepare for the Magento Certified Developer Exam (MCD) 2. To be used as a reference for best practices and Magento architecture 3. Give solutions to specific problems in a “developer cookbook” style The book content follows the Magento Certification Study Group Moderator Kit1 published by Magento. 1http://www.magentocommerce.com/certification/moderators-kit 7 8 CHAPTER 1. INTRODUCTION It takes the bare bone exercises and solutions provided by the Study Group Kit and provides insight into the core architecture by researching how a solution may be approached. Then it discusses the example exercise solutions provided with this book. Along the way, many aspects of the Magento architecture are uncovered, thus providing the background knowledge and mindset required to pass the MCD exam. Almost as a side effect readers will find they become more efficient and effective as Magento developers. This first book in the series focuses on the exercises from the Basics and Request Flow section of the Study Group Kit. It covers the following topics: • Class name resolution • How and why class rewrites work • Application Area Emulation • The Request Flow Process • The Front Controller • Database Based Request Rewrites • Configuration Based Request Rewrites • Action Controller Instantiation • The Action Controller Dispatch Process • Route Configuration • Action Controller Rewrites • Action Controller Flags • The Event Dispatch Process and Observer Configuration • The Configuration XML Loading and Merging Process • Setting, Reading and Saving Configuration Values • The Magento Application Dispatch Process • The Store View Selection Process • Approaches for Multi-Website Setups • The Customer Session beforeAuthUrl and afterAuthUrl Properties • Email Template Placeholders and Variables • Custom Email Template Variables ABOUT THIS BOOK 9 The Magento Developer Certification Preparation Study Group Moderator Kit One of the main tools Magento offers to prepare for the Magento Certified Developer exam (in short: MCD) is the Magento Developer Certification Preparation Study Group Moderator Kit. Phew, what a name! We’ll just call it the “Study Group Kit”. The study group kit is good but rather bare-bones. Besides instructions on how to organize and structure meetings, it comes with a bunch of exercises for each of the content sections and some example solutions. However, for some of the exercises no solutions are provided, and the solutions that do exist only have a few comments in the source code to explain what is happening. The Study Group Kit really is relying on you, or your study group, to dig deep into the Magento source code to figure out how things work exactly. On one hand this makes sense, since it facilitates learning the ins and outs of the Magento framework. On the other hand, it may not be the fastest way to learn for everybody, and certainly not the easiest. Also it is easy to miss things. This book and the others in the Grokking Magento series aim to be a guide through the exercises and solutions, providing additional insight while still helping the reader to become accustomed to the Magento core code. Prerequisites This book is not a basic introduction to Magento development. There are many books and online resources available to get a novice Magento developer started with creating custom Magento modules. This book series expects the reader to have some prior knowledge about Magento. To gain the most from this book, the reader should be familiar with the following topics: • Good knowledge of the PHP language • A solid understanding of object-oriented PHP • How to create a skeleton Magento module 10 CHAPTER 1. INTRODUCTION • The Magento directory structure • The details of Varien_Object’s magic getters and setters2 The more context you already have, the more you will benefit from this book. If you are reading this book as a novice Magento developer, it makes sense to return to this book again later with more knowledge. You can be sure to gain additional knowledge and better understanding the second time around. What this book offers Firstly, this book contains better solutions to the exercises of one section of the MCD study group kit. What’s more, it not only comes with the solution code for the exercises, but also provides extensive documentation for the code in the form of this book. This book can be used as a reference whenever you want to dig into a specific area of Magento development, independently from being in the process of preparing for the MCD exam. One of the best skills to develop

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    170 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us