Magento 2 Code Generator

Overview

Magento 2 Code Generator

Created by Orba

Inspired by https://github.com/staempfli/magento2-code-generator

Purpose

In day-to-day Magento 2 development there are some common tasks which require development of repeatable code that is hard to simply copy-paste. The purpose of this app is to automatize creation of such code, so the developers may focus on business logic and thanks to that being much more efficient and happy.

There are other tools on the market that allows to generate Magento boilerplate code, but we went a step further. The unique value of our tool is that it can be used with already existing codebase. The code generated by the tool is automatically merged with current code (eg. configuration XML files, requirejs-config JS files, etc.). Also, our aim was to generate high-quality code that uses modern PHP features and Magento coding standards.

Supported Magento versions

  • 2.3.7
  • 2.4.0
  • 2.4.1
  • 2.4.2

Watchout: Minimal version of Magento's PHP is 7.4.

Available templates

addProductAttributes - creates data patch which adds custom attributes to product entity

apiEndpoint - creates an API endpoint

block - creates a block and phtml template file for it

cache - creates a cache type

configField - creates config field for already existent group of store configuration

configGroup - creates group for already existent section of store configuration

configSection - creates section in existent tab of store configuration

configTab - creates tab for store configuration

consoleCommand - creates a console command

cron - creates a cron job and (optionally) a cron group

crud - creates new entity and all CRUD actions in the admin panel for it

emailTemplate - creates a system e-mail template with class for sending it and config for allowing admin to customize it

eventObserver - creates event observer for given event

frontPageController - creates a frontend controller that renders custom page

frontPostController - creates a very basic front POST controller

importEntity - creates an import model to import data into your custom entity table

jsMixin - creates a JS mixin

jsModule - creates a JS module

model - creates a model with the corresponding repository, searchResult, resourceModel, collection, db_schema.xml and APIs

module - creates basic configuration needed to start a custom module

queueMessage - creates queue message with publisher and handler using AMQP connection

quoteFields - creates custom fields for quote and order

searchCriteriaUsage - creates a management class and search criteria usage

theme - creates basic configurations needed to start a custom theme

viewModel - creates a view model and phtml template file for it

widget - creates a widget

Installation

Recommended way to install this app is to add it as Magento's Composer dev dependency:

composer require --dev orba/magento2-codegen

If you don't want to attach this app to your Magento, you can also simply clone the repository and use it as a standalone library. Don't forget to run composer install to install all required dependencies.

Configuration

Create your custom config file (not needed for Orba developers) either in package config directory or in your Magento root directory:

cp vendor/orba/magento2-codegen/config/codegen.yml.dist vendor/orba/magento2-codegen/config/codegen.yml

or

cp vendor/orba/magento2-codegen/config/codegen.yml.dist codegen.yml

and edit default values.

You may add your own template directory by including the following in your codegen.yml:

templateDirectories:
  - { path: "path/to/templates" }

Template folder path must be relative to package directory, ex. if you want to add private templates to your Magento dev folder, you should use ../../../dev/codegen_templates path.

You may include multiple template directories.

To overwrite a core template just copy a core template to your template directory and make changes as necessary.

Usage

  1. List all templates:
bin/codegen template:list
  1. Show template info:
bin/codegen template:info <template>
  1. Generate template:

bin/codegen template:generate <template>

This command must be executed on the module root folder where the registration.php file is. You can also use option --root-dir to specify this path, if you execute it from a different location.

Examples:

cd /path/to/magento/app/code/Orba/TestModule
../../../../vendor/bin/codegen template:generate block
cd /path/to/magento/vendor
bin/codegen --root-dir="/path/to/magento/app/code/Orba/TestModule" template:generate block

If specified root directory doesn't exist, it will be created automatically.

Contribution

Feel free to contribute with new templates, bugfixes and features. Submit your code to review using pull request.

Be aware that we require all the code to be compatible with PSR12. Also, we are validating the code with the following PHPMD rule sets: cleancode, codesize, controversial, design, unusedcode.

In dev/docs.md you can find the additional documentation for developers.

You might also like...
Magento-Functions - A Resource of Magento Functions

