SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Downloaden Sie, um offline zu lesen
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/

Weitere ähnliche Inhalte

Andere mochten auch

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 2Meet Magento Italy
 
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] 2015David Alger
 
Magento 2 looks like.
Magento 2 looks like.Magento 2 looks like.
Magento 2 looks like.Magestore
 
Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhubMagento Dev
 
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 benchmarksYireo
 
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)Magestore
 
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 2Magestore
 
Magento 2 Design Patterns
Magento 2 Design PatternsMagento 2 Design Patterns
Magento 2 Design PatternsMax Pronko
 
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 LeonovaElena Leonova
 
Magento 2 overview. Alan Kent
Magento 2 overview. Alan Kent Magento 2 overview. Alan Kent
Magento 2 overview. Alan Kent MeetMagentoNY2014
 
Max Yekaterynenko: Magento 2 overview
Max Yekaterynenko: Magento 2 overviewMax Yekaterynenko: Magento 2 overview
Max Yekaterynenko: Magento 2 overviewMeet Magento Italy
 
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 DistributionMeet Magento Italy
 
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 performanceMeet Magento Italy
 

Andere mochten auch (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
 

Mehr von Matthias Glitzner-Zeis

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 StoryblokMatthias Glitzner-Zeis
 
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 WienMatthias Glitzner-Zeis
 
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 2Matthias Glitzner-Zeis
 

Mehr von 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
 

Kürzlich hochgeladen

Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
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
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
(+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 ...Escorts Call Girls
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
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).pptxellan12
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 

Kürzlich hochgeladen (20)

Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
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 Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
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...
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
(+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 ...
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
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
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 

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/