SlideShare a Scribd company logo
Join us in Ibiza September 24th – 27th 2012
Magento 2.0:
Prepare yourself for a new way of module development



                                      Ivan Chepurnyi
About Me


 • Devoted to Magento Platform, since May 2007

 • Former Magento Core Team member

 • More than 5 Years of Magento Development
   Experience

 • Technical Director at EcomDev

 • Magento Coach for European developers
Magento 1.x Issues
Non-transparent Module Structure

                                                                             app/design
      app/code
                                                 Layout
                         PHP Classes

                                                              Templates
                 Configuration      Module
                                  Functionality                     Emails

                   Definition
                                                     Translations
                                   Static Data

                                                                             app/locale
    app/etc/modules
                                       skin
Excessive Configurations

 • Info for building
   classes names of
   • Models
   • Blocks
   • Helpers
 • Info about file
   path
   • Layout
   • Translate
Performance


 • Timings for app
   initialization

 • Excessive memory
   usage for building of
   page layout

 • Loading of redundant
   XML configurations for
   each request
Magento 2.0 Module Changes
Module Structure in Magento 2.0

     app/code/<codePool>/<Namespace>/<Module>

             Model
             Helper                 Classes that are used in MVC
                                    application
             Block
             controllers            Configuration files
             etc
                                    Setup Scripts
             sql
             data                   Layouts, Templates, Static Data
             view
                                    Translations
             locale
Refactored Configuration
Changes in Main Configuration


 • Definition of the module in
   app/etc/modules/<Module_Name>.xml moved to
   its etc/config.xml file
 • Added option to specify dependency type
 • Removed class aliases
 • Fieldsets copy rules moved to a separate file
 • Simplified rewrite system
New Modules Bootstrap Logic


 1. Merging only <modules /> nodes from the
    following file paths:
   1.   app/code/pool/Mage/<Module>/etc/config.xml
   2.   app/code/pool/<Namespace>/<Module>/etc/config.xml
   3.   app/etc/modules/<Namespace_ModuleName>.xml
New Modules Bootstrap Logic


 2. Sorting of modules by dependency and checking
    module activity
 3. Merging of the config.xml file from sorted and
    active modules
Dependency Types

 • Hard Dependency (By Default)
 • Soft Dependency


 Snippet:
 <Namespace_Module>
   <depends>
       <Mage_Category type=“soft”/>
       <Mage_Core /> <!– This one is hard dependency 
    </depends>
 </Namespace_Module>
No More Class Aliases

 • A full class name specified in all factory calls
   • Mage::getModel(‘Namespace_Module_Model_Name’);
   • Mage::helper(‘Namespace_Module_Helper_Name’);
   • etc…



 • Now all the factories use the same service locator
Rewrite Is Simplified


  Rewrite is specified for class name instead of
  <models />, <helpers /> and <blocks /> nodes:
  <global>
     <rewrites>
        <ClassName_To_Rewrite>Class_That_Sustitutes</ClassName_To_Rewrite>
     </rewrites>
  </global>
Configuration Changes In Admin Panel

 1. New ACL and authorization system
   • Acl resources now placed at <Module>/etc/adminhtml/acl.xml
   • It is even possible to connect own authentication model

 2. Introduced Menu Builder
   • A separate xml file at <Module>/etc/adminhtml/menu.xml
   • Menu is build by XML instructions: <add />, <update /> and
   <remove />
 3. Added schema for these XML files validation
View Layer Changes
View Structure in Module


 • Layout, templates, module CSS and JS files moved
   from <area>/base/default theme and skin to the
   module directory

 • There is no more template and layout directories
   on view level

 • Module has a view configuration file for defining
   own variables
View Directory

                               Magento Application Area
     view                      (frontend, adminhtml, install)

     <area>                    Layout File that is defined in
                               module config.xml
                layout.xml
                               Template that is specified via
              template.phtml   layout or block construct
                css/file.css
                               Static files that can be
                  file.js      included into HTML markup
                               via layout or template
                image.jpg
View Configuration


 • File is merged from all modules and current
   theme:
   • <Module>/etc/view.xml
   • <theme>/view.xml
 • It has XML scheme for the validation of its content
 • Can be used in feature for Design Editor
View Configuration Example

 In module config or theme:
 <?xml version=“1.0”?>
 <view>
   <vars module=”Namespace_Module”>
     <var name=“items_count”>10</var>
   </vars>
 </view>
 In template or block:
 $this->getVar(‘items_count’, ‘Namespace_Module’);
