Magento 2 is best known as the most successful open source commerce app but did you know that it is a full-fledged PHP framework underneath, complete with several tools to make a developer's life easier? In order to build and maintain a Magento 2 site, developers must adhere to certain framework conventions and use the tools that ship with the app. This talk presents these best practices and introduces some community-created tools as well.
4. @benmarks ZendCon 2016
Have Proper Expectations
• M1 != M2
• M1 expertise is helpful, but not imperative
• Framework + Digital Commerce Application
• Open Source
5. @benmarks ZendCon 2016
Know the Basics
• Own MVC framework, own ORM
• PHP + XML + PHTML
• Composer
• PSR 1-4 (2*)
• Tests (unit, integration, functional)
• Native FPC. Many caches & indexes.
6. @benmarks ZendCon 2016
Have the right setup
• Local environment, or…
• …Virtualization: Docker* & Vagrant
• Use an IDE. PhpStorm is great.
• Step debugger
• Documentation: devdocs.magento.com
• PHP 7!
7. @benmarks ZendCon 2016
Install the Right Way
• Archive or Composer (installs under ./vendor)
composer create-project
--repository-url=https://repo.magento.com/
magento/project-community-edition
• Contributing (installs under ./app/code)
git clone github.com/magento/magento2
(PRs: -b developer - not stable!)
• Sample data
bin/magento sampledata:deploy
bin/magento setup:upgrade
9. @benmarks ZendCon 2016
Understand Modes
• Developer mode
• Static file materialization is not enabled.
• Uncaught exceptions displayed in the browser
• Exceptions thrown in error handler, not logged
• System logging in var/report, highly detailed.
• Production mode
• Deployment phase on the production system;
highest performance
• Exceptions are not displayed to the user -- written
to logs only.
• This mode disables static file materialization.
• The Magento docroot can have read-only
permissions.
Default Mode: just no.
10. @benmarks ZendCon 2016
Know your Job Scope
• Customizations may involve:
• New functionality
• Changed functionality
• Thematic changes
12. @benmarks ZendCon 2016
Use Others’ Work!
• We went to the trouble to make M2 work with Composer
• PSR 1, 2, 3, 4
• Leverage the effort of others!
• marketplace.magento.com
• https://packagist.org/search/?q=magento%202
14. @benmarks ZendCon 2016
Follow coding standards
• Code demarcation
standard
• PHP coding standard
• JavaScript coding
standard
• jQuery widget coding
standard
• DocBlock standard
• JavaScript DocBlock
standard
• LESS coding standard
• HTML style guide
devdocs.magento.com/guides/v2.1/coding-standards/bk-coding-standards.html
21. @benmarks ZendCon 2016
Be Aware of Generation
• Depending on technique, and MAGE_MODE, class
definitions are generated from DI settings +
definition
• Developer: normal step debugging
• Production: check ./var/generation for
generated classes
22. @benmarks ZendCon 2016
Use UI Components
• DRY system for data templating
• “Easy to use”
• Define data source, and go!
• Example