Magento 2 Modules Are Easy.
#magento2 • @benmarks • #ssphp16

ben@magento.com
Rome wasn’t built in a day
And neither was Magento 2.
The story of Magento 2 begins with Magento 1,
which is now an eight year old technology

(March 31, 2008).
When Magento 1.0 released, PHP was at version
5.2, MySQL was at version 5.0, and no one was
testing PHP apps

(but PhpUnit was at version 3.2).
Of course, building the most popular and
unconventional open source commerce app taught us
some lessons.
Magento 1 Challenges
• Confusing configuration
implementation
• Non-unified module
structure
• Internal coupling
• Extensible, but constrained
by form & function
• Difficult to test
Source: http://www.osnews.com/story/19266/WTFs_m
Magento 1 Challenges
…documentation?!?
Modernizing Magento for 2016+
• PHP 7 support
• GitHub-based collaboration
• Composer-based DM
• Dependency Injection
• PSR adoption (1, 2, 3, 4)
• Updated frontend tech
• Extensible CLI tool
• Test coverage & framework
Modernizing Magento for 2016+
• New checkout flow & architecture
• Performance = CE, Scale = EE
• EE licensing independent of
server architecture
• Quarterly feature releases
• Proposed EE roadmap for 2016:
✦ ElasticSearch, B2B suite,
Staging & Preview, Enhanced CMS
functionality
✦ More…
Magento 2 is the beginning of a new era,

rather than an endpoint.
• Installation methods
• IDE + debugger
• Deployment modes
• Check CLI tool:



$ bin/magento deploy:mode:set developer

$ bin/magento dev:tests:run --help
Developer Preparations
• Module structure is quite different
• Configuration is slightly different
• Controllers are slightly different
• View is quite different
• ORM is mostly the same; yes EAV still is used, and no, MongoDB is
not the solution
• Install/Upgrade (setup) scripts have changed
• New customization options (plugins & preferences)
Framework Notes M1 <> M2
Magento 2 Module Structure
• ./vendor or ./app/code

• Basic module:
★ registration.php
★ etc/module.xml
registration.php
module.xml
Configuration
• Configuration is split
out by type

• Magento 2 provides XSD
for config files; this
helps IDEs & tooling!

• No more class groups
• In Magento 2, all dependencies should be
constructor-injected
Dependencies & DI
• Dependency injection parameters are found in module
di.xml files
DI Configuration
• Dependency injection results in synthesized class
definitions in ./var/generation
DI generation
• Routes are declared in module route.xml files
• Route handlers are instance of MagentoFramework
AppActionAction
• One class per action, one action per class
(different from M1 controllers)
• Action->execute()
Controllers
• Instance of MagentoFrameworkViewElementAbstractBlock
• Templates simplified, most logic moved to block
classes
• Layouts broken out by handle, i.e. no longer ~1 per
module
• Templates & layouts moved inside module’s directory
• jQuery, RequireJS, JS Mixins, LESS
Views
• Model, resource model, collections still there
• No configuration for types
• Simple, complex, EAV
• API (SOAP & REST) are still available
• Service contracts should be on your radar
ORM
Setup Scripts
• No more per-step

files
Customization
• Plugins: before, after,
around (via DI)
• Preferences (via DI) 

