Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
Riccardo TempestaThe right tools for the right job in Magento 2
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
The daily work of a [Magento 2] developer consists of two main job types
Debuggingexisting features
Creatingnew features
Your code3rd party’s
(or core) code
A B
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
We will focus on this
Debuggingexisting features
Creatingnew features
Your code3rd party’s
(or core) code
A B
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
A SHORT HINT ON: CREATING FEATURES
You will need these thingies:
PHPStorm IDE
Vagrant (or Docker ?)
GIT
Magicento2
Code generators
A lot of free time…
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
A SHORT HINT ON: CREATING FEATURES
Magicento 2 and Code Generators because: Magento 2 requires a bit of boilerplate code A typo is always lurking somewhere Your time is not free The amount of required code may be considerable You may need a social life… (not sure about this)
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
A SHORT HINT ON: CREATING FEATURES
STARTING YOUR PROJECT:Mage2Gen can create a whole module skeleton with a minimum effort.It is an online/commandline tool available at: https://mage2gen.com/
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
DEVELOPING YOUR PROJECT:Magicento can create controllers, modules, plugins, observers and lots of other coding entities in few clicks.Convenient code hints and autocompletition.
Your client does not always understand how complex this job is!So make it as simple as possible!
REMEMBER
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
A SHORT HINT ON: CREATING FEATURESExample of code complexity: Magento 1 vs. Magento 2
Magento 1 – DB Models: Model ResourceModel Collection Install / Upgrade scripts config.xml
Magento 2 – DB Models: Model Data Model ResourceModel Collection Install / Upgrade scripts Repository Repository Interface Model Interface Data Interface Preferences Getters / Setters in DataInterface
Total involved files: 4-5 Total involved files: 10-11
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
A SHORT HINT ON: CREATING FEATURESYou will need: MageSpecialist Code Monkey
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
magento@somewhere:~$ php bin/magento msp:cm:crud My_Module Myentity mydatabasetable
● Model● Data Model● DataModel Interface● Resource Model● Collection● Repository● Repository Interface● Registry
● di.xml configuration● Getters● Setters● Repository getters based
on table indexes● Fully Magento2
codestyling compliant
Starting from a database table it can create:
https://github.com/magespecialist/m2-MSP_CodeMonkey
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
https://github.com/staempfli/magento2-phpstorm-templatesTwitter: @Jalogut
A SHORT HINT ON: MORE ADVANCED TOOLS
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
PhpStorm Magento2 Templatesfrom Juan Alonso @ StaempfliHigh M2 coding standard compliance.
Ultimate Magento2 module creatorfrom Marius Strajeru
https://github.com/UltimateModuleCreator/Umc_BaseTwitter: @MariusStrajeru
Remember:you owe a beerto both of them
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING
DEBUGGING & REVERSE ENGINEERINGbe honest… they are the actual 99% work of a developer
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Your code3rd party’s
(or core) code
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Common scenario when you’re debugging your code:
You do not know where the broken piece of code may be.
It is very hard to let the client understand that debugging is part (actually: the
most) of developing, so:
You probably do not have any of the project’s budget lef;
Plus, you have a very short time to fix it!
You did not write any kind of test… We know it, do not lie on this!
Stack Exchange is offline.
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Common scenario when you’re debugging 3rd party’s code:
You have no clue about the how the work’s engineered.
You still do not know where the broken piece of code is.
You hope the programmer who worked on that code before you did not touch the
core.
The programmer who created that feature is now probably on permanent vacation
and/or does not speak a single word of your language!
Stack Exchange is still offline…
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
HOPE IT’S NOT A MESS OF
SPAGHETTI CODE
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
“I’ve seen PHP code you people wouldn’t believe…”
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Debugging process can be tricky in Magento 2.
Magento 2 has lots of new ways to intercept and change the standard core behaviour...
(I mean without changing the core! Do not try this at home!)
Magento 1 rewriting tools
Rewrites
Routes hijacking
Observers
Layout updates
Magento 2 rewriting tools
Preferences
Routes hijacking
Observers
Layout updates
Stackable plugins (after, before, around)
Extension attributes
…
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
FINDING THE PIECE OF CODE YOU NEED CAN BE OFTEN CHALLENGING AND TIME
CONSUMING.
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
DEBUGGING FEATURES
So the hard part is simply
FIND SOME PIECE OF CODE DOING SOMETHING SOMEHOW SOMEWHERE
and, once found
FIX SOMETHING BROKEN SOMEWHERE WITHSOME THING YOU WILL DO SOMEHOW
As easy as pie… isn’t it?
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
PhpStorm as IDE
MSP DevTools
To find out where the code is
PHP Xdebug
To find out what’s wrong with the code
GIT bisect
To find out when you broke it
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
DEBUGGING FEATURES
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
DEBUGGING FEATURES: MSP DEVTOOLS
Magento 1 & Magento 2 support
Free github project
Chrome extension
Chrome inspector integration
PHPStorm integration
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES: PHP X-DEBUG Suspend code execution
Inspect variables
Log results
Runtime variables value change
PHP Storm integrates it
You can do the same with “var_dump”, “print_r” and “echo”, but
everytime you do that, a programmer dies somewhere!
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
MEH IZ PROGRAMMAHPLZ DON’T KILL MEH
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEMO #1
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
MEH IZ PROGRAMMAHPLZ DON’T KILL MEH
PHP Storm MSP DevTools Xdebug
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES: GIT BISECT
A typical customer’s bug report is like:
If you manage to understand what is actually broken you can use GIT bisect.
So you just need to know:
what the broken features is and
when it was working for the last time.
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
“Yesterday all was working on the website, today nothing works! Fix it!!11!1!!”
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEBUGGING FEATURES: GIT BISECT
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Works like this
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
DEMO #2
MEH IZ PROGRAMMAHPLZ DON’T KILL MEH
Git bisect
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
GIT BISECT!
BAD COMMIT!OH NO!
SO BUGFOUND! RESTORED!
WOW!
Riccardo Tempesta @ MageSpecialist / Twitter: @RicTempesta #MM17RO
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO 2 CODING)
THANK YOU!
KEEP CALM AND
I WILL ANSWERYOUR QUESTIONS
Github:MageSpecialist
Twitter:@RicTempesta