Changes in Layout

 • Changes in layout building behavior
 • Hierarchical Layout Handles
 • Containers instead of structural blocks
 • New <move /> layout element
Layout building behavior

  1. Adding layout handles updates
  2. Extracting current handles and processing
     <update handle=“<name>”/> node
  3. Transforming XML structure into array tree and
     sorting blocks within that tree without creating
     the block
  4. Applying scheduled remove and move operations
  5. Building blocks and containers from array tree
Hierarchical Page Handles

 • Realized via attributes for layout handle:
   • type=“page”
   • parent=“handle_name”
 • Helps getting rid of layout duplicates
 • Used to specify which layout handles are pages in
   Design Editor functionality
Example of Page Handle

 <catalog_category_view
     translate="label”
     type="page”
     parent="default”>
    <!– some structure -->
 <catalog_category_view>
 <catalog_category_view_type_layered
     translate="label”
     type="page"
     parent="catalog_category_view”>
    <!– some structure -->
 <catalog_category_view_type_layered>
No more structural blocks


 • Blocks will be refactored to be a final unit of view

 • Containers will replace structural blocks

 • Containers are not objects, they are rendered and
   managed by layout model
Container Element

 <container
    name=“unique_name”              Same as for block
    as=“alias_in_parent” ≈
                                    Container HTML properties
    before=“sibling_name”           (optional)
    after=“sibling_name”
    htmlTag=“div”
    htmlClass=“css-class” ≈
    htmlId=“id-in-html”
    label=“Container Name in Design Editor”>
    <container />
    <block />                       Container Name for Design Editor
 </container>                       functionality
Move Statement

                                       The element that should be moved
 <move
   element=“name”                      Destination element in layout
   destination=“destination.element”
   as=“new_alias”                      Same as for block
   after=”sibling_name”       ≈
   before="sibling_name” />
Themes
Simplified Themes

 • Themes become more simple and flexible
   • Only one configuration field in the admin panel
   • It is possible to create as many inherited themes as you
     need
   • Skin become a style/locale variation on theme level
   • Strict files relation in theme to the module
Theme Definition

 • Every theme is defined by theme.xml in its
   directory
   • app/design/<area>/<package>/<theme>/theme.xml

 • It contains:
   • Requirements for Magento version
   • Fallback information
   • Name of the theme for admin user
Theme Definition

 <design>
     <package code=”package_code”>
         <title>Default</title>
         <theme version="2.0.0.0"
                    code=”theme_code” parent=“theme_code”>
              <title>Default</title>
              <requirements>
                   <magento_version
                           from=”1.0.0.0”
                           to=“1.0.0.0|*"/>
              </requirements>
         </theme>
     </package>
 </design>
Theme Definition


 • package/title – package name, that is visible to
   admin user
 • theme/title – theme name, that is visible to admin
   user
 • package/@code – unique identifier of a package
 • theme/@code – unique identifier of a theme
   within the package
Theme Definition


 • theme/@version – internal version of theme
 • theme/@parent – theme name that the current
   one is inherited
 • magento_version/@from – minimal required
   Magento version for theme
 • magento_version/@to - maximum compatible
   version of Magento for theme (can be a wildcard)
Theme Fallbacks

 Fallback structure for dynamic files looks quite
 simple, but you should consider theme inheritance:
 1. <theme>/<Namespace_Module>/layout.xml
 2. <parent_theme>/<Namespace_Module>/layout.x
    ml
 3. <Module>/view/layout.xml
Skin Fallbacks

  • Static files (JS, CSS, Images) should be placed in theme skin directory
  • Theme can have multiple skins, the default skin is “default”
  • Skin directory allows fallbacks on locale level
    •   <theme>/skin/<skin_code>/<locale_code>/file.js
    •   <theme>/skin/<skin_code>/file.js
    •   <theme>/skin/<skin_code>/<locale_code>/<Namespace_Module>/file.js
    •   <theme>/skin/<skin_code>/<Namespace_Module>/file.js
Localization Inheritance
Localization Inheritance


  It is possible to define inheritance between locales in
  any xml file that is merged for global configuration:
  <global>
      <locale>
           <inheritance>
               <!-- Inheritance of UK Locale from US one -->
               <en_GB>en_US</en_GB>
           </inheritance>
      </locale>
  </global>
Developer Stuff
Developer Stuff

  • dev/shell – same as Magento 1 shell directory
  • dev/tests – set of different test suites:
   • integration – tests that require Magento initialization
   • js – Java Script UnitTests
   • unit – test that can be run without Magento
   • performance – load tests
   • static – code analysis tools
