SlideShare a Scribd company logo
1 of 56
Download to read offline
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/

More Related Content

Viewers also liked

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
 

Viewers also liked (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
 

More from 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
 

More from 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
 

Recently uploaded

VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneCall girls in Ahmedabad High profile
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our EscortsCall Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escortsindian call girls near you
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
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
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一3sw2qly1
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
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
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdfkeithzhangding
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of indiaimessage0108
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneCall girls in Ahmedabad High profile
 

Recently uploaded (20)

VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our EscortsCall Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
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
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
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
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of india
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
 

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/