≈ rewrites in M1
• Events still there
• Execute before, after, around public methods
• Preferred method of customization
Plugins
• Swap classes
• Change arguments
Preferences & Params
Let’s make a module!
• github.com/magento/magento2 (and ./*)
• devdocs.magento.com
• community.magento.com
• magento.stackexchange.com
• alankent.me
• alanstorm.com
Resources
• Several classes available online
• Fundamentals class available online with in-person
component
• M2-based certifications work begins later in 2016
• I have discount vouchers for you!
Magento U
Thank you!
📧 ben@magento.com
🐦 @benmarks
Feedback: http://bit.ly/m2-tut-1

Magento 2 Modules are Easy!

  • 1.
    Magento 2 ModulesAre Easy. #magento2 • @benmarks • #ssphp16
 ben@magento.com
  • 2.
    Rome wasn’t builtin a day And neither was Magento 2.
  • 3.
    The story ofMagento 2 begins with Magento 1, which is now an eight year old technology
 (March 31, 2008).
  • 4.
    When Magento 1.0released, PHP was at version 5.2, MySQL was at version 5.0, and no one was testing PHP apps
 (but PhpUnit was at version 3.2).
  • 5.
    Of course, buildingthe most popular and unconventional open source commerce app taught us some lessons.
  • 6.
    Magento 1 Challenges •Confusing configuration implementation • Non-unified module structure • Internal coupling • Extensible, but constrained by form & function • Difficult to test Source: http://www.osnews.com/story/19266/WTFs_m
  • 7.
  • 8.
    Modernizing Magento for2016+ • PHP 7 support • GitHub-based collaboration • Composer-based DM • Dependency Injection • PSR adoption (1, 2, 3, 4) • Updated frontend tech • Extensible CLI tool • Test coverage & framework
  • 9.
    Modernizing Magento for2016+ • New checkout flow & architecture • Performance = CE, Scale = EE • EE licensing independent of server architecture • Quarterly feature releases • Proposed EE roadmap for 2016: ✦ ElasticSearch, B2B suite, Staging & Preview, Enhanced CMS functionality ✦ More…
  • 10.
    Magento 2 isthe beginning of a new era,
 rather than an endpoint.
  • 11.
    • Installation methods •IDE + debugger • Deployment modes • Check CLI tool:
 
 $ bin/magento deploy:mode:set developer
 $ bin/magento dev:tests:run --help Developer Preparations
  • 12.
    • Module structureis quite different • Configuration is slightly different • Controllers are slightly different • View is quite different • ORM is mostly the same; yes EAV still is used, and no, MongoDB is not the solution • Install/Upgrade (setup) scripts have changed • New customization options (plugins & preferences) Framework Notes M1 <> M2
  • 13.
    Magento 2 ModuleStructure • ./vendor or ./app/code
 • Basic module: ★ registration.php ★ etc/module.xml
  • 14.
  • 15.
  • 16.
    Configuration • Configuration issplit out by type
 • Magento 2 provides XSD for config files; this helps IDEs & tooling!
 • No more class groups
  • 17.
    • In Magento2, all dependencies should be constructor-injected Dependencies & DI
  • 18.
    • Dependency injectionparameters are found in module di.xml files DI Configuration
  • 19.
    • Dependency injectionresults in synthesized class definitions in ./var/generation DI generation
  • 20.
    • Routes aredeclared in module route.xml files • Route handlers are instance of MagentoFramework AppActionAction • One class per action, one action per class (different from M1 controllers) • Action->execute() Controllers
  • 21.
    • Instance ofMagentoFrameworkViewElementAbstractBlock • Templates simplified, most logic moved to block classes • Layouts broken out by handle, i.e. no longer ~1 per module • Templates & layouts moved inside module’s directory • jQuery, RequireJS, JS Mixins, LESS Views
  • 22.
    • Model, resourcemodel, collections still there • No configuration for types • Simple, complex, EAV • API (SOAP & REST) are still available • Service contracts should be on your radar ORM
  • 23.
    Setup Scripts • Nomore per-step
 files
  • 24.
    Customization • Plugins: before,after, around (via DI) • Preferences (via DI) 
 ≈ rewrites in M1 • Events still there
  • 25.
    • Execute before,after, around public methods • Preferred method of customization Plugins
  • 26.
    • Swap classes •Change arguments Preferences & Params
  • 27.
  • 28.
    • github.com/magento/magento2 (and./*) • devdocs.magento.com • community.magento.com • magento.stackexchange.com • alankent.me • alanstorm.com Resources
  • 29.
    • Several classesavailable online • Fundamentals class available online with in-person component • M2-based certifications work begins later in 2016 • I have discount vouchers for you! Magento U
  • 30.
    Thank you! 📧 ben@magento.com 🐦@benmarks Feedback: http://bit.ly/m2-tut-1