Top Banner
22

Develop faster on Magento 2 using code generation tools

Jan 21, 2018

Download

Juan Alonso
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Develop faster on Magento 2 using code generation tools
Page 2: Develop faster on Magento 2 using code generation tools

Develop faster on M2 using code generation tools

Juan AlonsoSenior Developer @ Stämpfli

Page 3: Develop faster on Magento 2 using code generation tools

About me

• @Jalogut

• Senior Developer at Stämpfli AG

• +5 years working on Magento

• Magento Certified Developer

• Magento Certified Solution Specialist

Page 4: Develop faster on Magento 2 using code generation tools

Agenda

1. Personal experience working with Magento2

2. What are code generation tools?

3. Existing tools for Magento2

4. My own generator

5. Live Demo

6. Other tips

Page 5: Develop faster on Magento 2 using code generation tools

Personal Experience on M2

• Experience -> lots of copy-pasting

• One goal -> avoid copy-pasting

• Problem -> many different file formats

• Xml definitions

• Class types and inheritance

Page 6: Develop faster on Magento 2 using code generation tools

Personal Experience on M2

• Solution -> PHPStorm Templates

• @VinaiKopp Gist

• https://gist.github.com/Vinai/eb4713bda65fb8b467b1

• Magento2-phpstorm-templates

• https://github.com/staempfli/magento2-phpstorm-templates

Page 7: Develop faster on Magento 2 using code generation tools

😃

I was Happy

Page 8: Develop faster on Magento 2 using code generation tools

Personal Experience on M2

• Another Problem -> CRUD Modules

• + 30 files needed

Page 9: Develop faster on Magento 2 using code generation tools

😢

Sad again

Page 10: Develop faster on Magento 2 using code generation tools

🤔So what can I do?

Page 11: Develop faster on Magento 2 using code generation tools

Personal Experience on M2

• Solution -> Code generation tools

• https://www.yireo.com/blog/1816-magento-2-code-generation-tools

Page 12: Develop faster on Magento 2 using code generation tools

What are code generation tools?

• Tools that help developers to create modules more easily

• Automatically generate files with working code

• Skip boring process of creating files that are always the same

• Quick start to have base code of a module or functionality

Page 13: Develop faster on Magento 2 using code generation tools

Existing Tools for M2

• Pestle (Alan Storm): https://github.com/astorm/pestle

• N98-magerun2: https://github.com/netz98/n98-magerun2

• Mage2gen:

• https://mage2gen.com/

• https://github.com/krukas/Mage2Gen

• MSP_CodeMonkey (under construction):

• https://github.com/magespecialist/m2-MSP_CodeMonkey

Page 14: Develop faster on Magento 2 using code generation tools

My own generator

Goals:

• Similar to “PHPStorm live templates” but for multiple files

• Folders & files structure with placeholders

• Easily extensible:

• Simple and fast to add new templates

• Encourage other developers to contribute

• Keep it simple

Page 15: Develop faster on Magento 2 using code generation tools

My own generator

magento2-code-generator

• Github repo:

• https://github.com/staempfli/magento2-code-generator

Page 16: Develop faster on Magento 2 using code generation tools

🤔Live Demo

Page 17: Develop faster on Magento 2 using code generation tools

Live Demo

• Playlist videos:

• https://www.youtube.com/playlist?list=PLBt8dizedSZCxuqK41vG01_MngJQPRuMj

• CRUD EAV in 5 minutes:

• https://www.youtube.com/watch?v=f8qBnOIRIs4

Page 18: Develop faster on Magento 2 using code generation tools

Conclusions

• Stop copy-pasting

• Use a code generation tool for Magento 2.

• It will make your life easier.

• They are free, your time is not

• If you miss something, just contribute, they are open-source.

Page 19: Develop faster on Magento 2 using code generation tools

Links• Twitter: @Jalogut

• Commercehero: https://commercehero.io/juan.alonso

• PHPStorm templates:

• https://github.com/staempfli/magento2-phpstorm-templates

• magento2-code-generator:

• https://github.com/staempfli/magento2-code-generator

Page 20: Develop faster on Magento 2 using code generation tools

?

Page 21: Develop faster on Magento 2 using code generation tools

Other tips• PHPStorm External Tools

• Preferences > Tools > External Tools

• Keymap > External Tools > External Tools

• Useful tools:

• Clear cache: bin/magento cache:clean

• Setup: bin/magento setup:upgrade

• Generation flush: bin/n98-magerun2 generation:flush

• Purge all:

find var/generation var/cache var/page_cache var/view_preprocessed pub/static -mindepth 1 -maxdepth

1 -not -name .htaccess -exec rm -r {} +

Page 22: Develop faster on Magento 2 using code generation tools