Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Building Magento 2 extensions 101 for Magento 1 developers

10.338 visualizaciones

Publicado el

We, the developers invested much time to get proficient in the art of building extensions in Magento 1. Magento 2 is ist just around the corner. And now? Do we have to start all over again?

This talk aims to show developers how features and techniques from Magento 1 translate to Magento 2.
The goal of a direct comparison between M1 and M2 is to ease the first steps with the new system.

Visit my German blog for more information on Magento 1 & Magento 2!
http://www.matthias-zeis.com

Publicado en: Internet
  • Hey guys! Who wants to chat with me? More photos with me here 👉 http://www.bit.ly/katekoxx
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Nice Post. I would also like to share the best list of Magento 2 extensions that meet all Magento 2.0 Standards and can be easily incorporated into your existing Magento store. Check out here: https://goo.gl/dswLJQ
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Great tips. Thank you very much for this useful information .If you aim at building the store that meets all the requirements of modern eCommerce industry . Then here are the amazing Magento extension which I have found a few days ago. These are cost effective and beneficial for users as well as for beginners. Check it out https://goo.gl/rC9Ira
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí

Building Magento 2 extensions 101 for Magento 1 developers

  1. 1. Matthias Zeis Building Magento 2 extensions 101 for Magento 1 developers (Vienna, AT) Magento Certified Developer @mzeis matthias-zeis.com
  2. 2. What is this talk about? • I know Magento 1 • I want to know Magento 2 • Do I have to start all over again?
  3. 3. https://twitter.com/allanmacgregor/status/554659836999110656
  4. 4. Goal of this talk • Jump start for developers knowing Magento 1 • “I did X in this way in M1, how do I do it in M2?” • Disclaimer: based on 0.74.0-beta 10
  5. 5. Key concepts to grasp • Decoupling modules • Organising modules • Splitting up • Cleaning up • Improving stability • Improving quality
  6. 6. Let's get started!
  7. 7. Create an extension
  8. 8. Create an extension 1. Define the extension 2. Activate the extension
  9. 9. Create an extension: Magento 1 1. Define the extension: Configuration XML file app/code/{core,community,local}/Mzeis/Mm15nl/etc/config.xml <?xml version="1.0"?> <config> <modules> <Mzeis_Mm15nl> <version>1.0.0</version> </Mzeis_Mm15nl> </modules> </config> Extension & DB schema version
  10. 10. Create an extension: Magento 1 2. Activate the extension: Activation XML file app/etc/modules/Mzeis_Mm15nl.xml <?xml version="1.0"?> <config> <modules> <Mzeis_Mm15nl> <active>true</active> <codePool>community</codePool> </Mzeis_Mm15nl> </modules> </config>
  11. 11. And now in Magento 2!
  12. 12. Create an extension: Magento 2 1. Define the extension: Configuration XML file app/code/Mzeis/Mm15nl/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/m odule.xsd"> <module name="Mzeis_Mm15nl" setup_version="1.0.0" /> </config> DB schema version
  13. 13. Create an extension: Magento 2 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/modul e.xsd"> What the…? Autocompletion & validation!
  14. 14. Create an extension: Magento 2 2. Activate the extension: CLI tool modifies app/etc/config.php php bin/magento module:enable Mzeis_Mm15nl
  15. 15. Well done!
  16. 16. Concepts applied • Organising modules • All files in the module directory • Cleaning up • Shortening code • Improving quality • Automated validation • Automated testing
  17. 17. Organising modules
  18. 18. Organising modules: Magento 1 • File organisation • Core: put files into the appropriate directories • Community: modman, Composer + Composer installer • Only hard dependencies • Load order • dependencies • alphabet
  19. 19. Organising modules: Magento 1 • Configure dependencies + load order app/etc/modules/Mzeis_Mm15nl.xml <?xml version="1.0"?> <config> <modules> <Mzeis_Mm15nl> <active>true</active> <codePool>community</codePool> <depends> <Mage_Catalog /> </depends> </Mzeis_Mm15nl> </modules> </config> Hard dependency
  20. 20. Organising modules: Magento 2 • File organisation • Core: Composer + Composer installer • Community: ... okay with that? • Hard & soft dependencies • Load order • sequence configuration • alphabet
  21. 21. { "name": "mzeis/mm15nl", "description": "Meet Magento 15 NL", "require": { "magento/module-store": "0.74.0-beta10" }, "suggest": { "magento/module-cookie": "0.74.0-beta10" }, "type": "magento2-module", "version": "1.0.0", "extra": { "map": [ [ "*", "Mzeis/Mm15nl" ] ] } } Module types Mapping Hard dependency Soft dependency Organising modules: Magento 2 • Configure dependencies app/code/Mzeis/Mm15nl/composer.json Extension version
  22. 22. Organising modules: Magento 2 • Configure load order app/code/Mzeis/Mm15nl/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/mo dule.xsd"> <module name="Mzeis_Mm15nl" setup_version="1.0.0"> <sequence> <module name="Magento_Catalog" /> </sequence> </module> </config> Load order of one or multiple modules No error when module is missing!
  23. 23. Concepts applied • Organising modules • Packaging modules • All files in the module directory • Improving quality • Automated validation • Automated testing
  24. 24. Controller & Route
  25. 25. Controllers & Route 1. Define route 2. Create controller
  26. 26. Controllers & Route: Magento 1 1. Define route app/code/community/Mzeis/Mm15nl/etc/config.xml <config> <frontend> <routers> <mzeis_mm15nl> <use>standard</use> <args> <frontName>mm15nl</frontName> <module>Mzeis_Mm15nl</module> </args> </mzeis_mm15nl> </routers> </frontend>
  27. 27. Controllers & Route: Magento 1 2. Create controller app/code/community/Mzeis/Mm15nl/controllers/IndexController.php <?php class Mzeis_Mm15nl_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(); $this->renderLayout(); } } Multiple actions in one file One controller, one file
  28. 28. Controllers & Route: Magento 2 1. Define route app/code/Mzeis/Mm15nl/etc/frontend/routes.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/r outes.xsd"> <router id="standard"> <route id="mzeis_mmnl" frontName="mm15nl"> <module name="Mzeis_Mm15nl" /> </route> </router> </config> No numbers allowed as of 0.74.0-beta10 (#1290)!
  29. 29. Controllers & Route: Magento 2 2. Create controller app/code/Mzeis/Mm15nl/Controller/Index/Index.php <?php namespace MzeisMm15nlControllerIndex; class Index extends MagentoFrameworkAppActionAction { /* see next slide */ } One controller, one directory One action per file
  30. 30. Controllers & Route: Magento 2 public function __construct( MagentoFrameworkAppActionContext $context, MagentoFrameworkViewResultPageFactory $resultPageFactory ) { $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * @return MagentoFrameworkViewResultPage */ public function execute() { return $this->resultPageFactory->create(); } Dependency Injection
  31. 31. Concepts applied • Decoupling modules • Dependency Injection • Separation of concerns • Splitting up • XML configuration files • Controller actions
  32. 32. Concepts applied • Cleaning up • Separating e-commerce application from framework • Improving quality • Automated validation • Automated testing
  33. 33. Layout & Design
  34. 34. Layout & Design: Magento 1 • Extension layout file path app/design/ {adminhtml,frontend,install}/ rwd/ default/ layout/ mzeis_mm15nl.xml Area Package Theme Extension layout file
  35. 35. Layout & Design: Magento 2 • Extension layout file path app/code/ Mzeis/ Mm15nl/ view/ {adminhtml,base,frontend,install}/ layout/ mzeis_mmnl_index_index.xml Vendor Extension Area Layout handle file Remember #1290!
  36. 36. Layout & Design: Magento 1 • Extension layout file directives <layout version="0.1.0"> <mzeis_mm15nl_index_index> <reference name="content"> <block type="core/text_list" name="mzeis.mm15nl.container" /> <block type="mzeis_mm15nl/talks" name="mzeis.mm15nl.talks" /> </reference> <reference name="root"> <action method="setTemplate"> <template>page/empty.phtml</template> </action> </reference> </mzeis_mm15nl_index_index> </layout> Container-ish Class Modify existing block Layout handle
  37. 37. Layout & Design: Magento 2 • Extension layout file directives <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/La yout/etc/page_configuration.xsd"> <body> <container name="mzeis.mm15nl.container" /> <block class="MzeisMm15nlBlockTalks" name="mzeis.mm15nl.talks" /> <referenceContainer name="root"> <block class="MzeisMm15nlBlockInfo" name="mzeis.mm15nl.info" /> </referenceContainer> </body> Real container Class Modify existing cont.
  38. 38. Concepts applied • Organising modules • All files in the module directory • Splitting up • XML layout files • Cleaning up • Renaming
  39. 39. Interacting with other modules
  40. 40. Interacting with other modules: M1 • Using functionality • Get object from “god class” Mage • Modifying behaviour • Event observers • Rewrite classes • Code pool overrides • No stable API - everything can change without notice!
  41. 41. Interacting with other modules: M2 • Using functionality • Dependency Injection • Service contracts • Modifying behaviour • Plug-ins (interception) • Event observers • Rewrite classes • Public API & SPI - promised to be stable for minor releases!
  42. 42. Reading store configuration Magento 1 public function getTitle() { return Mage::getStoreConfig('mzeis_mm15nl/talks/title'); } Magento 2 public function __construct( MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig ) { $this->scopeConfig = $scopeConfig; } public function getTitle() { return $this->scopeConfig->getValue('mzeis_mm15nl/talks/title'); } Dependency Injection, Public API
  43. 43. Logging Magento 1 Mage::logException($e); Magento 2 public function __construct( PsrLogLoggerInterface $logger ) { $this->logger = $logger; } $this->logger->critical($e); Dependency Injection PSR-3 compliant logger! MagentoFrameworkLoggerMonolog
  44. 44. Loading a product by SKU Magento 1 $product = Mage::getModel('catalog/product'); $product->load($product->getIdBySku($sku)); Magento 2 public function __construct( MagentoCatalogApiProductRepositoryInterface $productRepository ) { $this->productRepository = $productRepository; } $this->productRepository->get($sku); Dependency Injection Service contracts Public API
  45. 45. Concepts applied • Decoupling modules • Dependency injection • Separation of concerns • Improving stability • Plug-ins (interception) • Service contracts • Public API
  46. 46. Conclusion
  47. 47. Decoupling modules • Dependency Injection • Separation of concerns
  48. 48. Organising modules • Packaging modules • All files in the module directory
  49. 49. Splitting up • XML configuration files • XML layout files • Controller actions
  50. 50. Cleaning up • Separating e-commerce application from framework • Shortening code • Renaming
  51. 51. Improving stability • Plug-ins (interception) • Service contracts • Public API
  52. 52. Improving quality • Automated validation • Automated testing
  53. 53. Resources • Code github.com/magento/magento2 • Sample modules github.com/magento/magento2-samples • Documentation devdocs.magento.com • Developer Hub magento.com/developers/magento2 • Fundamentals of magento.com/training/ Magento 2 Development
  54. 54. Resources • Alan Kent alankent.wordpress.com • Max Yekaterynenko maxyek.wordpress.com • Ben Marks bhmarks.com/blog/
  55. 55. Thank you! Questions? Slides slideshare.net/mzeis/ M1 github.com/mzeis/mm15nl-magento1/ M2 github.com/mzeis/mm15nl-magento2/ @mzeis matthias-zeis.com We're hiring! limesoda.com/jobs/

×