SlideShare a Scribd company logo
1 of 38
Magento 2 module development
An introduction
Joke Puts - @jokeputs
PHP developer at PHPro
What is Magento?
Lets get that question out of the way
A commerce platform
Not just a framework
composer create-project symfony/framework-standard-edition
composer create-project magento/project-community-edition
It’s open source!
The community edition that is
https://github.com/magento/magento2
What's underneath the hood?
Well… a bit of everything
What’s this “module” thing?
An extension, a plugin, … a set of files that makes a feature
What can I do with it?
§Create a composer package
§Create customizations for your commerce platform
§Sell them on the Magento Marketplace
Edition 1-9 extensions
10-30
extensions
31-50
extensions
50+ extensions
Community 10% 53% 26% 11%
Enterprise 9% 32% 27% 32%
Setting it up
Not even a “Hello world”
Adding a customization to your installation?
Start in the app/code directory
Creating a reusable feature?
Create a composer package
§etc/module.xml
§registration.php
§composer.json
https://github.com/jokeputs/mage2-module-setup
registration.php
<?php
MagentoFrameworkComponentComponentRegistrar:
:register(
MagentoFrameworkComponentComponentRegistr
ar::MODULE,
'Vendor_Module',
__DIR__
);
etc/module.xml
<?xml version="1.0" ?>
<config>
<module
name="Vendor_Module"
setup_version="1.0.0" />
</config>
composer.json
{
"name": "vendor/module",
"type": "magento2-module",
"version": "1.0.0",
"require": {
"php": "~7.0.0|~7.1.0",
"magento/framework": "100.1.*"
},
But wait... there’s more!
Or at least there should be
Make this guy your friend!
https://github.com/phpro/grumphp
grumphp.yml
phpcs:
standard: "ruleset.xml"
show_warnings: false
ignore_patterns:
- "vendor"
- "Test/Unit"
triggered_by: [php]
grumphp.yml
triggered_by: [php]
phpunit:
metadata:
priority: 100
grumphp.yml
git_blacklist:
keywords:
- "die("
- "var_dump("
- "exit;"
- "console.log("
triggered_by: [php,js]
Letting Magento know what’s up
Registering your module
bin/magento setup:upgrade
Lets go a little deeper
We only dipped our toe in the water
Model-View-Control pattern
§ Block
§ Controller
§ Model
§ Setup
§ etc
§ frontend
§ routes.xml
§ adminhtml
§ routes.xml
§ view
§ frontend
§ adminhtml
… But it doesn’t do what I want
Change the “core”
Adapting the core
§Dependency injection
§Observers
§Plugins
Dependency injection
§DI via constructor
§Api: interfaces for a module
§etc/di.xml, etc/frontend/di.xml, etc/adminhtml/di.xml
§Class preferences
§Constructor arguments
DI: Class preferences
<preference
for="MagentoCustomerApiAddressRepositoryInter
face"
type="MagentoCustomerModelResourceModelAddre
ssRepository" />
DI: Constructor arguments
<type name="MagentoCustomerModelVisitor">
<arguments>
<argument name="ignoredUserAgents" xsi:type="array">
<item name="google1" xsi:type="string">Googlebot/1.0
(googlebot@googlebot.com http://googlebot.com/)</item>
<item name="google2" xsi:type="string">Mozilla/5.0
(compatible; Googlebot/2.1; +http://www.google.com/bot.html)</item>
<item name="google3" xsi:type="string">Googlebot/2.1
(+http://www.googlebot.com/bot.html)</item>
</argument>
</arguments>
</type>
Events
<event
name="admin_system_config_changed_section_catalo
g">
<observer
name="catalog_update_price_attribute"
instance="MagentoCatalogObserverSwitchPriceAt
tributeScopeOnConfigChange" />
</event>
Plugins
• Modifies behavior of a public method of a class
• Before method
• Runs before the method
• Receives the arguments of the method
• After method
• Runs after completion of the method
• Receives the output of the method
• Around method
• Runs both before and after the method
• Receives the arguments of the method
• Receives a callable, which will give the output of the method
di.xml
<type
name="MagentoEavModelEntityAttributeBackend
AbstractBackend">
<plugin name="attributeValidation"
type="MagentoCatalogPluginModelAttributeBac
kendAttributeValidation"/>
</type>
AttributeValidation.php
public function aroundValidate(AbstractBackend
$subject, Closure $proceed, DataObject $entity)
{
$isAllowedType =
!empty(array_filter(array_map(function
($allowedEntity) use ($entity) {
return $entity instanceof $allowedEntity;
}, $this->allowedEntityTypes)));
...
return $proceed($entity);
}
The one tip…
You know, the one to rule them all
Look at the core
Know it and understand it
Can’t get enough?
I got just the thing for you
Thank you!
https://joind.in/talk/8a633

More Related Content

What's hot

Plugging into plugins
Plugging into pluginsPlugging into plugins
Plugging into plugins
Josh Harrison
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
Brajesh Yadav
 
AngularJS Introduction
AngularJS IntroductionAngularJS Introduction
AngularJS Introduction
Brajesh Yadav
 
JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)
Roger Kitain
 
Filters in AngularJS
Filters in AngularJSFilters in AngularJS
Filters in AngularJS
Brajesh Yadav
 

What's hot (20)

Xaml novinky ve Windows 10
Xaml novinky ve Windows 10Xaml novinky ve Windows 10
Xaml novinky ve Windows 10
 
Built in filters
Built in filtersBuilt in filters
Built in filters
 
Plugging into plugins
Plugging into pluginsPlugging into plugins
Plugging into plugins
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
 
Directives
DirectivesDirectives
Directives
 
AngularJS Introduction
AngularJS IntroductionAngularJS Introduction
AngularJS Introduction
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Shaping up with angular JS
Shaping up with angular JSShaping up with angular JS
Shaping up with angular JS
 
2018 UI5con Drag-and-Drop Concept
2018 UI5con Drag-and-Drop Concept2018 UI5con Drag-and-Drop Concept
2018 UI5con Drag-and-Drop Concept
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
Angular js
Angular jsAngular js
Angular js
 
The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
React django
React djangoReact django
React django
 
JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)
 
Filters in AngularJS
Filters in AngularJSFilters in AngularJS
Filters in AngularJS
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 

Similar to Introduction to Magento 2 module development - PHP Antwerp Meetup 2017

Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Hnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
Hnd201 Building Ibm Lotus Domino Applications With Ajax PluginsHnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
Hnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
dominion
 
Rock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsRock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment Workflows
AOE
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
Trọng Huỳnh
 
Android crash course
Android crash courseAndroid crash course
Android crash course
Showmax Engineering
 

Similar to Introduction to Magento 2 module development - PHP Antwerp Meetup 2017 (20)

Magento++
Magento++Magento++
Magento++
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
 
A Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to DeploymentA Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to Deployment
 
Plugins 2.0: The Overview
Plugins 2.0: The OverviewPlugins 2.0: The Overview
Plugins 2.0: The Overview
 
ElggCamp Santiago> For Developers!
ElggCamp Santiago> For Developers!ElggCamp Santiago> For Developers!
ElggCamp Santiago> For Developers!
 
ElggCamp Santiago - Dev Edition
ElggCamp Santiago - Dev EditionElggCamp Santiago - Dev Edition
ElggCamp Santiago - Dev Edition
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Мы ведь тоже люди. Еретическая лекция про юзабилити инструментов разработчика
Мы ведь тоже люди. Еретическая лекция про юзабилити инструментов разработчикаМы ведь тоже люди. Еретическая лекция про юзабилити инструментов разработчика
Мы ведь тоже люди. Еретическая лекция про юзабилити инструментов разработчика
 
Hnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
Hnd201 Building Ibm Lotus Domino Applications With Ajax PluginsHnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
Hnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Desenvolvimento Mobile Híbrido
Desenvolvimento Mobile HíbridoDesenvolvimento Mobile Híbrido
Desenvolvimento Mobile Híbrido
 
Rock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsRock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment Workflows
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Integrate Shindig with Joomla
Integrate Shindig with JoomlaIntegrate Shindig with Joomla
Integrate Shindig with Joomla
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Developing Android Apps
Developing Android AppsDeveloping Android Apps
Developing Android Apps
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
 
Android crash course
Android crash courseAndroid crash course
Android crash course
 
Magento 2 integration tests
Magento 2 integration testsMagento 2 integration tests
Magento 2 integration tests
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NET
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 

Introduction to Magento 2 module development - PHP Antwerp Meetup 2017