Magento-Functions A Resource of Magento Functions Table of Contents Category Product User Cart Checkout General Account [Working w/ URL's] (#urls) Cat

Magento - Magento Community Editions

Magento Community Edition /// THIS REPOSITORY IS DEPREACTED /// 1.9.4.1 will be the last version update. Please switch over to OpenMage! Either to the

Magento-Vagrant-Puppet-Nginx - Installs magento and a nginx server

Magento-Vagrant-Puppet-Nginx Installs Magento MySQL PHP PHP-FPM Nginx n98-magerun Setup git submodule init git submodule update vagrant up Modify pupp

Docker-magento - Docker image for Magento 1.6 to 1.9

Docker image for Magento 1.x This repo creates a Docker image for Magento 1.x. Please note The primary goal of this repo is to create Docker images fo

Magento-composer-installer - Composer installer for Magento modules
Magento-composer-installer - Composer installer for Magento modules

!!! support the maintainer of this project via Patreon: https://www.patreon.com/Flyingmana Magento Composer Installer The purpose of this project is t

Chef-magento - Installs and Configures a Magento project

Description Requirements Chef 0.10.0 or higher required (for Chef environment use). Platform Debian, Ubuntu CentOS, Red Hat, Fedora Your basebox must

Cookbook-magento - Collection of recipes to build app stack for the Magento deployments with Chef

Magento Cookbook Collection of recipes to build app stack for the Magento deployments with Chef Installation With Berkshelf echo "cookbook 'magento',

Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

Phpcs-magento-rules - A set of PHPCS rules used by made.com when hacking Magento

Made.com PHPCS Magento Rules A set of PHPCS rules used by made.com when hacking Magento. Pre-Requisites PHPCS Installation Short Version Clone this re

Comments
  • Empty copyrights

    Empty copyrights

    Thanks for providing such an useful tool for community.

    Adding additional flag like "includeCompanyHeader" would be useful as not all companies includes company name and exact author data. Adding empty values doesn't prevent adding copyrights notes in headers and they look like this:

    <!--
    /**
     * @copyright Copyright ©  . All rights reserved.
     * @author
     */
    -->
    
    enhancement 
    opened by bartoszkubicki 2
  • Crontab generation issue

    Crontab generation issue

    Thanks for providing such an useful tool for community. I have just started testing it around and found tiny issues.

    While answering questions about crontab.xml file I couldn't insert value 0 for scheduleHour. I bet the same issue may occur for other parts of crontab expression. Maybe 0 is casted to null or sth like this and it is not accepted as value is required.

    Generated crontab not exactly matches what I've inserted through CLI. Job name is prepended with snake case module name, what was for me unexpected.

    bug 
    opened by bartoszkubicki 2
  • Syntax error in templates/model/Model/{{ entityName|pascal }}.php

    Syntax error in templates/model/Model/{{ entityName|pascal }}.php

    In version 3.3.0 there is an unexpected : after getId() in the following code snippet. It causes syntax error for generated file.

        public function getId():
        {
            return $this->_getData('entity_id');
        }
    
    bug 
    opened by michalbiarda 0
  • Managing newly created module dependencies on fly

    Managing newly created module dependencies on fly

    That's enhancement I would find useful, but don't know the architecture of your library for now, so just posting an idea.

    So, let's assume we generate certain types of templates, with an option of module creation on the fly. It would be nice to have dependencies sorted out in process. For example, generation of crontab, should be followed by adding dependency to Magento_Cron in module.xml and composer.json. However there are some issues I see:

    • it is possible only if we say 'yes' to question if we would like to have module generated - I assume we should get that question every time we generate something
    • it is a problem to resolve package version (for composer version) if we don't know for which magento version code is generated - it can be avoided by putting wildcard (*) on the other hand or we could specify our target magento version in some config file
    • matrix of dependencies vs template has to be stored in some config file, but I don't know if there are templates that can generate code dependant to different packages according to what we insert during survey in CLI
    enhancement 
    opened by bartoszkubicki 1
Releases(3.3.0)
  • 3.3.0(Feb 23, 2022)

    Added

    • Possibility to collect property values from YAML file instead of console prompts
    • Exemplary YAML files for the following templates:
      • block
      • categoryAttributes
      • configField
      • emailTemplate
      • viewModel
    • Demo GIFs in readme file
    • .gitattributes file

    Changed

    • Readme file updated with description of all options of template:generate command

    Fixed

    • Inline edit error thrown on save for grid generated using crud template

    Removed

    • --dry-run option in template:generate command
    Source code(tar.gz)
    Source code(zip)
Owner
null
Code generator for Magento 2

Magento 2 Code Generator Tool Installation Option1: Downloading .phar wget https://github.com/staempfli/magento2-code-generator/releases/download/<ver

Stämpfli AG 254 Dec 5, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
[ONLY Magento 2.0.x Compatible] Code samples for Magento developers

Synopsis This project is a collection of samples to demonstrate technologies introduced in Magento 2. You will find the most simple extension along wi

Magento 58 Dec 26, 2022
Invoice PDF Generator For Magento 2

Magento Invoice PDF Generator Magento 2 Invoice PDF Generator - helps you to customize the pdf templates for Magento 2. If you have an enabled templat

EAdesign 66 Dec 13, 2022
Contracts for Rule Doc Generator. Useful for production code with minimum dependencies.

Rule Doc Generator Contracts Contracts for Rule Doc Generator. Useful for production code with minimum dependencies. Install composer require symplify

null 19 Dec 22, 2022
Algerian code generator for invoices, quotes or any commercial documents

Algerian invoice code generator The library is useful to generate code for invoices, quotes or any commercial transaction document. Goal Is to provide

Hippone Consulting 7 Jul 19, 2021
Runtime Code Generator like Lombok for PocketMine-MP

PlumbokPM Runtime Code Generator like Lombok for PocketMine-MP. Code generation starts when additional autoloader detects class uses PlumbokPM annotat

OctoPush 4 Apr 18, 2022
A QR Code generator for PHP7.4+

chillerlan/php-qrcode A PHP 7.4+ QR Code library based on the implementation by Kazuhiko Arase, namespaced, cleaned up, improved and other stuff. Docu

chillerlan 1.2k Dec 30, 2022
This Magento 2 extension integrates EasyTranslate into Magento 2.

EasyTranslate Magento 2 Connector This Magento 2 extension integrates EasyTranslate into Magento 2. Mind that you need to have an account with EasyTra

Easytranslate ApS 0 Oct 7, 2022