Developer Stuff

  • dev/tools – tools for developer
   • migration – a set of tools for migration of Magento 1.x
     module to 2.0
   • classmap – generator of the class map
   • batch_tests – batch test runner
Thank You
Your Questions




                 E-mail: ivan@ecomdev.org

More Related Content

PPTX
Magento Indexes
PPTX
Fixing Magento Core for Better Performance - Ivan Chepurnyi
PDF
Magento Product Types Demystified
PPTX
Making Magento flying like a rocket! (A set of valuable tips for developers)
PDF
Tips and Tricks for LiveWhale Development
PPTX
Editing the Visual Editor (WordPress)
KEY
Templates
KEY
Django Admin: Widgetry & Witchery
Magento Indexes
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Magento Product Types Demystified
Making Magento flying like a rocket! (A set of valuable tips for developers)
Tips and Tricks for LiveWhale Development
Editing the Visual Editor (WordPress)
Templates
Django Admin: Widgetry & Witchery

What's hot (20)

PDF
Maven plugin guide using Modello Framework
PDF
Polymer
PDF
How to Develop a Basic Magento Extension Tutorial
ODP
A Complete Tour of JSF 2
PPT
An Introduction to Drupal
PDF
Alfredo-PUMEX
PDF
Web components - An Introduction
PDF
td_mxc_rubyrails_shin
PDF
How to Create A Magento Adminhtml Controller in Magento Extension
PDF
How to create a magento controller in magento extension
PPT
Mangento
PDF
Handlebars and Require.js
PPTX
MVC Frameworks for building PHP Web Applications
PPTX
MVC & SQL_In_1_Hour
PPTX
Angular JS
PDF
Empowering users: modifying the admin experience
PDF
Intro To Mvc Development In Php
PPTX
Simple module Development in Joomla! 2.5
PDF
AngularJS 101 - Everything you need to know to get started
PPTX
WordPress plugin #2
Maven plugin guide using Modello Framework
Polymer
How to Develop a Basic Magento Extension Tutorial
A Complete Tour of JSF 2
An Introduction to Drupal
Alfredo-PUMEX
Web components - An Introduction
td_mxc_rubyrails_shin
How to Create A Magento Adminhtml Controller in Magento Extension
How to create a magento controller in magento extension
Mangento
Handlebars and Require.js
MVC Frameworks for building PHP Web Applications
MVC & SQL_In_1_Hour
Angular JS
Empowering users: modifying the admin experience
Intro To Mvc Development In Php
Simple module Development in Joomla! 2.5
AngularJS 101 - Everything you need to know to get started
WordPress plugin #2
Ad

Similar to Magento 2.0: Prepare yourself for a new way of module development (20)

PPTX
Magento mega menu extension
PPTX
Finding Your Way: Understanding Magento Code
PDF
Magento2 Basics for Frontend Development
PPTX
Magento 2 theming - knowledge sharing session by suman kc
PDF
Federico Soich - Upgrading Magento Version
PPTX
Magento 2 View Layer Evolution
PDF
Magento 2 Backend Development Essentials
PDF
Front End Development in Magento
PDF
Designing for magento
PPTX
Magento 2: A technical overview
PDF
How To Create Theme in Magento 2 - Part 1
PPTX
php[world] Magento101
PPTX
Magento2 frontend development
PPTX
Zendcon magento101
PPTX
Magento 2 - Getting started.
PDF
A Successful Magento Project From Design to Deployment
PDF
How to-create-a-simple-module-in-magento-2.0
PDF
29. Magento Meetup - Why the hell did I choose Magento 2?
PPTX
Magento 1.x to Magento 2 Code Migration Tools
PDF
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Magento mega menu extension
Finding Your Way: Understanding Magento Code
Magento2 Basics for Frontend Development
Magento 2 theming - knowledge sharing session by suman kc
Federico Soich - Upgrading Magento Version
Magento 2 View Layer Evolution
Magento 2 Backend Development Essentials
Front End Development in Magento
Designing for magento
Magento 2: A technical overview
How To Create Theme in Magento 2 - Part 1
php[world] Magento101
Magento2 frontend development
Zendcon magento101
Magento 2 - Getting started.
A Successful Magento Project From Design to Deployment
How to-create-a-simple-module-in-magento-2.0
29. Magento Meetup - Why the hell did I choose Magento 2?
Magento 1.x to Magento 2 Code Migration Tools
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Ad

