SlideShare une entreprise Scribd logo
1  sur  56
Télécharger pour lire hors ligne
Matthias Zeis
Building Magento 2 extensions 101 for
Magento 1 developers
(Vienna, AT)
Magento Certified Developer
@mzeis
matthias-zeis.com
What is this talk about?
• I know Magento 1
• I want to know Magento 2
• Do I have to start all over again?
https://twitter.com/allanmacgregor/status/554659836999110656
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
Key concepts to grasp
• Decoupling modules
• Organising modules
• Splitting up
• Cleaning up
• Improving stability
• Improving quality
Let's get started!
Create an extension
Create an extension
1. Define the extension
2. Activate the extension
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
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>
And now in Magento 2!
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
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!
Create an extension: Magento 2
2. Activate the extension: CLI tool
modifies app/etc/config.php
php bin/magento module:enable Mzeis_Mm15nl
Well done!
Concepts applied
• Organising modules
• All files in the module directory
• Cleaning up
• Shortening code
• Improving quality
• Automated validation
• Automated testing
Organising modules
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
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
Organising modules: Magento 2
• File organisation
• Core: Composer + Composer installer
• Community: ... okay with that?
• Hard & soft dependencies
• Load order
• sequence configuration
• alphabet
{
"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
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!
Concepts applied
• Organising modules
• Packaging modules
• All files in the module directory
• Improving quality
• Automated validation
• Automated testing
Controller & Route
Controllers & Route
1. Define route
2. Create controller
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>
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
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)!
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
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
Concepts applied
• Decoupling modules
• Dependency Injection
• Separation of concerns
• Splitting up
• XML configuration files
• Controller actions
Concepts applied
• Cleaning up
• Separating e-commerce application from framework
• Improving quality
• Automated validation
• Automated testing
Layout & Design
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
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!
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
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.
Concepts applied
• Organising modules
• All files in the module directory
• Splitting up
• XML layout files
• Cleaning up
• Renaming
Interacting with other modules
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!
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!
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
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
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
Concepts applied
• Decoupling modules
• Dependency injection
• Separation of concerns
• Improving stability
• Plug-ins (interception)
• Service contracts
• Public API
Conclusion
Decoupling modules
• Dependency Injection
• Separation of concerns
Organising modules
• Packaging modules
• All files in the module directory
Splitting up
• XML configuration files
• XML layout files
• Controller actions
Cleaning up
• Separating e-commerce application from framework
• Shortening code
• Renaming
Improving stability
• Plug-ins (interception)
• Service contracts
• Public API
Improving quality
• Automated validation
• Automated testing
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
Resources
• Alan Kent alankent.wordpress.com
• Max Yekaterynenko maxyek.wordpress.com
• Ben Marks bhmarks.com/blog/
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/

Contenu connexe

En vedette

Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhub
Magento Dev
 

En vedette (13)

Sergii Shymko - Code migration tool for upgrade to Magento 2
Sergii Shymko - Code migration tool for upgrade to Magento 2Sergii Shymko - Code migration tool for upgrade to Magento 2
Sergii Shymko - Code migration tool for upgrade to Magento 2
 
Fundamentals of Extending Magento 2 - php[world] 2015
Fundamentals of Extending Magento 2 - php[world] 2015Fundamentals of Extending Magento 2 - php[world] 2015
Fundamentals of Extending Magento 2 - php[world] 2015
 
Magento 2 looks like.
Magento 2 looks like.Magento 2 looks like.
Magento 2 looks like.
 
Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhub
 
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarksMagento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarks
 
How To Install Magento 2 (updated for the latest version)
How To Install Magento 2 (updated for the latest version)How To Install Magento 2 (updated for the latest version)
How To Install Magento 2 (updated for the latest version)
 
How to create theme in Magento 2 - Part 2
How to create theme in Magento 2 - Part 2How to create theme in Magento 2 - Part 2
How to create theme in Magento 2 - Part 2
 
Magento 2 Design Patterns
Magento 2 Design PatternsMagento 2 Design Patterns
Magento 2 Design Patterns
 
Meet Magento Belarus - Magento2: What to expect and when? - Elena Leonova
Meet Magento Belarus -  Magento2: What to expect and when? - Elena LeonovaMeet Magento Belarus -  Magento2: What to expect and when? - Elena Leonova
Meet Magento Belarus - Magento2: What to expect and when? - Elena Leonova
 
Magento 2 overview. Alan Kent
Magento 2 overview. Alan Kent Magento 2 overview. Alan Kent
Magento 2 overview. Alan Kent
 
Max Yekaterynenko: Magento 2 overview
Max Yekaterynenko: Magento 2 overviewMax Yekaterynenko: Magento 2 overview
Max Yekaterynenko: Magento 2 overview
 
Sergii Shymko: Magento 2: Composer for Extensions Distribution
Sergii Shymko: Magento 2: Composer for Extensions DistributionSergii Shymko: Magento 2: Composer for Extensions Distribution
Sergii Shymko: Magento 2: Composer for Extensions Distribution
 
Oleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performanceOleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performance
 

Plus de Matthias Glitzner-Zeis

Plus de Matthias Glitzner-Zeis (8)

Headless CMS for Magento using Hyvä and Storyblok
Headless CMS for Magento using Hyvä and StoryblokHeadless CMS for Magento using Hyvä and Storyblok
Headless CMS for Magento using Hyvä and Storyblok
 
What's new in Magento 2.2?
What's new in Magento 2.2?What's new in Magento 2.2?
What's new in Magento 2.2?
 
Magento News @ Magento Meetup Wien 19
Magento News @ Magento Meetup Wien 19Magento News @ Magento Meetup Wien 19
Magento News @ Magento Meetup Wien 19
 
Magento News @ Magento Meetup Wien 18
Magento News @ Magento Meetup Wien 18Magento News @ Magento Meetup Wien 18
Magento News @ Magento Meetup Wien 18
 
Magento News @ Magento Meetup Wien 17
Magento News @ Magento Meetup Wien 17Magento News @ Magento Meetup Wien 17
Magento News @ Magento Meetup Wien 17
 
Migrating from Magento 1 to Magento 2 @ Magento Meetup Wien
Migrating from Magento 1 to Magento 2 @ Magento Meetup WienMigrating from Magento 1 to Magento 2 @ Magento Meetup Wien
Migrating from Magento 1 to Magento 2 @ Magento Meetup Wien
 
How to migrate from Magento 1 to Magento 2
How to migrate from Magento 1 to Magento 2How to migrate from Magento 1 to Magento 2
How to migrate from Magento 1 to Magento 2
 
Migrating from Magento 1 to Magento 2
Migrating from Magento 1 to Magento 2Migrating from Magento 1 to Magento 2
Migrating from Magento 1 to Magento 2
 

Dernier

Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Sheetaleventcompany
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
sexy call girls service in goa
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ellan12
 

Dernier (20)

Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 

Building Magento 2 extensions 101 for Magento 1 developers

  • 1.
  • 2. Matthias Zeis Building Magento 2 extensions 101 for Magento 1 developers (Vienna, AT) Magento Certified Developer @mzeis matthias-zeis.com
  • 3. What is this talk about? • I know Magento 1 • I want to know Magento 2 • Do I have to start all over again?
  • 5. 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
  • 6. Key concepts to grasp • Decoupling modules • Organising modules • Splitting up • Cleaning up • Improving stability • Improving quality
  • 9. Create an extension 1. Define the extension 2. Activate the extension
  • 10. 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
  • 11. 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>
  • 12. And now in Magento 2!
  • 13. 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
  • 14. 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!
  • 15. Create an extension: Magento 2 2. Activate the extension: CLI tool modifies app/etc/config.php php bin/magento module:enable Mzeis_Mm15nl
  • 17. Concepts applied • Organising modules • All files in the module directory • Cleaning up • Shortening code • Improving quality • Automated validation • Automated testing
  • 19. 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
  • 20. 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
  • 21. Organising modules: Magento 2 • File organisation • Core: Composer + Composer installer • Community: ... okay with that? • Hard & soft dependencies • Load order • sequence configuration • alphabet
  • 22. { "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
  • 23. 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!
  • 24. Concepts applied • Organising modules • Packaging modules • All files in the module directory • Improving quality • Automated validation • Automated testing
  • 26. Controllers & Route 1. Define route 2. Create controller
  • 27. 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>
  • 28. 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
  • 29. 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)!
  • 30. 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
  • 31. 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
  • 32. Concepts applied • Decoupling modules • Dependency Injection • Separation of concerns • Splitting up • XML configuration files • Controller actions
  • 33. Concepts applied • Cleaning up • Separating e-commerce application from framework • Improving quality • Automated validation • Automated testing
  • 35. 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
  • 36. 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!
  • 37. 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
  • 38. 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.
  • 39. Concepts applied • Organising modules • All files in the module directory • Splitting up • XML layout files • Cleaning up • Renaming
  • 41. 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!
  • 42. 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!
  • 43. 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
  • 44. 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
  • 45. 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
  • 46. Concepts applied • Decoupling modules • Dependency injection • Separation of concerns • Improving stability • Plug-ins (interception) • Service contracts • Public API
  • 48. Decoupling modules • Dependency Injection • Separation of concerns
  • 49. Organising modules • Packaging modules • All files in the module directory
  • 50. Splitting up • XML configuration files • XML layout files • Controller actions
  • 51. Cleaning up • Separating e-commerce application from framework • Shortening code • Renaming
  • 52. Improving stability • Plug-ins (interception) • Service contracts • Public API
  • 53. Improving quality • Automated validation • Automated testing
  • 54. 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
  • 55. Resources • Alan Kent alankent.wordpress.com • Max Yekaterynenko maxyek.wordpress.com • Ben Marks bhmarks.com/blog/
  • 56. 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/