Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Whats new in Magento 2
Search
James Cowie
September 17, 2015
Technology
0
110
Whats new in Magento 2
An overview of what has changed since Magento 1 and what to expect as a developer
James Cowie
September 17, 2015
Tweet
Share
More Decks by James Cowie
See All by James Cowie
Learn to love testing an agile journey into Behat, PHPSpec and Magento
jamescowie
0
340
Outside in BDD
jamescowie
1
75
Behaviour Driven Development
jamescowie
1
970
Other Decks in Technology
See All in Technology
20250903_1つのAWSアカウントに複数システムがある環境におけるアクセス制御をABACで実現.pdf
yhana
3
540
Flutterでキャッチしないエラーはどこに行く
taiju59
0
220
落ちる 落ちるよ サーバーは落ちる
suehiromasatoshi
0
150
2025年になってもまだMySQLが好き
yoku0825
8
4.6k
【初心者向け】ローカルLLMの色々な動かし方まとめ
aratako
7
3.4k
共有と分離 - Compose Multiplatform "本番導入" の設計指針
error96num
1
360
職種の壁を溶かして開発サイクルを高速に回す~情報透明性と職種越境から考えるAIフレンドリーな職種間連携~
daitasu
0
140
人工衛星のファームウェアをRustで書く理由
koba789
13
7.1k
生成AIでセキュリティ運用を効率化する話
sakaitakeshi
0
510
DevIO2025_継続的なサービス開発のための技術的意思決定のポイント / how-to-tech-decision-makaing-devio2025
nologyance
1
370
Aurora DSQLはサーバーレスアーキテクチャの常識を変えるのか
iwatatomoya
1
720
react-callを使ってダイヤログをいろんなとこで再利用しよう!
shinaps
1
230
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
74
5k
Building Applications with DynamoDB
mza
96
6.6k
Facilitating Awesome Meetings
lara
55
6.5k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
51
5.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Speed Design
sergeychernyshev
32
1.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Thoughts on Productivity
jonyablonski
70
4.8k
Transcript
1 Whats New in magento 2
2 James Cowie Software Engineer Session Digital @Jcowie
3 What to expect as a developer
4 Whats changed Since Magento 1
5
6 2012 2009 2012 2009 2013 Composer namespaces. traits generators.
type hinting
7 The world of engineering has changed
8 • Server Architecture • TDD • BDD • DDD
Cloud Docker VPS PHPSpec - 2011 Behat - 2011
9 installing Magento break time
None
11
12 composer create-project --stability=beta --no-install magento/project-community-edition M2Test
{ "name": "magento/project-community-edition", "type": "project", "require": { "magento/product-community-edition": "0.74.0-beta12" },
"require-dev": { } }
14 composer can do much more
15 • Packagist + packages.magento.com • Package versioning • Dependency
Management
composer require "league/period"
1 /** 2 * @var League\Period\Period; 3 */ 4 protected
$_datePeriod; 5 6 /** 7 * @param \League\Period\Period; $datePeriod 8 */ 9 public function __construct(\League\Period\Period $datePeriod) 10 { 11 $this->_datePeriod = $datePeriod; 12 }
18 Versioning In Composer
19 Exact version: “1.4.2″, “v1.4.2″. "magento/product-community-edition": “1.0.1”
20 Ranges: >=1.0, <2.0, "magento/product-community-edition": “>=1.0, <2”
21 Wildcard: “1.0.*”, “1.*” "magento/product-community-edition": “1.*” "magento/product-community-edition": “1.0.*”
22 Next Significant Release: “~1.2″ is equivalent to “>=1.2,<2.0″. "magento/product-community-edition":
“~1.2”
None
24 Decoupling modules
None
26 •Clean Code •Reusable packages •Testable •Easier to read •Easier
to maintain
27 • No Dependency Injection container. • Mage god class
• Hard to test • Hard to decouple logic
28 Dependency Injection in Magento 2
None
public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry
$coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry
$coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator Code Smell
32 • replaces Mage:: god class • Dependency Injection can
be overused. • enables composition.
1 <?php 2 class Sample 3 { 4 protected $logger;
5 6 public function doSomething() 7 { 8 $this->logger = new \Logger(); 9 $logger->doSomething(); 10 } 11 }
1 <?php 2 class Sample 3 { 4 protected $logger;
5 6 public function doSomething() 7 { 8 $this->logger = new \Logger(); 9 $logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
38 • Responsibility • swap concrete implementation • Mock the
dependency
39 Back to Magento 2
/** * @param \Magento\Framework\View\Element\Context $conte */ public function __construct( \Magento\Framework\View\Element\Context
$context ) { parent::__construct($context, $data); }
41 Its not only Objects that can be injected.
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
protected $_extensions; public function __construct( array $extensions = [] )
{ $this->_extensions = $extensions; }
$allowed = $this->_extensions["{$type}_allowed"];
48 • Separating instantiation of objects from the object •
Easier to test • Aids with Separation of concerns
49 Testing
None
None
function it_should_create_a_new_cached_image($filesystem) { $filesystem->beADoubleOf( \Magento\Framework\Filesystem $fileSystem); $this->createCachedFile($filesystem) ->shouldReturnTrue(); }
53 • Composer can help create reusable packages • Dependency
Injection is a must, • Yet be careful on how many dependencies are injected • Testing has become easier • Decoupling of modules is now easier • Magento 2 service contracts / Design by contract ( Interfaces )
54 special thanks
55