develop faster on magento 2 using code generation tools
TRANSCRIPT
![Page 1: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/1.jpg)
![Page 2: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/2.jpg)
Develop faster on M2 using code generation tools
Juan AlonsoSenior Developer @ Stämpfli
![Page 3: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/3.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/4.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/5.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/6.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/7.jpg)
😃
I was Happy
![Page 8: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/8.jpg)
Personal Experience on M2
• Another Problem -> CRUD Modules
• + 30 files needed
![Page 9: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/9.jpg)
😢
Sad again
![Page 10: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/10.jpg)
🤔So what can I do?
![Page 11: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/11.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/12.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/13.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/14.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/15.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/16.jpg)
🤔Live Demo
![Page 17: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/17.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/18.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/19.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/20.jpg)
?
![Page 21: Develop faster on Magento 2 using code generation tools](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/21.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052418/5a64bf617f8b9ac86f8b4811/html5/thumbnails/22.jpg)