SlideShare a Scribd company logo
Magento2-handson
Andralungu @iamspringerin
Dependency InjectionPlugins
ServiceContracts
Composer
Proxies
Factories
UiComponents
knockout&Require
Andralungu @iamspringerin
http://tinyurl.com/m2mmro-links
ExtensionAttributes
The clients asks: I want to know when a user wants the invoice
and in this case we need the company name
Addacheckbox,duringtheshippingsteptobe
checkedincasetheuserwantstheinvoiceandin
thatcasethecompanyfieldbecomes required
Addacheckbox,duringtheshippingsteptobecheckedincasetheuserwants
theinvoiceandinthatcasethecompanyfieldbecomesvisibleandrequired.
Easy task, right?
Estimationonmagento1vsMagento2
Andralungu @iamspringerin
Beforewegetstarted
Requirements :
● composer create-project
--repository-url=https://repo.magento.com/
magento/project-community-edition <installation directory
name>
● bin/magento setup:install
● bin/magento deploy:mode:set developer
● bin/magento cache:disable
Wheretogetstarted:let’sCreateourmagento2module
http://tinyurl.com/m2mmro-start
bitbull-team/meetmagentoro/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Bitbull_MeetMagentoRo',
__DIR__
);
Magento components, including modules, themes, and language packages, must be registered in
the Magento system through the Magento ComponentRegistrar class
Wheretogetstarted:let’sCreateourmagento2module
bitbull-team/meetmagentoro/composer.json
"name": "bitbull-team/meetmagentoro",
"description": "sample magento 2 module starter",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/magento-composer-installer": "*"
},
……………………...
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"BitbullMeetMagentoRo": ""
}
}
http://tinyurl.com/m2mmro-start
Wheretogetstarted:let’sCreateourmagento2module
http://tinyurl.com/m2mmro-start
bitbull-team/meetmagentoro/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"
<module name="Bitbull_MeetMagentoRo" setup_version="0.1.0">
</module>
</config>
SETUPSCRIPTS
Setup/InstallSchema
Setup/UpgradeSchema
Setup/InstallData
Setup/UpgradeData
Setup/Recurring - Magento_Indexer module checks for new
defined indexers and adds them to indexer_state table.
Setup/Uninstall
SETUPSCRIPTS
bitbull-team/meetmagentoro/Setup/InstallSchema.php
namespace BitbullMeetMagentoRoSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
/**
* Class InstallSchema
* @package BitbullMeetMagentoRoSetup
*/
class InstallSchema implements InstallSchemaInterface
{
SETUPSCRIPTS
bitbull-team/meetmagentoro/Setup/InstallSchema.php
public function install(SchemaSetupInterface $setup, ModuleContextInterface
$context)
{
$installer = $setup;
$installer->startSetup();
$installer->getConnection()->addColumn(
$installer->getTable('sales_order'),
'invoice_checkbox',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'nullable' => false,
'default' => '0',
'comment' => 'Request invoice'
]
);
$setup->endSetup();
}
SETUPSCRIPTS
magento/module-catalog/Setup/UpgradeData.php
public function upgrade(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context){
$setup->startSetup();
if ($context->getVersion() &&
version_compare($context->getVersion(), '2.0.1') < 0)
<module name="Magento_Catalog" setup_version="2.0.7">
magento/module-catalog/etc/module.xml
SETUPSCRIPTS
bin/magento module:enable Bitbull_MeetMagentoRo
bin/magento setup:upgrade
Expected result:
- In the db, inside setup_module ( old core_resource)
# module, schema_version, data_version
Bitbull_MeetMagentoRo, 0.1.0, 0.1.0
- Listed in config.php
- Listed with bin/magento module:status
- And our new column inside sales_order
SHowitonthefrontend:theeasypart?
http://tinyurl.com/m2mmro-coxml
<argument name=" jsLayout" xsi:type="array">
<item name=" components" xsi:type="array">
<item name=" checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name=" steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name=" shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name=" shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name=" shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<item name=" invoice-checkbox" xsi:type="array">
bitbull-team/meetmagentoro/view/frontend/layout/checkout_index_index.xml
SHowitonthefrontend
<item name="invoice-checkbox" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/boolean</item>
<item name="config" xsi:type="array">
<item name="customScope" xsi:type="string">shippingAddress.custom_attributes</item>
<item name="template" xsi:type="string">ui/form/field</item>
<item name="elementTmpl"
xsi:type="string">Bitbull_MeetMagentoRo/form/element/invoice-check</item>
</item>
<item name="provider" xsi:type="string">checkoutProvider</item>
<item name="dataScope"
xsi:type="string">shippingAddress.custom_attributes.invoice-checkbox</item>
<item name="description" xsi:type="string">Request Invoice</item>
<item name="sortOrder" xsi:type="string">121</item>
</item>
<item name="company" xsi:type="array">
<item name="component" xsi:type="string">Bitbull_MeetMagentoRo/js/invoice-input</item>
<item name="sortOrder" xsi:type="string">122</item>
</item>
SHowitonthefrontend
bitbull-team/meetmagentoro/view/frontend/web/template/form/element/invoice-check.html
<item name="elementTmpl"
xsi:type="string">Bitbull_MeetMagentoRo/form/element/invoice-check</item>
<div class="field choice">
<input type="checkbox" class="checkbox"
data-bind="checked: value, attr: { id: uid, disabled: disabled, name: inputName
}, hasFocus: focused">
<label data-bind="checked: value, attr: { for: uid }">
<span data-bind="text: description"></span>
</label>
</div>
SHowitonthefrontend
bitbull-team/meetmagentoro/view/frontend/web/js/invoice-input.js
<item name="component" xsi:type="string">Bitbull_MeetMagentoRo/js/invoice-input</item>
define([
'underscore',
'Magento_Ui/js/form/element/abstract',
'jquery'
], function (_, Abstract, $) {
"use strict";
return Abstract.extend({
defaults: {
visible: false,
required: false,
listens: {
'${ $.provider }:${ $.customScope ? $.customScope + "." :
""}custom_attributes.invoice-checkbox': 'setVisible'
SHowitonthefrontend
bitbull-team/meetmagentoro/view/frontend/web/js/invoice-input.js
<item name="component" xsi:type="string">Bitbull_MeetMagentoRo/js/invoice-input</item>
setVisible: function () {
var visible =
this.source.shippingAddress.custom_attributes['invoice-checkbox'];
if (visible) {
this.validation['required-entry'] = true;
} else {
this.error(false);
this.validation = _.omit(this.validation, 'required-entry');
}
this.visible(visible);
this.required(visible);
return this;
}
<item name="dataScope"
xsi:type="string">shippingAddress.custom_attributes.invoice-checkbox</item>
Sendittothebackend
bitbull-team/meetmagentoro/view/frontend/requirejs-config.js
var config = {
config:{
mixins: {
'Magento_Checkout/js/action/set-shipping-information': {
'Bitbull_MeetMagentoRo/js/action/set-shipping-information-mixin': true
}
}
},
map: {
'*': {
'Bitbull_MeetMagentoRo/js/invoice-input':
'Bitbull_MeetMagentoRo/js/invoice-input'
}
}
}
http://tinyurl.com/m2mmro-requirejs
Sendittothebackend
bitbull-team/meetmagentoro/view/frontend/web/js/action/set-shipping-information-mixin.js
define([
'jquery',
'mage/utils/wrapper',
'Magento_Checkout/js/model/quote'
], function ($, wrapper, quote) {
'use strict';
return function (setShippingInformationAction) {
return wrapper.wrap(setShippingInformationAction, function (originalAction) {
var shippingAddress = quote.shippingAddress();
if (shippingAddress['extension_attributes'] === undefined) {
shippingAddress['extension_attributes'] = {};
}
shippingAddress['extension_attributes']['invoice_checkbox'] =
shippingAddress.customAttributes['invoice_checkbox'];
// original action Magento_Checkout/js/action/set-shipping-information
return originalAction();
Onestepback:module.xml
If you know that your component’s logic depends on something in another component then you should add it
to require in composer.json and <sequence> in module.xml
<module name="Bitbull_MeetMagentoRo" setup_version="0.1.0">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Ui"/>
</sequence>
</module>
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/magento-composer-installer": "*",
"magento/module-ui": "100.1.*",
"magento/framework": "100.1.*",
"magento/module-checkout": "100.1.*"
},
Onestepback:module.xml
If you change the component load order using <sequence>, you
must regenerate the component list in config.php; otherwise,
the load order does not take effect.
bin/magento module:disable Bitbull_MeetMagentoRo
bin/magento module:enable Bitbull_MeetMagentoRo
Whatwe’vegotsofar
I am a truly believer in Murphy's law so ...let’s see it in action
Saveitinsidetheorder
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name=" sales_model_service_quote_submit_before">
<observer name="save-checkbox-invoice-order"
instance="BitbullMeetMagentoRoObserverSaveCheckboxInvoiceToOrderObserver"/>
</event>
</config>
bitbull-team/meetmagentoro/etc/events.xml
Saveitinsidetheorder
/**
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)
{
/** @var MagentoSalesApiDataOrderInterface $order */
$order = $observer->getOrder();
/** @var MagentoQuoteModelQuote $quote */
$quote = $observer->getQuote();
$invoiceCheckbox =
$quote->getShippingAddress()->getExtensionAttributes()->getInvoiceCheckbox();
$order->setInvoiceCheckbox($invoiceCheckbox);
return $this;
}
bitbull-team/meetmagentoro/Observer/SaveCheckboxInvoiceToOrderObserver.php
Sorrybutisnottheend….
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="add-invoice-check"
type="BitbullMeetMagentoRoPluginSalesApiOrderRepositoryInterfacePlugin"/>
</type>
</config>
bitbull-team/meetmagentoro/etc/di.xml
Sorrybutisnottheend….
/**
*
* @param MagentoSalesApiOrderRepositoryInterface $subject
* @param MagentoSalesApiDataOrderSearchResultInterface $result
* @return MagentoSalesApiDataOrderSearchResultInterface
*/
public function afterGetList(
MagentoSalesApiOrderRepositoryInterface $subject,
MagentoSalesApiDataOrderSearchResultInterface $result
) {
foreach ($result->getItems() as $order) {
$this->getInvoiceCheckExtensionAttribute($order);
}
return $result;
}
bitbull-team/meetmagentoro/Plugin/Sales/Api/OrderRepositoryInterfacePlugin.php
Sorrybutisnottheend….
/**
* @param MagentoSalesApiDataOrderInterface $order
* @return MagentoSalesApiDataOrderInterface
*/
private function getInvoiceCheckExtensionAttribute($order)
{
/** @var MagentoSalesApiDataOrderExtensionInterface $extensionAttributes */
$extensionAttributes = $order->getExtensionAttributes();
if ($extensionAttributes && $extensionAttributes->getInvoiceCheckbox()) {
return $order;
}
if (null === $extensionAttributes) {
$extensionAttributes = $this->orderExtensionFactory->create();
}
$extensionAttributes->setInvoiceCheckbox($order->getInvoiceCheckbox());
$order->setExtensionAttributes($extensionAttributes);
return $order;
}
bitbull-team/meetmagentoro/Plugin/Sales/Api/OrderRepositoryInterfacePlugin.php
THEEND
Questions ?
Thank you
Magento 2 -  hands on MeetMagento Romania 2016

More Related Content

PPTX
Magento Presentation Layer
PDF
Magento 2.1 ee content staging
PPTX
Checkout in Magento 2 by Max Pronko
PDF
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
PPTX
Meet Magento Belarus 2015: Uladzimir Kalashnikau
PPTX
Meet Magento Belarus - Sergey Ivashchenko
PPTX
Meet Magento Belarus 2015: Mladen Ristić
PPTX
Parallelminds.web partdemo
Magento Presentation Layer
Magento 2.1 ee content staging
Checkout in Magento 2 by Max Pronko
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Meet Magento Belarus 2015: Uladzimir Kalashnikau
Meet Magento Belarus - Sergey Ivashchenko
Meet Magento Belarus 2015: Mladen Ristić
Parallelminds.web partdemo

Viewers also liked (12)

PDF
Secure input and output handling - Meet Magento Romania 2016
PDF
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
PDF
Api in magento 2
PPTX
Don’t be a git
PDF
Secure input and output handling - Mage Titans Manchester 2016
PPTX
Magento Imagine eCommerce Conference:5 Way to Supercharge your Magento Enterp...
PPTX
Magento Performance Toolkit
PDF
Magento 2 Development Best Practices
PDF
Real use cases of performance optimization in magento 2
PDF
Oleh Kobchenko - Configure Magento 2 to get maximum performance
PDF
Max Pronko - Best practices for checkout customisation in Magento 2
PDF
Magento Performance Optimization 101
Secure input and output handling - Meet Magento Romania 2016
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
Api in magento 2
Don’t be a git
Secure input and output handling - Mage Titans Manchester 2016
Magento Imagine eCommerce Conference:5 Way to Supercharge your Magento Enterp...
Magento Performance Toolkit
Magento 2 Development Best Practices
Real use cases of performance optimization in magento 2
Oleh Kobchenko - Configure Magento 2 to get maximum performance
Max Pronko - Best practices for checkout customisation in Magento 2
Magento Performance Optimization 101
Ad

Similar to Magento 2 - hands on MeetMagento Romania 2016 (20)

PPTX
Checkout Customizations in Magento 2 - MageTitansMCR 2017
PPTX
How to Create a Dynamic Snippet in Odoo 17
PPTX
Odoo Website - How to Develop Building Blocks
PDF
Polymer Code Lab in Dart - DevFest Kraków 2014
PPTX
How to Add Pagination in Website portal in Odoo
PDF
Web Components for Java Developers
PDF
Simplify React app login with asgardeo-sdk
PDF
Benefits of Google Tag Manager
PDF
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
PDF
"Auth for React.js APP", Nikita Galkin
PDF
implemetning google analytics - 2011-09-24 Google Devfest Chiangmai
PDF
DevFest Chiang Mai - Implementing Google Analytics - 2011-09-24.ppt
PPTX
Implementation of GUI Framework part3
PDF
Introduction to Polymer
PDF
Angular js quickstart
PDF
Monetate Implementation Cheat Sheet
PDF
QCon 2015 - Thinking in components: A new paradigm for Web UI
DOCX
How to Create Module to Track Affiliate Conversions?
TXT
Private slideshow
PDF
Pluginが広げるRailsの魅力
Checkout Customizations in Magento 2 - MageTitansMCR 2017
How to Create a Dynamic Snippet in Odoo 17
Odoo Website - How to Develop Building Blocks
Polymer Code Lab in Dart - DevFest Kraków 2014
How to Add Pagination in Website portal in Odoo
Web Components for Java Developers
Simplify React app login with asgardeo-sdk
Benefits of Google Tag Manager
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
"Auth for React.js APP", Nikita Galkin
implemetning google analytics - 2011-09-24 Google Devfest Chiangmai
DevFest Chiang Mai - Implementing Google Analytics - 2011-09-24.ppt
Implementation of GUI Framework part3
Introduction to Polymer
Angular js quickstart
Monetate Implementation Cheat Sheet
QCon 2015 - Thinking in components: A new paradigm for Web UI
How to Create Module to Track Affiliate Conversions?
Private slideshow
Pluginが広げるRailsの魅力
Ad

Recently uploaded (20)

PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
E -tech empowerment technologies PowerPoint
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
artificial intelligence overview of it and more
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
Introduction to the IoT system, how the IoT system works
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
innovation process that make everything different.pptx
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
Tenda Login Guide: Access Your Router in 5 Easy Steps
WebRTC in SignalWire - troubleshooting media negotiation
Module 1 - Cyber Law and Ethics 101.pptx
E -tech empowerment technologies PowerPoint
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
artificial intelligence overview of it and more
522797556-Unit-2-Temperature-measurement-1-1.pptx
Introduction to the IoT system, how the IoT system works
INTERNET------BASICS-------UPDATED PPT PRESENTATION
An introduction to the IFRS (ISSB) Stndards.pdf
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
innovation process that make everything different.pptx
Introuction about WHO-FIC in ICD-10.pptx
Slides PDF The World Game (s) Eco Economic Epochs.pdf
presentation_pfe-universite-molay-seltan.pptx
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Paper PDF World Game (s) Great Redesign.pdf
SASE Traffic Flow - ZTNA Connector-1.pdf

Magento 2 - hands on MeetMagento Romania 2016