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

ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 

Kürzlich hochgeladen (11)

ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 

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/