More from Ivan Chepurnyi (6)

PPTX
Optimizing Magento by Preloading Data
PDF
How to import 1 million SKUs in under 10 minutes
PDF
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
PPTX
Varnish Cache and its usage in the real world!
PPTX
Hidden Secrets of Magento Price Rules
PPTX
Using of TDD practices for Magento
Optimizing Magento by Preloading Data
How to import 1 million SKUs in under 10 minutes
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Varnish Cache and its usage in the real world!
Hidden Secrets of Magento Price Rules
Using of TDD practices for Magento

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Modernizing your data center with Dell and AMD
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
Modernizing your data center with Dell and AMD
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KodekX | Application Modernization Development

Magento 2.0: Prepare yourself for a new way of module development

  • 1. Join us in Ibiza September 24th – 27th 2012
  • 2. Magento 2.0: Prepare yourself for a new way of module development Ivan Chepurnyi
  • 3. About Me • Devoted to Magento Platform, since May 2007 • Former Magento Core Team member • More than 5 Years of Magento Development Experience • Technical Director at EcomDev • Magento Coach for European developers
  • 5. Non-transparent Module Structure app/design app/code Layout PHP Classes Templates Configuration Module Functionality Emails Definition Translations Static Data app/locale app/etc/modules skin
  • 6. Excessive Configurations • Info for building classes names of • Models • Blocks • Helpers • Info about file path • Layout • Translate
  • 7. Performance • Timings for app initialization • Excessive memory usage for building of page layout • Loading of redundant XML configurations for each request
  • 9. Module Structure in Magento 2.0 app/code/<codePool>/<Namespace>/<Module> Model Helper Classes that are used in MVC application Block controllers Configuration files etc Setup Scripts sql data Layouts, Templates, Static Data view Translations locale
  • 11. Changes in Main Configuration • Definition of the module in app/etc/modules/<Module_Name>.xml moved to its etc/config.xml file • Added option to specify dependency type • Removed class aliases • Fieldsets copy rules moved to a separate file • Simplified rewrite system
  • 12. New Modules Bootstrap Logic 1. Merging only <modules /> nodes from the following file paths: 1. app/code/pool/Mage/<Module>/etc/config.xml 2. app/code/pool/<Namespace>/<Module>/etc/config.xml 3. app/etc/modules/<Namespace_ModuleName>.xml
  • 13. New Modules Bootstrap Logic 2. Sorting of modules by dependency and checking module activity 3. Merging of the config.xml file from sorted and active modules
  • 14. Dependency Types • Hard Dependency (By Default) • Soft Dependency Snippet: <Namespace_Module> <depends> <Mage_Category type=“soft”/> <Mage_Core /> <!– This one is hard dependency  </depends> </Namespace_Module>
  • 15. No More Class Aliases • A full class name specified in all factory calls • Mage::getModel(‘Namespace_Module_Model_Name’); • Mage::helper(‘Namespace_Module_Helper_Name’); • etc… • Now all the factories use the same service locator
  • 16. Rewrite Is Simplified Rewrite is specified for class name instead of <models />, <helpers /> and <blocks /> nodes: <global> <rewrites> <ClassName_To_Rewrite>Class_That_Sustitutes</ClassName_To_Rewrite> </rewrites> </global>
  • 17. Configuration Changes In Admin Panel 1. New ACL and authorization system • Acl resources now placed at <Module>/etc/adminhtml/acl.xml • It is even possible to connect own authentication model 2. Introduced Menu Builder • A separate xml file at <Module>/etc/adminhtml/menu.xml • Menu is build by XML instructions: <add />, <update /> and <remove /> 3. Added schema for these XML files validation
  • 19. View Structure in Module • Layout, templates, module CSS and JS files moved from <area>/base/default theme and skin to the module directory • There is no more template and layout directories on view level • Module has a view configuration file for defining own variables
  • 20. View Directory Magento Application Area view (frontend, adminhtml, install) <area> Layout File that is defined in module config.xml layout.xml Template that is specified via template.phtml layout or block construct css/file.css Static files that can be file.js included into HTML markup via layout or template image.jpg
  • 21. View Configuration • File is merged from all modules and current theme: • <Module>/etc/view.xml • <theme>/view.xml • It has XML scheme for the validation of its content • Can be used in feature for Design Editor
  • 22. View Configuration Example In module config or theme: <?xml version=“1.0”?> <view> <vars module=”Namespace_Module”> <var name=“items_count”>10</var> </vars> </view> In template or block: $this->getVar(‘items_count’, ‘Namespace_Module’);
  • 23. Changes in Layout • Changes in layout building behavior • Hierarchical Layout Handles • Containers instead of structural blocks • New <move /> layout element
  • 24. Layout building behavior 1. Adding layout handles updates 2. Extracting current handles and processing <update handle=“<name>”/> node 3. Transforming XML structure into array tree and sorting blocks within that tree without creating the block 4. Applying scheduled remove and move operations 5. Building blocks and containers from array tree
  • 25. Hierarchical Page Handles • Realized via attributes for layout handle: • type=“page” • parent=“handle_name” • Helps getting rid of layout duplicates • Used to specify which layout handles are pages in Design Editor functionality
  • 26. Example of Page Handle <catalog_category_view translate="label” type="page” parent="default”> <!– some structure --> <catalog_category_view> <catalog_category_view_type_layered translate="label” type="page" parent="catalog_category_view”> <!– some structure --> <catalog_category_view_type_layered>
  • 27. No more structural blocks • Blocks will be refactored to be a final unit of view • Containers will replace structural blocks • Containers are not objects, they are rendered and managed by layout model
  • 28. Container Element <container name=“unique_name” Same as for block as=“alias_in_parent” ≈ Container HTML properties before=“sibling_name” (optional) after=“sibling_name” htmlTag=“div” htmlClass=“css-class” ≈ htmlId=“id-in-html” label=“Container Name in Design Editor”> <container /> <block /> Container Name for Design Editor </container> functionality
  • 29. Move Statement The element that should be moved <move element=“name” Destination element in layout destination=“destination.element” as=“new_alias” Same as for block after=”sibling_name” ≈ before="sibling_name” />
  • 31. Simplified Themes • Themes become more simple and flexible • Only one configuration field in the admin panel • It is possible to create as many inherited themes as you need • Skin become a style/locale variation on theme level • Strict files relation in theme to the module
  • 32. Theme Definition • Every theme is defined by theme.xml in its directory • app/design/<area>/<package>/<theme>/theme.xml • It contains: • Requirements for Magento version • Fallback information • Name of the theme for admin user
  • 33. Theme Definition <design> <package code=”package_code”> <title>Default</title> <theme version="2.0.0.0" code=”theme_code” parent=“theme_code”> <title>Default</title> <requirements> <magento_version from=”1.0.0.0” to=“1.0.0.0|*"/> </requirements> </theme> </package> </design>
  • 34. Theme Definition • package/title – package name, that is visible to admin user • theme/title – theme name, that is visible to admin user • package/@code – unique identifier of a package • theme/@code – unique identifier of a theme within the package
  • 35. Theme Definition • theme/@version – internal version of theme • theme/@parent – theme name that the current one is inherited • magento_version/@from – minimal required Magento version for theme • magento_version/@to - maximum compatible version of Magento for theme (can be a wildcard)
  • 36. Theme Fallbacks Fallback structure for dynamic files looks quite simple, but you should consider theme inheritance: 1. <theme>/<Namespace_Module>/layout.xml 2. <parent_theme>/<Namespace_Module>/layout.x ml 3. <Module>/view/layout.xml
  • 37. Skin Fallbacks • Static files (JS, CSS, Images) should be placed in theme skin directory • Theme can have multiple skins, the default skin is “default” • Skin directory allows fallbacks on locale level • <theme>/skin/<skin_code>/<locale_code>/file.js • <theme>/skin/<skin_code>/file.js • <theme>/skin/<skin_code>/<locale_code>/<Namespace_Module>/file.js • <theme>/skin/<skin_code>/<Namespace_Module>/file.js
  • 39. Localization Inheritance It is possible to define inheritance between locales in any xml file that is merged for global configuration: <global> <locale> <inheritance> <!-- Inheritance of UK Locale from US one --> <en_GB>en_US</en_GB> </inheritance> </locale> </global>
  • 41. Developer Stuff • dev/shell – same as Magento 1 shell directory • dev/tests – set of different test suites: • integration – tests that require Magento initialization • js – Java Script UnitTests • unit – test that can be run without Magento • performance – load tests • static – code analysis tools
  • 42. Developer Stuff • dev/tools – tools for developer • migration – a set of tools for migration of Magento 1.x module to 2.0 • classmap – generator of the class map • batch_tests – batch test runner
  • 44. Your Questions E-mail: ivan@ecomdev.org